@@ -37,6 +37,7 @@ uint16_t data_index = 0;
37
37
uint16_t residual_space = (uint16_t )BUFFER_SIZE ;
38
38
uint32_t nb_bytes = 0 ;
39
39
uint8_t crc = 0 ;
40
+ bool load_flag = false;
40
41
uint16_t source_id = 0 ; // used to save source_id, ie gate_id
41
42
uint32_t tickstart = 0 ;
42
43
#endif
@@ -150,7 +151,7 @@ uint8_t LuosBootloader_IsEnoughSpace(uint32_t binary_size)
150
151
151
152
/******************************************************************************
152
153
* @brief process binary data received from the gate
153
- * @param None
154
+ * @param None
154
155
* @return None
155
156
******************************************************************************/
156
157
void LuosBootloader_EraseMemory (void )
@@ -160,7 +161,7 @@ void LuosBootloader_EraseMemory(void)
160
161
161
162
/******************************************************************************
162
163
* @brief process binary data received from the gate
163
- * @param None
164
+ * @param None
164
165
* @return None
165
166
******************************************************************************/
166
167
void LuosBootloader_ProcessData (void )
@@ -198,8 +199,8 @@ void LuosBootloader_ProcessData(void)
198
199
}
199
200
200
201
/******************************************************************************
201
- * @brief Save the current page when BIN_END command is received
202
- * @param None
202
+ * @brief Save the current page when BIN_END command is received
203
+ * @param None
203
204
* @return None
204
205
******************************************************************************/
205
206
void LuosBootloader_SaveLastData (void )
@@ -209,7 +210,7 @@ void LuosBootloader_SaveLastData(void)
209
210
210
211
/******************************************************************************
211
212
* @brief compute crc 8 for each data
212
- * @param data pointer, data len
213
+ * @param data pointer, data len
213
214
* @return crc
214
215
******************************************************************************/
215
216
void crc8 (const uint8_t * data , uint8_t * crc , uint16_t polynome )
@@ -237,7 +238,7 @@ void crc8(const uint8_t *data, uint8_t *crc, uint16_t polynome)
237
238
238
239
/******************************************************************************
239
240
* @brief compute crc for the whole binary
240
- * @param data pointer, data len
241
+ * @param data pointer, data len
241
242
* @return crc
242
243
******************************************************************************/
243
244
uint8_t compute_crc (void )
@@ -316,13 +317,14 @@ void LuosBootloader_Loop(void)
316
317
{
317
318
switch (LuosBootloader_GetMode ())
318
319
{
319
- case APPLICATION_MODE :
320
+ case JUMP_TO_APP_MODE :
320
321
// boot the application programmed in dedicated flash partition
321
322
LuosBootloader_DeInit ();
322
323
LuosBootloader_JumpToApp ();
323
324
break ;
324
325
325
- case BOOTLOADER_MODE :
326
+ case BOOT_MODE :
327
+ case APP_RELOAD_MODE :
326
328
default :
327
329
break ;
328
330
}
@@ -344,7 +346,7 @@ void LuosBootloader_MsgHandler(msg_t *input)
344
346
case BOOTLOADER_START :
345
347
// We're in the app,
346
348
// set bootloader mode, save node ID and reboot
347
- LuosHAL_SetMode ((uint8_t )BOOTLOADER_MODE );
349
+ LuosHAL_SetMode ((uint8_t )APP_RELOAD_MODE );
348
350
LuosBootloader_SaveNodeID ();
349
351
LuosHAL_Reboot ();
350
352
break ;
@@ -410,13 +412,26 @@ void LuosBootloader_MsgHandler(msg_t *input)
410
412
LuosBootloader_SendCrc (BOOTLOADER_CRC_RESP , crc );
411
413
break ;
412
414
415
+ case BOOTLOADER_APP_SAVED :
416
+ // set load flag
417
+ load_flag = true;
418
+ break ;
419
+
413
420
case BOOTLOADER_STOP :
414
421
source_id = input -> header .source ;
415
422
bootloader_data_size = input -> header .size - sizeof (char );
416
423
memcpy (bootloader_data , & (input -> data [1 ]), bootloader_data_size );
417
424
418
- // save boot_mode in flash
419
- LuosHAL_SetMode ((uint8_t )APPLICATION_MODE );
425
+ // save bootloader mode in flash
426
+ if (load_flag || (LuosBootloader_GetMode () == APP_RELOAD_MODE ))
427
+ {
428
+ LuosHAL_SetMode ((uint8_t )JUMP_TO_APP_MODE );
429
+ }
430
+ else
431
+ {
432
+ LuosHAL_SetMode ((uint8_t )BOOT_MODE );
433
+ }
434
+
420
435
// wait for the command to be send to all nodes
421
436
tickstart = LuosHAL_GetSystick ();
422
437
while ((LuosHAL_GetSystick () - tickstart ) < 1000 )
0 commit comments