Skip to content

Commit 24768bc

Browse files
committed
clean up
1 parent 859a721 commit 24768bc

3 files changed

Lines changed: 133 additions & 39 deletions

File tree

.clang-format

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: LLVM
4+
AlignAfterOpenBracket: Align
5+
AlignConsecutiveAssignments:
6+
Enabled: true
7+
AcrossEmptyLines: false
8+
AcrossComments: false
9+
AlignConsecutiveBitFields:
10+
Enabled: true
11+
AcrossEmptyLines: false
12+
AcrossComments: false
13+
AlignConsecutiveDeclarations:
14+
Enabled: true
15+
AcrossEmptyLines: false
16+
AcrossComments: false
17+
AlignConsecutiveMacros:
18+
Enabled: true
19+
AcrossEmptyLines: true
20+
AcrossComments: false
21+
AlignConsecutiveShortCaseStatements:
22+
Enabled: true
23+
AcrossEmptyLines: true
24+
AcrossComments: true
25+
AlignCaseColons: false
26+
AlignEscapedNewlines: LeftWithLastLine
27+
AlignOperands: true
28+
AlignTrailingComments:
29+
Kind: Always
30+
OverEmptyLines: 2
31+
AllowAllArgumentsOnNextLine: false
32+
AllowAllConstructorInitializersOnNextLine: false
33+
AllowAllParametersOfDeclarationOnNextLine: false
34+
AllowShortBlocksOnASingleLine: Empty
35+
AllowShortCaseExpressionOnASingleLine: true
36+
AllowShortCaseLabelsOnASingleLine: false
37+
AllowShortEnumsOnASingleLine: false
38+
AllowShortFunctionsOnASingleLine: None
39+
AllowShortIfStatementsOnASingleLine: Never
40+
AlwaysBreakTemplateDeclarations: Yes
41+
BinPackArguments: true
42+
BreakBeforeBraces: Custom
43+
BraceWrapping:
44+
AfterCaseLabel: false
45+
AfterClass: false
46+
AfterControlStatement: false
47+
AfterEnum: false
48+
AfterFunction: false
49+
AfterNamespace: false
50+
AfterStruct: false
51+
AfterUnion: false
52+
AfterExternBlock: false
53+
BeforeCatch: true
54+
BeforeElse: false
55+
BeforeLambdaBody: false
56+
BeforeWhile: false
57+
SplitEmptyFunction: true
58+
SplitEmptyRecord: true
59+
SplitEmptyNamespace: true
60+
BracedInitializerIndentWidth: 2
61+
BreakBeforeBinaryOperators: None
62+
BreakConstructorInitializers: AfterColon
63+
BreakConstructorInitializersBeforeComma: false
64+
ContinuationIndentWidth: 2
65+
ColumnLimit: 120
66+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
67+
Cpp11BracedListStyle: true
68+
IncludeBlocks: Preserve
69+
IncludeCategories:
70+
- Regex: '^<.*'
71+
Priority: 1
72+
- Regex: '^".*'
73+
Priority: 2
74+
- Regex: '.*'
75+
Priority: 3
76+
IncludeIsMainRegex: '([-_](test|unittest))?$'
77+
IndentPPDirectives: BeforeHash
78+
InsertBraces: true
79+
IndentCaseLabels: true
80+
InsertNewlineAtEOF: true
81+
MacroBlockBegin: ''
82+
MacroBlockEnd: ''
83+
MaxEmptyLinesToKeep: 2
84+
NamespaceIndentation: All
85+
PenaltyBreakBeforeFirstCallParameter: 1000000
86+
PenaltyBreakOpenParenthesis: 1000000
87+
PPIndentWidth: 2
88+
QualifierAlignment: Custom
89+
QualifierOrder: ['static', 'const', 'volatile', 'restrict', 'type']
90+
SpaceAfterTemplateKeyword: false
91+
SpaceBeforeRangeBasedForLoopColon: false
92+
SpaceInEmptyParentheses: false
93+
SpacesInAngles: false
94+
SpacesInConditionalStatement: false
95+
SpacesInCStyleCastParentheses: false
96+
SpacesInParentheses: false
97+
SortIncludes: false
98+
TabWidth: 2
99+
...

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ make BOARD=feather_nrf52840_express all
137137
For the list of supported boards, run `make` without `BOARD=` :
138138
139139
```
140-
$ make
140+
make
141141
You must provide a BOARD parameter with 'BOARD='
142142
Supported boards are: feather_nrf52840_express feather_nrf52840_express pca10056
143143
Makefile:90: *** BOARD not defined. Stop
@@ -213,7 +213,7 @@ make BOARD=feather_nrf52840_express flash-mbr
213213
If you get the following error ...
214214

215215
```
216-
$ make BOARD=feather_nrf52840_express all
216+
make BOARD=feather_nrf52840_express all
217217
Compiling file: main.c
218218
/bin/sh: /usr/bin/arm-none-eabi-gcc: No such file or directory
219219
make: *** [_build/main.o] Error 127
@@ -222,7 +222,7 @@ make: *** [_build/main.o] Error 127
222222
... you may need to pass the location of the GCC ARM toolchain binaries to `make` using
223223
the variable `CROSS_COMPILE` as below:
224224
```
225-
$ make CROSS_COMPILE=/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi- BOARD=feather_nrf52832 all
225+
make CROSS_COMPILE=/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi- BOARD=feather_nrf52832 all
226226
```
227227

228228
For other compile errors, check the gcc version with `arm-none-eabi-gcc --version` to insure it is at least 9.x.

src/main.c

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,27 @@
3939
#include <stddef.h>
4040

