improve bledfu
This commit is contained in:
1 parent
a398152c87
commit
0603230f65
1 file changed
+16
-5
@@ -118,6 +118,8 @@ static void bledfu_control_wr_authorize_cb(BLECharacteristic& chr, ble_gatts_evt
|
||||
uint16_t crc16;
|
||||
}peer_data_t;
|
||||
|
||||
VERIFY_STATIC(offsetof(peer_data_t, crc16) == 60);
|
||||
|
||||
/* Save Peer data
|
||||
* Peer data address is defined in bootloader linker @0x20007F80
|
||||
* - If bonded : save Security information
|
||||
@@ -151,8 +153,8 @@ static void bledfu_control_wr_authorize_cb(BLECharacteristic& chr, ble_gatts_evt
|
||||
peer_data->crc16 = crc16((uint8_t*) peer_data, offsetof(peer_data_t, crc16));
|
||||
|
||||
// Initiate DFU Sequence and reboot into DFU OTA mode
|
||||
Bluefruit.Advertising.restartOnDisconnect(false);
|
||||
Bluefruit.disconnect();
|
||||
Bluefruit.Advertising.stop();
|
||||
|
||||
// Set GPReset to DFU OTA
|
||||
enum { DFU_OTA_MAGIC = 0xB1 };
|
||||
@@ -161,16 +163,25 @@ static void bledfu_control_wr_authorize_cb(BLECharacteristic& chr, ble_gatts_evt
|
||||
VERIFY_STATUS( sd_power_gpregret_set(0, DFU_OTA_MAGIC), RETURN_VOID);
|
||||
VERIFY_STATUS( sd_softdevice_disable(), RETURN_VOID );
|
||||
|
||||
// Disable Systick to prevent Interrupt happens after changing vector table
|
||||
bitClear(SysTick->CTRL, SysTick_CTRL_ENABLE_Pos);
|
||||
|
||||
// Disable all interrupts
|
||||
#if defined(NRF52832_XXAA)
|
||||
#define MAX_NUMBER_INTERRUPTS 39
|
||||
#elif defined(NRF52840_XXAA)
|
||||
#define MAX_NUMBER_INTERRUPTS 48
|
||||
#endif
|
||||
|
||||
NVIC_ClearPendingIRQ(SD_EVT_IRQn);
|
||||
for(int i=0; i <= FPU_IRQn; i++)
|
||||
for(int i=0; i < MAX_NUMBER_INTERRUPTS; i++)
|
||||
{
|
||||
NVIC_DisableIRQ( (IRQn_Type) i );
|
||||
}
|
||||
|
||||
// Clear RTC1 timer to prevent Interrupt happens after changing vector table
|
||||
// NRF_RTC1->EVTENCLR = RTC_EVTEN_COMPARE0_Msk;
|
||||
// NRF_RTC1->INTENCLR = RTC_INTENSET_COMPARE0_Msk;
|
||||
// NRF_RTC1->TASKS_STOP = 1;
|
||||
// NRF_RTC1->TASKS_CLEAR = 1;
|
||||
|
||||
VERIFY_STATUS( sd_softdevice_vector_table_base_set(NRF_UICR->NRFFW[0]), RETURN_VOID);
|
||||
|
||||
__set_CONTROL(0); // switch to MSP, required if using FreeRTOS
|
||||
|
||||
Reference in new issue
Block a user