Skip to content

Commit 5cd4c23

Browse files
committed
fix reset to bootloader issue with busy SoftDevice
1 parent 4414359 commit 5cd4c23

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

cores/nRF5/common_func.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,13 @@ const char* dbg_err_str(int32_t err_id); // TODO move to other place
179179
#define PRINT_LOCATION() PRINTF("%s: %d:\r\n", __PRETTY_FUNCTION__, __LINE__)
180180
#define PRINT_MESS(x) PRINTF("%s: %d: %s \r\n" , __FUNCTION__, __LINE__, (char*)(x))
181181
#define PRINT_HEAP() if (CFG_DEBUG >= 3) PRINTF("\n%s: %d: Heap free: %d\r\n", __FUNCTION__, __LINE__, util_heap_get_free_size())
182-
#define PRINT_STR(x) PRINTF("%s: %d: " #x " = %s\r\n" , __FUNCTION__, __LINE__, (char*)(x) )
183-
#define PRINT_INT(x) PRINTF("%s: %d: " #x " = %ld\r\n" , __FUNCTION__, __LINE__, (uint32_t) (x) )
184-
#define PRINT_FLOAT(x) PRINTF("%s: %d: " #x " = %f\r\n" , __FUNCTION__, __LINE__, (float) (x) )
182+
#define PRINT_STR(x) PRINTF(#x " = %s\r\n" , (char*)(x) )
183+
#define PRINT_INT(x) PRINTF(#x " = %ld\r\n", (uint32_t) (x) )
184+
#define PRINT_FLOAT(x) PRINTF(#x " = %f\r\n" , (float) (x) )
185185

186186
#define PRINT_HEX(x) \
187187
do {\
188-
PRINTF("%s: %d: " #x " = 0x", __PRETTY_FUNCTION__, __LINE__);\
188+
PRINTF(#x " = 0x");\
189189
char fmt[] = "%00X\r\n";\
190190
fmt[2] += 2*sizeof(x); /* Hex with correct size */\
191191
PRINTF(fmt, (x) );\

cores/nRF5/wiring.c

+25-6
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,41 @@ uint32_t readResetReason(void)
7474
return _reset_reason;
7575
}
7676

77-
void enterUf2Dfu(void)
77+
static void reset_mcu(uint32_t gpregret)
7878
{
79-
NRF_POWER->GPREGRET = DFU_MAGIC_UF2_RESET;
79+
// disable SD
80+
sd_softdevice_disable();
81+
82+
// Disable all interrupts
83+
NVIC->ICER[0]=0xFFFFFFFF;
84+
NVIC->ICPR[0]=0xFFFFFFFF;
85+
#if defined(__NRF_NVIC_ISER_COUNT) && __NRF_NVIC_ISER_COUNT == 2
86+
NVIC->ICER[1]=0xFFFFFFFF;
87+
NVIC->ICPR[1]=0xFFFFFFFF;
88+
#endif
89+
90+
NRF_POWER->GPREGRET = gpregret;
91+
8092
NVIC_SystemReset();
93+
94+
// maybe yield ?
95+
while(1) {}
96+
}
97+
98+
void enterUf2Dfu(void)
99+
{
100+
reset_mcu(DFU_MAGIC_UF2_RESET);
81101
}
82102

83103
void enterSerialDfu(void)
84104
{
85-
NRF_POWER->GPREGRET = DFU_MAGIC_SERIAL_ONLY_RESET;
86-
NVIC_SystemReset();
105+
// shut down everything
106+
reset_mcu(DFU_MAGIC_SERIAL_ONLY_RESET);
87107
}
88108

89109
void enterOTADfu(void)
90110
{
91-
NRF_POWER->GPREGRET = DFU_MAGIC_OTA_RESET;
92-
NVIC_SystemReset();
111+
reset_mcu(DFU_MAGIC_OTA_RESET);
93112
}
94113

95114
void waitForEvent(void)

0 commit comments

Comments
 (0)