4141
#include "nrfx.h"
42-
#include "nrf_clock.h"
4342
#include "nrfx_power.h"
44-
#include "nrfx_pwm.h"
45-
46-
#include "nordic_common.h"
4743
#include "sdk_common.h"
48-
#include "dfu_transport.h"
4944
#include "bootloader.h"
5045
#include "bootloader_util.h"
5146

5247
#include "nrf.h"
5348
#include "nrf_soc.h"
5449
#include "nrf_nvic.h"
5550
#include "app_error.h"
56-
#include "nrf_gpio.h"
5751
#include "ble.h"
58-
#include "nrf.h"
59-
#include "ble_hci.h"
6052
#include "app_scheduler.h"
6153
#include "nrf_error.h"
6254

6355
#include "boards.h"
6456

6557
#include "pstorage_platform.h"
6658
#include "nrf_mbr.h"
67-
#include "pstorage.h"
68-
#include "nrfx_nvmc.h"
6959

7060
#ifdef NRF_USBD
7161

7262
#include "uf2/uf2.h"
73-
#include "nrf_usbd.h"
7463
#include "tusb.h"
7564

7665
void usb_init(bool cdc_only);
@@ -250,31 +239,34 @@ static void check_dfu_mode(void) {
250239
(((*dbl_reset_mem) == DFU_DBL_RESET_MAGIC) && reason_reset_pin);
251240

252241
// Clear GPREGRET if it is our values
253-
if (dfu_start || dfu_skip) NRF_POWER->GPREGRET = 0;
242+
if (dfu_start || dfu_skip) {
243+
NRF_POWER->GPREGRET = 0;
244+
}
254245

255246
// skip dfu entirely
256-
if (dfu_skip) return;
247+
if (dfu_skip) {
248+
return;
249+
}
257250

258251
/*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/
259-
// DFU button pressed
260-
dfu_start = dfu_start || button_pressed(BUTTON_DFU);
252+
dfu_start = dfu_start || button_pressed(BUTTON_DFU); // DFU button pressed
261253

262254
// DFU + FRESET are pressed --> OTA
263255
_ota_dfu = _ota_dfu || (button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET));
264256

265257
bool const valid_app = bootloader_app_is_valid();
266258
bool const just_start_app = valid_app && !dfu_start && (*dbl_reset_mem) == DFU_DBL_RESET_APP;
267259

268-
if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET()) dfu_start = 1;
260+
if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET()) {
261+
dfu_start = 1;
262+
}
269263

270264
// App mode: Double Reset detection or DFU startup for nrf52832
271265
if (!(just_start_app || dfu_start || !valid_app)) {
272266
#ifdef NRF52832_XXAA
273267
/* Even DFU is not active, we still force an 1000 ms dfu serial mode when startup
274268
* to support auto programming from Arduino IDE
275-
*
276-
* Note: Double Reset WONT work with nrf52832 since all its SRAM got cleared with GPIO reset.
277-
*/
269+
* Note: Double Reset WONT work with nrf52832 since all its SRAM got cleared with GPIO reset. */
278270
bootloader_dfu_start(false, DFU_SERIAL_STARTUP_INTERVAL, false);
279271
#else
280272
// Note: RESETREAS is not clear by bootloader, it should be cleared by application upon init()
@@ -323,6 +315,10 @@ static void check_dfu_mode(void) {
323315
}
324316
}
325317

318+
//--------------------------------------------------------------------+
319+
// BLE
320+
//--------------------------------------------------------------------+
321+
326322
// Initializes the SoftDevice by following SD specs section
327323
// "Master Boot Record and SoftDevice initializaton procedure"
328324
static uint32_t ble_stack_init(void) {
@@ -389,23 +385,6 @@ static uint32_t ble_stack_init(void) {
389385
return NRF_SUCCESS;
390386
}
391387

392-
//--------------------------------------------------------------------+
393-
// Error Handler
394-
//--------------------------------------------------------------------+
395-
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) {
396-
volatile uint32_t* ARM_CM_DHCSR = ((volatile uint32_t*) 0xE000EDF0UL); /* Cortex M CoreDebug->DHCSR */
397-
if ((*ARM_CM_DHCSR) & 1UL) __asm("BKPT #0\n"); /* Only halt mcu if debugger is attached */
398-
NVIC_SystemReset();
399-
}
400-
401-
void assert_nrf_callback(uint16_t line_num, uint8_t const* p_file_name) {
402-
app_error_fault_handler(0xDEADBEEF, 0, 0);
403-
}
404-
405-
/*------------------------------------------------------------------*/
406-
/* SoftDevice Event handler
407-
*------------------------------------------------------------------*/
408-
409388
// Process BLE event from SD
410389
uint32_t proc_ble(void) {
411390
__ALIGN(4) uint8_t ev_buf[BLE_EVT_LEN_MAX(BLEGATT_ATT_MTU_MAX)];
@@ -479,6 +458,22 @@ void SD_EVT_IRQHandler(void) {
479458
app_sched_event_put(NULL, 0, proc_sd_task);
480459
}
481460

461+
//--------------------------------------------------------------------+
462+
// Error Handler
463+
//--------------------------------------------------------------------+
464+
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) {
465+
volatile uint32_t *ARM_CM_DHCSR = ((volatile uint32_t *)0xE000EDF0UL); /* Cortex M CoreDebug->DHCSR */
466+
if ((*ARM_CM_DHCSR) & 1UL) {
467+
__asm("BKPT #0\n"); /* Only halt mcu if debugger is attached */
468+
}
469+
NVIC_SystemReset();
470+
}
471+
472+
void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name) {
473+
app_error_fault_handler(0xDEADBEEF, 0, 0);
474+
}
475+
476+
482477
//--------------------------------------------------------------------+
483478
// RTT printf retarget for Debug
484479
//--------------------------------------------------------------------+

0 commit comments

Comments
 (0)