@@ -69,27 +69,31 @@ int main()
6969 MODEM.begin ();
7070 fileUtils.begin ();
7171 bool update_success = false ;
72- auto size = fileUtils.listFile (filename);
73- auto cycles = (size / blockSize) + 1 ;
74- if (size > SSU_SIZE) {
75- size -= SSU_SIZE;
76-
77- /* Erase the MCU flash */
78- uint32_t flash_address = (uint32_t )SKETCH_START;
79- mcu_flash.erase ((void *)flash_address, size);
80-
81- for (auto i = 0 ; i < cycles; i++) {
82- uint8_t block[blockSize] { 0 };
83- digitalWrite (LED_BUILTIN,LOW);
84- auto read = fileUtils.readBlock (filename, (i * blockSize) + SSU_SIZE, blockSize, block);
85- digitalWrite (LED_BUILTIN,HIGH);
86- mcu_flash.write ((void *)flash_address, block, read);
87- flash_address += read;
72+ if (fileUtils.listFile (" UPDATE.OK" ) == 1 ) {
73+ auto size = fileUtils.listFile (filename);
74+ auto cycles = (size / blockSize) + 1 ;
75+ if (size > SSU_SIZE) {
76+ size -= SSU_SIZE;
77+
78+ /* Erase the MCU flash */
79+ uint32_t flash_address = (uint32_t )SKETCH_START;
80+ mcu_flash.erase ((void *)flash_address, size);
81+
82+ for (auto i = 0 ; i < cycles; i++) {
83+ uint8_t block[blockSize] { 0 };
84+ digitalWrite (LED_BUILTIN,LOW);
85+ auto read = fileUtils.readBlock (filename, (i * blockSize) + SSU_SIZE, blockSize, block);
86+ digitalWrite (LED_BUILTIN,HIGH);
87+ mcu_flash.write ((void *)flash_address, block, read);
88+ flash_address += read;
89+ }
90+ update_success = true ;
91+ }
92+ if (update_success) {
93+ fileUtils.deleteFile (filename);
94+ fileUtils.deleteFile (" UPDATE.OK" );
8895 }
89- update_success = true ;
9096 }
91- if (update_success) { fileUtils.deleteFile (filename); }
92-
9397 /* Jump to the sketch */
9498 __set_MSP (*SKETCH_START);
9599
0 commit comments