diff --git a/ARM_Tag_FW/ESP32_S3_to_C6_Flasher_Test/flashid-dump-esptool.txt b/ARM_Tag_FW/ESP32_S3_to_C6_Flasher_Test/flashid-dump-esptool.txt new file mode 100644 index 00000000..6c3a5f1f --- /dev/null +++ b/ARM_Tag_FW/ESP32_S3_to_C6_Flasher_Test/flashid-dump-esptool.txt @@ -0,0 +1,281 @@ + + +TRACE +0.008 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=00100040 +TRACE +0.000 Write 14 bytes: c0000a04000000000000100040c0 +TRACE +0.002 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04006f80e02c00000000c0 +TRACE +0.000 Received full packet: 010a04006f80e02c00000000 + +Detecting chip type... + +TRACE +0.000 command op=0x14 data len=0 wait_response=1 timeout=3.000 data= +TRACE +0.000 Write 10 bytes: c00014000000000000c0 +TRACE +0.008 Read 1 bytes: c0 +TRACE +0.000 Read 33 bytes: + 011418006f80e02c 0000000000000000 | ....o..,........ + 0000000c0d000000 0000000000000000 | ................ + c0 | . +TRACE +0.000 Received full packet: + 011418006f80e02c 0000000000000000 | ....o..,........ + 0000000c0d000000 0000000000000000 | ................ + +TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=80f58740 +TRACE +0.000 Write 14 bytes: c0000a04000000000080f58740c0 +TRACE +0.002 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04000000000000000000c0 +TRACE +0.000 Received full packet: 010a04000000000000000000 + +TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=50080b60 +TRACE +0.000 Write 14 bytes: c0000a04000000000050080b60c0 +TRACE +0.000 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04000000000800000000c0 +TRACE +0.000 Received full packet: 010a04000000000800000000 + +TRACE +0.008 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=50080b60 +TRACE +0.000 Write 14 bytes: c0000a04000000000050080b60c0 +TRACE +0.002 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04000000000800000000c0 +TRACE +0.000 Received full packet: 010a04000000000800000000 + +TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=50080b60 +TRACE +0.000 Write 14 bytes: c0000a04000000000050080b60c0 +TRACE +0.000 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04000000000800000000c0 +TRACE +0.000 Received full packet: 010a04000000000800000000 + +Chip is ESP32-C6 (QFN40) (revision v0.0) +Features: WiFi 6, BT 5, IEEE802.15.4 +Crystal is 40MHz + +TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=44080b60 +TRACE +0.000 Write 14 bytes: c0000a04000000000044080b60c0 +TRACE +0.010 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a0400e85342ca00000000c0 +TRACE +0.000 Received full packet: 010a0400e85342ca00000000 + +TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=48080b60 +TRACE +0.000 Write 14 bytes: c0000a04000000000048080b60c0 +TRACE +0.000 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04004c40feff00000000c0 +TRACE +0.000 Received full packet: 010a04004c40feff00000000 + +MAC: 40:4c:ca:ff:fe:42:53:e8 + +TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=44080b60 +TRACE +0.000 Write 14 bytes: c0000a04000000000044080b60c0 +TRACE +0.008 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a0400e85342ca00000000c0 +TRACE +0.000 Received full packet: 010a0400e85342ca00000000 + +TRACE +0.002 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=48080b60 +TRACE +0.000 Write 14 bytes: c0000a04000000000048080b60c0 +TRACE +0.000 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04004c40feff00000000c0 +TRACE +0.000 Received full packet: 010a04004c40feff00000000 + +BASE MAC: 40:4c:ca:42:53:e8 + +TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=44080b60 +TRACE +0.000 Write 14 bytes: c0000a04000000000044080b60c0 +TRACE +0.008 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a0400e85342ca00000000c0 +TRACE +0.000 Received full packet: 010a0400e85342ca00000000 + +!!! TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=48080b60 +TRACE +0.000 Write 14 bytes: c0000a04000000000048080b60c0 +TRACE +0.002 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04004c40feff00000000c0 +TRACE +0.000 Received full packet: 010a04004c40feff00000000 + +MAC_EXT: ff:fe + +Enabling default SPI flash mode... + +!!!! TRACE +0.000 command op=0x0d data len=8 wait_response=1 timeout=3.000 data=0000000000000000 +TRACE +0.000 Write 18 bytes: + c0000d0800000000 0000000000000000 | ................ + 00c0 | .. +TRACE +0.000 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010d04004c40feff00000000c0 +TRACE +0.000 Received full packet: 010d04004c40feff00000000 + +v TRACE +0.008 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=18300060 +TRACE +0.000 Write 14 bytes: c0000a04000000000018300060c0 +TRACE +0.002 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04000000008000000000c0 +TRACE +0.000 Received full packet: 010a04000000008000000000 + +v TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=20300060 +TRACE +0.000 Write 14 bytes: c0000a04000000000020300060c0 +TRACE +0.000 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04000000007000000000c0 +TRACE +0.000 Received full packet: 010a04000000007000000000 + +v TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=2830006017000000ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 0028300060170000 | .........(0.`... + 00ffffffff000000 00c0 | .......... +TRACE +0.010 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010904000000007000000000c0 +TRACE +0.000 Received full packet: 010904000000007000000000 + +TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=1830006000000090ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 0018300060000000 | ..........0.`... + 90ffffffff000000 00c0 | .......... +TRACE +0.000 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010904000000007000000000c0 +TRACE +0.000 Received full packet: 010904000000007000000000 + +TRACE +0.008 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=203000609f000070ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 00203000609f0000 | ......... 0.`... + 70ffffffff000000 00c0 | p......... +TRACE +0.002 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010904000000007000000000c0 +TRACE +0.000 Received full packet: 010904000000007000000000 + +TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=5830006000000000ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 0058300060000000 | .........X0.`... + 00ffffffff000000 00c0 | .......... +TRACE +0.008 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010904000000007000000000c0 +TRACE +0.000 Received full packet: 010904000000007000000000 + +TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=0030006000000400ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 0000300060000004 | ..........0.`... + 00ffffffff000000 00c0 | .......... +TRACE +0.002 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010904000000007000000000c0 +TRACE +0.000 Received full packet: 010904000000007000000000 + +TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=00300060 +TRACE +0.000 Write 14 bytes: c0000a04000000000000300060c0 +TRACE +0.008 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04000000000000000000c0 +TRACE +0.000 Received full packet: 010a04000000000000000000 + +!!! TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=58300060 +TRACE +0.000 Write 14 bytes: c0000a04000000000058300060c0 +TRACE +0.002 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a0400c840170000000000c0 +TRACE +0.000 Received full packet: 010a0400c840170000000000 + +!!! TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=1830006000000080ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 0018300060000000 | ..........0.`... + 80ffffffff000000 00c0 | .......... +TRACE +0.000 Read 1 bytes: c0 +TRACE +0.008 Read 13 bytes: 01090400c840170000000000c0 +TRACE +0.000 Received full packet: 01090400c840170000000000 + +TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=2030006000000070ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 0020300060000000 | ......... 0.`... + 70ffffffff000000 00c0 | p......... +TRACE +0.002 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 01090400c840170000000000c0 +TRACE +0.000 Received full packet: 01090400c840170000000000 + +TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=18300060 +TRACE +0.000 Write 14 bytes: c0000a04000000000018300060c0 +TRACE +0.008 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04000000008000000000c0 +TRACE +0.000 Received full packet: 010a04000000008000000000 + +TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=20300060 +TRACE +0.000 Write 14 bytes: c0000a04000000000020300060c0 +TRACE +0.002 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04000000007000000000c0 +TRACE +0.000 Received full packet: 010a04000000007000000000 + +TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=2830006007000000ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 0028300060070000 | .........(0.`... + 00ffffffff000000 00c0 | .......... +TRACE +0.008 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010904000000007000000000c0 +TRACE +0.000 Received full packet: 010904000000007000000000 + +TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=1c3000600700005cffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 001c300060070000 | ..........0.`... + 5cffffffff000000 00c0 | \......... +TRACE +0.002 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010904000000007000000000c0 +TRACE +0.000 Received full packet: 010904000000007000000000 + +TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=18300060000000f0ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 0018300060000000 | ..........0.`... + f0ffffffff000000 00c0 | .......... +TRACE +0.008 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010904000000007000000000c0 +TRACE +0.000 Received full packet: 010904000000007000000000 + +TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=203000605a000070ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 00203000605a0000 | ......... 0.`Z.. + 70ffffffff000000 00c0 | p......... +TRACE +0.000 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010904000000007000000000c0 +TRACE +0.000 Received full packet: 010904000000007000000000 + +TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=0430006010000000ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 0004300060100000 | ..........0.`... + 00ffffffff000000 00c0 | .......... +TRACE +0.012 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010904000000007000000000c0 +TRACE +0.000 Received full packet: 010904000000007000000000 + +TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=5830006000000000ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 0058300060000000 | .........X0.`... + 00ffffffff000000 00c0 | .......... +TRACE +0.000 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010904000000007000000000c0 +TRACE +0.000 Received full packet: 010904000000007000000000 + +TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=0030006000000400ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 0000300060000004 | ..........0.`... + 00ffffffff000000 00c0 | .......... +TRACE +0.010 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010904000000007000000000c0 +TRACE +0.000 Received full packet: 010904000000007000000000 + +TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=00300060 +TRACE +0.000 Write 14 bytes: c0000a04000000000000300060c0 +TRACE +0.000 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a04000000000000000000c0 +TRACE +0.000 Received full packet: 010a04000000000000000000 + +TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=58300060 +TRACE +0.000 Write 14 bytes: c0000a04000000000058300060c0 +TRACE +0.010 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 010a0400c800000000000000c0 +TRACE +0.000 Received full packet: 010a0400c800000000000000 + +TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=1830006000000080ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 0018300060000000 | ..........0.`... + 80ffffffff000000 00c0 | .......... +TRACE +0.000 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 01090400c800000000000000c0 +TRACE +0.000 Received full packet: 01090400c800000000000000 + +TRACE +0.000 command op=0x09 data len=16 wait_response=1 timeout=3.000 data=2030006000000070ffffffff00000000 +TRACE +0.000 Write 26 bytes: + c000091000000000 0020300060000000 | ......... 0.`... + 70ffffffff000000 00c0 | p......... +TRACE +0.010 Read 1 bytes: c0 +TRACE +0.000 Read 13 bytes: 01090400c800000000000000c0 +TRACE +0.000 Received full packet: 01090400c800000000000000 + +Manufacturer: c8 +Device: 4017 +Detected flash size: 8MB + diff --git a/ARM_Tag_FW/ESP32_S3_to_C6_Flasher_Test/flashid-dump-s3.txt b/ARM_Tag_FW/ESP32_S3_to_C6_Flasher_Test/flashid-dump-s3.txt new file mode 100644 index 00000000..d3ea4b83 --- /dev/null +++ b/ARM_Tag_FW/ESP32_S3_to_C6_Flasher_Test/flashid-dump-s3.txt @@ -0,0 +1,96 @@ +C6 flash starting + +Write 1 bytes: c000082400000000000707122055555555 +55555555555555555555555555555555 +555555555555555555555555c0 +Read 1 bytes: 004553502d524f4d3a657370333263362d32303232303931390d0a4275696c643a53657020313920323032320d0a7273743a3078312028504f5745524f4e292c626f6f743a307836362028444f574e4c4f4144285553422f55415254302f5344494f5f5245495f46454f29290d0a77616974696e6720666f7220646f776e6c6f61640d0a + +Write 1 bytes: c000082400000000000707122055555555 +55555555555555555555555555555555 +555555555555555555555555c0 +Read 1 bytes: c0010804000707122000000000c0 + +Write 1 bytes: c0000a04000000000000100040c0 +Read 1 bytes: c0010804000707122000000000c0 +c0010804000707122000000000c0 +c0010804000707122000000000c0 +c0010804000707122000000000c0 +c0010804000707122000000000c0 +c0010804000707122000000000c0 +c0010804000707122000000000c0 +c0010a04006f80e02c00000000c0 + +Write 1 bytes: c0000a04000000000048080b60c0 600b0848!!! read 0x12 + c0000a04000000000044080b60c0 600b0844 read 0x11 +Read 1 bytes: c0010a04004c40feff00000000c0 + c0010a0400e85342ca00000000c0 + esptool: c0010a04004c40feff00000000c0 + +>>>>> Write 1 bytes: c0000a0400000000004c080b60c0 600b084C!!! read 0x13 + esptool: c0000a04000000000048080b60c0 600b0848 read 0x12 +Read 1 bytes: c0010a04000000000000000000c0 + esptool: c0010a04004c40feff00000000c0 + +command op=0x0d data len=8 +>>>>> Write 1 bytes: c0000d080000000000feff000000000000c0 + esptool:c0000d0800000000000000000000000000c0 +>>>>> Read 1 bytes: c0010d04000000000000000000c0 + esptool: c0010d04004c40feff00000000c0 + +Connected to target +Connected to ESP32-C6 +bootloader +size: 21248 +Erasing flash (this may take a while)... +esp_loader_flash_start +block_size 1024 +detect_flash_size + +spi_flash_command 159 0 24 +v Write 1 bytes: c0000a04000000000018300060c0 +Read 1 bytes: c0010a04000000008000000000c0 + +v Write 1 bytes: c0000a04000000000020300060c0 +Read 1 bytes: c0010a04000000007000000000c0 + +v Write 1 bytes: c000091000000000002830006017000000 +ffffffff00000000c0 +Read 1 bytes: c0010904000000007000000000c0 + +v Write 1 bytes: c000091000000000001830006000000090 +ffffffff00000000c0 +Read 1 bytes: c0010904000000007000000000c0 + +v Write 1 bytes: c00009100000000000203000609f000070 +ffffffff00000000c0 +Read 1 bytes: c0010904000000007000000000c0 + +v Write 1 bytes: c000091000000000005830006000000000 +ffffffff00000000c0 +Read 1 bytes: c0010904000000007000000000c0 + +v Write 1 bytes: c000091000000000000030006000000400 +ffffffff00000000c0 +Read 1 bytes: c0010904000000007000000000c0try 9 + +v Write 1 bytes: c0000a04000000000000300060c0 +Read 1 bytes: c0010a04000000000000000000c0 + +Write 1 bytes: c0000a04000000000058300060c0 +!!! Read 1 bytes: c0010a0400ffffff0000000000c0 + +Write 1 bytes: c000091000000000001830006000000080 +ffffffff00000000c0 +!!! Read 1 bytes: c001090400ffffff0000000000c0 + +Write 1 bytes: c000091000000000002030006000000070 +ffffffff00000000c0 +Read 1 bytes: c001090400ffffff0000000000c0 + +size_id 255 +DEBUG: Flash size detection failed, falling back to default + +Write 1 bytes: c000021400000000000053000015000000 +000400000000000000000000c0 +Read 0 bytes: +Erasing flash failed with error 2. diff --git a/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/main.c b/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/main.c index 568aaf3d..1d2c5e9e 100644 --- a/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/main.c +++ b/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/main.c @@ -66,7 +66,7 @@ uint32_t lastBlockRequest = 0; uint8_t lastBlockMac[8]; uint8_t lastTagReturn[8]; -uint8_t curChannel = 11; +uint8_t curChannel = 25; uint8_t curPower = 10; uint8_t curPendingData = 0; @@ -326,13 +326,15 @@ void processSerial(uint8_t lastchar) { } goto SCPfailed; SCPchannelFound: - curChannel = scp->channel; - curPower = scp->power; - radioSetChannel(scp->channel); + pr("ACK>"); + if (curChannel != scp->channel) { + radioSetChannel(scp->channel); + curChannel = scp->channel; + } + curPower = scp->power; radioSetTxPower(scp->power); ESP_LOGI(TAG, "Set channel: %d power: %d", curChannel, curPower); - pr("ACK>"); - } else { + } else { SCPfailed: pr("NOK>"); } @@ -682,25 +684,24 @@ void sendPong(void *buf) { } void app_main(void) { + esp_event_loop_create_default(); + init_nvs(); - init_led(); + init_led(); init_second_uart(); - esp_event_loop_create_default(); - - radio_init(); - requestedData.blockId = 0xFF; // clear the array with pending information memset(pendingDataArr, 0, sizeof(pendingDataArr)); - radioSetChannel(curChannel); + radio_init(curChannel); radioSetTxPower(10); pr("RES>"); pr("RDY>"); + ESP_LOGI(TAG, "C6 ready!"); - housekeepingTimer = getMillis(); + housekeepingTimer = getMillis(); while (1) { while ((getMillis() - housekeepingTimer) < ((1000 * HOUSEKEEPING_INTERVAL) - 100)) { int8_t ret = commsRxUnencrypted(radiorxbuffer); diff --git a/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/radio.c b/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/radio.c index 62c3710a..f40f9e43 100644 --- a/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/radio.c +++ b/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/radio.c @@ -47,19 +47,44 @@ void esp_ieee802154_transmit_done(const uint8_t *frame, const uint8_t *ack, esp_ ESP_EARLY_LOGI(TAG, "TX %d", frame[0]); } -void radio_init() { - packet_buffer = xQueueCreate(32, 130); - esp_ieee802154_enable(); - radioSetChannel(11); - esp_ieee802154_set_panid(PROTO_PAN_ID); - esp_ieee802154_set_promiscuous(false); // Filter for our mac and PAN +void radio_init(uint8_t ch) { + if (packet_buffer == NULL) packet_buffer = xQueueCreate(32, 130); + + // this will trigger a "IEEE802154 MAC sleep init failed" when called a second time, but it works + esp_ieee802154_enable(); + esp_ieee802154_set_channel(ch); + // esp_ieee802154_set_txpower(int8_t power); + esp_ieee802154_set_panid(PROTO_PAN_ID); + esp_ieee802154_set_promiscuous(false); esp_ieee802154_set_coordinator(false); esp_ieee802154_set_pending_mode(ESP_IEEE802154_AUTO_PENDING_ZIGBEE); - esp_read_mac(mSelfMac, ESP_MAC_IEEE802154); - esp_ieee802154_set_extended_address(mSelfMac); - esp_ieee802154_set_short_address(0xFFFE); + + // esp_ieee802154_set_extended_address needs the MAC in reversed byte order + esp_read_mac(mSelfMac, ESP_MAC_IEEE802154); + uint8_t eui64_rev[8] = {0}; + for (int i = 0; i < 8; i++) { + eui64_rev[7 - i] = mSelfMac[i]; + } + esp_ieee802154_set_extended_address(eui64_rev); + esp_ieee802154_get_extended_address(mSelfMac); + + esp_ieee802154_set_short_address(0xFFFE); esp_ieee802154_set_rx_when_idle(true); esp_ieee802154_receive(); + + led_flash(1); + vTaskDelay(100 / portTICK_PERIOD_MS); + led_flash(0); + vTaskDelay(100 / portTICK_PERIOD_MS); + led_flash(1); + vTaskDelay(100 / portTICK_PERIOD_MS); + led_flash(0); + + ESP_LOGI(TAG, "Receiver ready, panId=0x%04x, channel=%d, long=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x, short=%04x", + esp_ieee802154_get_panid(), esp_ieee802154_get_channel(), + mSelfMac[0], mSelfMac[1], mSelfMac[2], mSelfMac[3], + mSelfMac[4], mSelfMac[5], mSelfMac[6], mSelfMac[7], + esp_ieee802154_get_short_address()); } uint32_t lastZbTx = 0; @@ -77,7 +102,9 @@ bool radioTx(uint8_t *packet) { return true; } -void radioSetChannel(uint8_t ch) { esp_ieee802154_set_channel(ch); } +void radioSetChannel(uint8_t ch) { + radio_init(ch); +} void radioSetTxPower(uint8_t power) {} diff --git a/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/radio.h b/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/radio.h index 2f50c751..73cd5286 100644 --- a/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/radio.h +++ b/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/radio.h @@ -4,7 +4,7 @@ extern uint8_t mSelfMac[8]; -void radio_init(); +void radio_init(uint8_t ch); bool radioTx(uint8_t *packet); void radioSetChannel(uint8_t ch); void radioSetTxPower(uint8_t power); diff --git a/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/second_uart.c b/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/second_uart.c index d6dadca0..b64e14ba 100644 --- a/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/second_uart.c +++ b/ARM_Tag_FW/OpenEPaperLink_esp32_C6_AP/main/second_uart.c @@ -32,7 +32,8 @@ volatile int curr_buff_pos = 0; volatile int worked_buff_pos = 0; volatile uint8_t buff_pos[MAX_BUFF_POS + 5]; - +#define S3_TX_PIN 3 +#define S3_RX_PIN 2 static void uart_event_task(void *pvParameters); void init_second_uart() { @@ -46,9 +47,9 @@ void init_second_uart() { }; ESP_ERROR_CHECK(uart_driver_install(1, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0)); ESP_ERROR_CHECK(uart_param_config(1, &uart_config)); - ESP_ERROR_CHECK(uart_set_pin(1, 3, 2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); + ESP_ERROR_CHECK(uart_set_pin(1, S3_TX_PIN, S3_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); - xTaskCreate(uart_event_task, "uart_event_task", 16384, NULL, 12, NULL); + xTaskCreate(uart_event_task, "uart_event_task", 16384, NULL, 12, NULL); } void uart_switch_speed(int baudrate) { @@ -92,7 +93,7 @@ static void uart_event_task(void *pvParameters) { } break; default: - ESP_LOGI(TAG, "uart event type: %d", event.type); + // ESP_LOGI(TAG, "uart event type: %d", event.type); break; } } diff --git a/ESP32_AP-Flasher/data/www/content_cards.json.gz b/ESP32_AP-Flasher/data/www/content_cards.json.gz index d99a6877..f5382ff3 100644 Binary files a/ESP32_AP-Flasher/data/www/content_cards.json.gz and b/ESP32_AP-Flasher/data/www/content_cards.json.gz differ diff --git a/ESP32_AP-Flasher/data/www/index.html.gz b/ESP32_AP-Flasher/data/www/index.html.gz index de5a77f9..88fed93f 100644 Binary files a/ESP32_AP-Flasher/data/www/index.html.gz and b/ESP32_AP-Flasher/data/www/index.html.gz differ diff --git a/ESP32_AP-Flasher/data/www/main.css.gz b/ESP32_AP-Flasher/data/www/main.css.gz index 0800418e..ec8720cc 100644 Binary files a/ESP32_AP-Flasher/data/www/main.css.gz and b/ESP32_AP-Flasher/data/www/main.css.gz differ diff --git a/ESP32_AP-Flasher/data/www/main.js.gz b/ESP32_AP-Flasher/data/www/main.js.gz index dab5e855..412ebb5e 100644 Binary files a/ESP32_AP-Flasher/data/www/main.js.gz and b/ESP32_AP-Flasher/data/www/main.js.gz differ diff --git a/ESP32_AP-Flasher/data/www/ota.js.gz b/ESP32_AP-Flasher/data/www/ota.js.gz index e4fa1810..80be0e9c 100644 Binary files a/ESP32_AP-Flasher/data/www/ota.js.gz and b/ESP32_AP-Flasher/data/www/ota.js.gz differ diff --git a/ESP32_AP-Flasher/include/esp32_port.h b/ESP32_AP-Flasher/include/esp32_port.h new file mode 100644 index 00000000..c098762d --- /dev/null +++ b/ESP32_AP-Flasher/include/esp32_port.h @@ -0,0 +1,59 @@ +/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #pragma once + +#include "esp_loader_io.h" +#include "freertos/FreeRTOS.h" +#include "freertos/queue.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct +{ + uint32_t baud_rate; /*!< Initial baud rate, can be changed later */ + uint32_t uart_port; /*!< UART port */ + uint32_t uart_rx_pin; /*!< This pin will be configured as UART Rx pin */ + uint32_t uart_tx_pin; /*!< This pin will be configured as UART Tx pin */ + uint32_t reset_trigger_pin; /*!< This pin will be used to reset target chip */ + uint32_t gpio0_trigger_pin; /*!< This pin will be used to toggle set IO0 of target chip */ + uint32_t rx_buffer_size; /*!< Set to zero for default RX buffer size */ + uint32_t tx_buffer_size; /*!< Set to zero for default TX buffer size */ + uint32_t queue_size; /*!< Set to zero for default UART queue size */ + QueueHandle_t *uart_queue; /*!< Set to NULL, if UART queue handle is not + necessary. Otherwise, it will be assigned here */ +} loader_esp32_config_t; + +/** + * @brief Initializes serial interface. + * + * @param baud_rate[in] Communication speed. + * + * @return + * - ESP_LOADER_SUCCESS Success + * - ESP_LOADER_ERROR_FAIL Initialization failure + */ +esp_loader_error_t loader_port_esp32_init(const loader_esp32_config_t *config); + +/** + * @brief Deinitialize serial interface. + */ +void loader_port_esp32_deinit(void); + +#ifdef __cplusplus +} +#endif diff --git a/ESP32_AP-Flasher/include/espflasher.h b/ESP32_AP-Flasher/include/espflasher.h new file mode 100644 index 00000000..10599252 --- /dev/null +++ b/ESP32_AP-Flasher/include/espflasher.h @@ -0,0 +1,4 @@ +#include +#include + +bool doC6flash(); diff --git a/ESP32_AP-Flasher/include/ota.h b/ESP32_AP-Flasher/include/ota.h index 5bbce278..e46fb9ad 100644 --- a/ESP32_AP-Flasher/include/ota.h +++ b/ESP32_AP-Flasher/include/ota.h @@ -9,4 +9,5 @@ void handleUpdateOTA(AsyncWebServerRequest* request); void firmwareUpdateTask(void* parameter); void updateFirmware(const char* url, const char* expectedMd5, const size_t size); void handleRollback(AsyncWebServerRequest* request); +void handleUpdateC6(AsyncWebServerRequest* request); void handleUpdateActions(AsyncWebServerRequest* request); diff --git a/ESP32_AP-Flasher/include/serialap.h b/ESP32_AP-Flasher/include/serialap.h index 8d9ea599..7b934f18 100644 --- a/ESP32_AP-Flasher/include/serialap.h +++ b/ESP32_AP-Flasher/include/serialap.h @@ -29,7 +29,8 @@ void APTask(void* parameter); bool sendCancelPending(struct pendingData* pending); bool sendDataAvail(struct pendingData* pending); bool sendPing(); - void APEnterEarlyReset(); - -bool sendChannelPower(struct espSetChannelPower* scp); \ No newline at end of file +bool sendChannelPower(struct espSetChannelPower* scp); +void rxSerialTask2(void* parameter); +void APTagReset(); +bool bringAPOnline(); \ No newline at end of file diff --git a/ESP32_AP-Flasher/platformio.ini b/ESP32_AP-Flasher/platformio.ini index fb1832c2..3b7de77f 100644 --- a/ESP32_AP-Flasher/platformio.ini +++ b/ESP32_AP-Flasher/platformio.ini @@ -64,7 +64,7 @@ build_flags = -D FLASHER_LED=15 -D FLASHER_RGB_LED=33 build_src_filter = - +<*>-- + +<*>--- board_build.psram_type=qspi_opi board_upload.maximum_size = 4194304 board_upload.maximum_ram_size = 327680 @@ -99,7 +99,7 @@ build_flags = -D FLASHER_LED=15 -D FLASHER_RGB_LED=-1 build_src_filter = - +<*>-- + +<*>--- board_build.psram_type=qspi_opi board_upload.maximum_size = 4194304 board_upload.maximum_ram_size = 327680 @@ -157,6 +157,8 @@ build_flags = -D FLASHER_ALT_TEST=13 -D FLASHER_LED=21 -D FLASHER_RGB_LED=48 +build_src_filter = + +<*>- board_build.flash_mode=qio board_build.arduino.memory_type = qio_opi board_build.psram_type=qspi_opi @@ -186,7 +188,7 @@ build_flags = -D FLASHER_AP_RXD=16 -D FLASHER_LED=22 build_src_filter = - +<*>-- + +<*>--- ; ---------------------------------------------------------------------------------------- ; !!! this configuration expects an wemos_d1_mini32 @@ -212,7 +214,7 @@ build_flags = -D FLASHER_AP_RXD=17 -D FLASHER_LED=22 build_src_filter = - +<*>-- + +<*>--- ; ---------------------------------------------------------------------------------------- ; !!! this configuration expects an m5stack esp32 @@ -249,7 +251,7 @@ build_flags = -D ILI9341_DRIVER -D SMOOTH_FONT build_src_filter = - +<*>-- + +<*>--- ; ---------------------------------------------------------------------------------------- ; !!! this configuration expects an ESP32-S3 16MB Flash 8MB RAM ; @@ -258,9 +260,11 @@ build_src_filter = board = esp32-s3-devkitc-1 board_build.partitions = large_spiffs_16MB.csv build_unflags = - -D ARDUINO_USB_MODE=1 - -D CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y - -D ILI9341_DRIVER + -D ARDUINO_USB_MODE=1 + -D CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y + -D ILI9341_DRIVER +lib_deps = + ${env.lib_deps} build_flags = ${env.build_flags} -D YELLOW_IPS_AP @@ -282,6 +286,7 @@ build_flags = -D FLASHER_AP_RXD=18 -D FLASHER_DEBUG_TXD=19 -D FLASHER_DEBUG_RXD=20 + -D FLASHER_DEBUG_PROG=21 -D FLASHER_LED=16 -D HAS_RGB_LED -D FLASHER_RGB_LED=48 @@ -297,6 +302,10 @@ build_flags = -D TFT_RGB_ORDER=TFT_BGR -D USE_HSPI_PORT -D LOAD_FONT2 + -D MD5_ENABLED=1 + -D SERIAL_FLASHER_INTERFACE_UART=1 + -D SERIAL_FLASHER_BOOT_HOLD_TIME_MS=50 + -D SERIAL_FLASHER_RESET_HOLD_TIME_MS=100 build_src_filter = +<*>-- board_build.flash_mode=qio @@ -331,7 +340,7 @@ build_flags = -D FLASHER_AP_RXD=23 -D FLASHER_LED=2 build_src_filter = - +<*>-- + +<*>--- board_build.psram_type=qspi_opi board_upload.maximum_size = 4194304 board_upload.maximum_ram_size = 327680 @@ -366,7 +375,7 @@ build_flags = -D FLASHER_LED=2 -D FLASHER_RGB_LED=-1 build_src_filter = - +<*>-- + +<*>--- board_build.psram_type=qspi_opi board_upload.maximum_size = 4194304 board_upload.maximum_ram_size = 327680 @@ -405,7 +414,7 @@ build_flags = -D FLASHER_LED=21 -D FLASHER_RGB_LED=38 build_src_filter = - +<*>-- + +<*>--- board_build.flash_mode=opi board_build.arduino.memory_type = opi_opi board_build.psram_type=qspi_opi diff --git a/ESP32_AP-Flasher/src/espflasher.cpp b/ESP32_AP-Flasher/src/espflasher.cpp new file mode 100644 index 00000000..3b8c3ab4 --- /dev/null +++ b/ESP32_AP-Flasher/src/espflasher.cpp @@ -0,0 +1,185 @@ +#include +#include + +#include "esp32_port.h" +#include "esp_littlefs.h" +#include "storage.h" +#include "web.h" + +esp_loader_error_t connect_to_target(uint32_t higher_transmission_rate) { + esp_loader_connect_args_t connect_config = ESP_LOADER_CONNECT_DEFAULT(); + esp_loader_error_t err = esp_loader_connect(&connect_config); + if (err != ESP_LOADER_SUCCESS) { + printf("Cannot connect to target. Error: %u\n", err); + return err; + } + printf("Connected to target\n"); + + if (higher_transmission_rate && esp_loader_get_target() != ESP8266_CHIP) { + err = esp_loader_change_transmission_rate(higher_transmission_rate); + if (err == ESP_LOADER_ERROR_UNSUPPORTED_FUNC) { + printf("ESP8266 does not support change transmission rate command."); + return err; + } else if (err != ESP_LOADER_SUCCESS) { + printf("Unable to change transmission rate on target."); + return err; + } else { + err = loader_port_change_transmission_rate(higher_transmission_rate); + if (err != ESP_LOADER_SUCCESS) { + printf("Unable to change transmission rate."); + return err; + } + printf("Transmission rate changed\n"); + } + } + return ESP_LOADER_SUCCESS; +} + +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) + +esp_loader_error_t flash_binary(const char *file_path, size_t address) { + esp_loader_error_t err; + + wsSerial("Flashing " + String(file_path)); + + File file = contentFS->open(file_path, "rb"); + if (!file) { + wsSerial("Failed to open file"); + return ESP_LOADER_ERROR_FAIL; + } + + size_t size = file.size(); + static uint8_t payload[1024]; + Serial.println("file size: " + String(size)); + + printf("Erasing flash (this may take a while)...\n"); + err = esp_loader_flash_start(address, size, sizeof(payload)); + if (err != ESP_LOADER_SUCCESS) { + wsSerial("Erasing flash failed"); + file.close(); + return err; + } + printf("Start programming\n"); + + size_t written = 0; + size_t sizeleft = size; + uint32_t t = millis(); + while (sizeleft > 0) { + size_t to_read = MIN(sizeleft, sizeof(payload)); + size_t bytes_read = file.readBytes(reinterpret_cast(payload), to_read); + + if (bytes_read != to_read) { + wsSerial("Failed to read file."); + file.close(); + return ESP_LOADER_ERROR_FAIL; + } + + err = esp_loader_flash_write(payload, to_read); + if (err != ESP_LOADER_SUCCESS) { + wsSerial("Packet could not be written!"); + file.close(); + return err; + } + + sizeleft -= to_read; + written += to_read; + + if (millis() - t > 250) { + uint32_t progress = written * 100 / size; + // printf("\rProgress: %d%%", progress); + wsSerial("Progress: " + String(progress) + "%"); + fflush(stdout); + t = millis(); + } + }; + wsSerial("Progress: 100%"); + + file.close(); + printf("\nFinished programming\n"); + +#if MD5_ENABLED + err = esp_loader_flash_verify(); + if (err == ESP_LOADER_ERROR_UNSUPPORTED_FUNC) { + printf("ESP8266 does not support flash verify command."); + return err; + } else if (err != ESP_LOADER_SUCCESS) { + wsSerial("MD5 does not match."); + return err; + } + wsSerial("Flash verified"); +#endif + + vTaskDelay(1000 / portTICK_PERIOD_MS); + return ESP_LOADER_SUCCESS; +} + +bool doC6flash() { + const loader_esp32_config_t config = { + .baud_rate = 115200, + .uart_port = 2, + .uart_rx_pin = FLASHER_DEBUG_TXD, + .uart_tx_pin = FLASHER_DEBUG_RXD, + .reset_trigger_pin = FLASHER_AP_RESET, + .gpio0_trigger_pin = FLASHER_DEBUG_PROG, + }; + + if (loader_port_esp32_init(&config) != ESP_LOADER_SUCCESS) { + wsSerial("Serial initialization failed"); + loader_port_esp32_deinit(); + return false; + } + + if (connect_to_target(230400) == ESP_LOADER_SUCCESS) { + if (esp_loader_get_target() == ESP32C6_CHIP) { + wsSerial("Connected to ESP32-C6"); + int maxRetries = 5; + esp_loader_error_t err; + + for (int retry = 0; retry < maxRetries; retry++) { + err = flash_binary("/bootloader.bin", 0x0); + if (err == ESP_LOADER_SUCCESS) break; + Serial.printf("Flash failed with error %d. Retrying...\n", err); + delay(1000); + } + if (err != ESP_LOADER_SUCCESS) { + loader_port_esp32_deinit(); + return false; + } + + for (int retry = 0; retry < maxRetries; retry++) { + err = flash_binary("/partition-table.bin", 0x8000); + if (err == ESP_LOADER_SUCCESS) break; + Serial.printf("Flash failed with error %d. Retrying...\n", err); + delay(1000); + } + if (err != ESP_LOADER_SUCCESS) { + loader_port_esp32_deinit(); + return false; + } + + for (int retry = 0; retry < maxRetries; retry++) { + err = flash_binary("/OpenEPaperLink_esp32_C6.bin", 0x10000); + if (err == ESP_LOADER_SUCCESS) break; + Serial.printf("Flash failed with error %d. Retrying...\n", err); + delay(1000); + } + if (err != ESP_LOADER_SUCCESS) { + loader_port_esp32_deinit(); + return false; + } + + Serial.println("Done!"); + } else { + wsSerial("Connected to wrong ESP32 type"); + loader_port_esp32_deinit(); + return false; + } + } else { + wsSerial("Connection failed"); + loader_port_esp32_deinit(); + return false; + } + loader_port_esp32_deinit(); + return true; +} diff --git a/ESP32_AP-Flasher/src/ota.cpp b/ESP32_AP-Flasher/src/ota.cpp index f899622c..c64b5a23 100644 --- a/ESP32_AP-Flasher/src/ota.cpp +++ b/ESP32_AP-Flasher/src/ota.cpp @@ -7,6 +7,8 @@ #include #include +#include "espflasher.h" +#include "serialap.h" #include "storage.h" #include "tag_db.h" #include "util.h" @@ -234,6 +236,60 @@ void handleRollback(AsyncWebServerRequest* request) { } } +void C6firmwareUpdateTask(void* parameter) { + wsSerial("Stopping AP service"); + + apInfo.isOnline = false; + apInfo.state = AP_STATE_FLASHING; + config.runStatus = RUNSTATUS_STOP; + extern bool rxSerialStopTask2; + rxSerialStopTask2 = true; + Serial1.end(); + delay(250); + + wsSerial("C6 flash starting"); + + bool result = doC6flash(); + + wsSerial("C6 flash end"); + + if (result) { + apInfo.state = AP_STATE_OFFLINE; + + wsSerial("Finishing config..."); + vTaskDelay(3000 / portTICK_PERIOD_MS); + + wsSerial("starting monitor"); + Serial1.begin(115200, SERIAL_8N1, FLASHER_AP_RXD, FLASHER_AP_TXD); + rxSerialStopTask2 = false; +#ifdef FLASHER_DEBUG_RXD + xTaskCreate(rxSerialTask2, "rxSerialTask2", 1750, NULL, configMAX_PRIORITIES - 4, NULL); +#endif + vTaskDelay(1000 / portTICK_PERIOD_MS); + + wsSerial("resetting AP"); + APTagReset(); + vTaskDelay(1000 / portTICK_PERIOD_MS); + + wsSerial("bringing AP online"); + if (bringAPOnline()) config.runStatus = RUNSTATUS_RUN; + + wsSerial("Finished!"); + } else { + wsSerial("Flashing failed. :-("); + } + vTaskDelete(NULL); +} + +void handleUpdateC6(AsyncWebServerRequest* request) { +#ifdef YELLOW_IPS_AP + xTaskCreate(C6firmwareUpdateTask, "OTAUpdateTask", 6144, NULL, 10, NULL); + request->send(200, "Ok"); +#else + request->send(400, "C6 flashing not implemented"); +#endif +} + void handleUpdateActions(AsyncWebServerRequest* request) { wsSerial("Performing cleanup"); File file = contentFS->open("/update_actions.json", "r"); diff --git a/ESP32_AP-Flasher/src/serialap.cpp b/ESP32_AP-Flasher/src/serialap.cpp index b851f5c7..5c00d44f 100644 --- a/ESP32_AP-Flasher/src/serialap.cpp +++ b/ESP32_AP-Flasher/src/serialap.cpp @@ -15,6 +15,7 @@ #include "zbs_interface.h" QueueHandle_t rxCmdQueue; + SemaphoreHandle_t txActive; // If a command is sent, it will wait for a reply here @@ -25,8 +26,9 @@ SemaphoreHandle_t txActive; volatile uint8_t cmdReplyValue = CMD_REPLY_WAIT; #define AP_SERIAL_PORT Serial1 +volatile bool rxSerialStopTask2 = false; -uint8_t channelList[6]; + uint8_t channelList[6]; struct espSetChannelPower curChannel = {0, 11, 10}; #define RX_CMD_RQB 0x01 @@ -264,6 +266,7 @@ bool sendChannelPower(struct espSetChannelPower* scp) { return false; } bool sendPing() { + if (apInfo.state == AP_STATE_FLASHING) return true; Serial.print("ping"); int t = millis(); if (!txStart()) return false; @@ -582,13 +585,16 @@ void rxSerialTask(void* parameter) { void rxSerialTask2(void* parameter) { char lastchar = 0; Serial2.begin(115200, SERIAL_8N1, FLASHER_DEBUG_TXD, FLASHER_DEBUG_RXD); - while (1) { + while (rxSerialStopTask2 == false) { while (Serial2.available()) { lastchar = Serial2.read(); Serial.write(lastchar); } vTaskDelay(1 / portTICK_PERIOD_MS); } + Serial2.end(); + Serial.println("Exiting AP serial monitor"); + vTaskDelete(NULL); } #endif @@ -640,6 +646,7 @@ void segmentedShowIp() { } bool bringAPOnline() { + if (apInfo.state == AP_STATE_FLASHING) return false; apInfo.isOnline = false; apInfo.state = AP_STATE_OFFLINE; // try without rebooting @@ -651,6 +658,7 @@ bool bringAPOnline() { vTaskDelay(300 / portTICK_PERIOD_MS); } if (!APrdy) { + if (apInfo.state == AP_STATE_FLASHING) return false; APTagReset(); vTaskDelay(500 / portTICK_PERIOD_MS); bootTimeout = millis(); @@ -733,39 +741,42 @@ void APTask(void* parameter) { updateContent(apInfo.mac); } - uint16_t fsversion; - fsversion = getAPUpdateVersion(apInfo.type); - if ((fsversion) && (apInfo.version != fsversion) && (FLASHER_AP_MOSI != -1)) { - Serial.printf("Firmware version on LittleFS: %04X\n", fsversion); - Serial.printf("We're going to try to update the AP's FW in\n"); - flashCountDown(30); - Serial.printf("\n"); - notifySegmentedFlash(); - apInfo.isOnline = false; - apInfo.state = AP_STATE_FLASHING; - if (doAPUpdate(apInfo.type)) { - checkWaitPowerCycle(); - Serial.printf("Flash completed, let's try to boot the AP!\n"); - if (bringAPOnline()) { - // AP works - ShowAPInfo(); - setAPchannel(); + uint16_t fsversion; + if (FLASHER_AP_MOSI != -1) { + fsversion = getAPUpdateVersion(apInfo.type); + if ((fsversion) && (apInfo.version != fsversion)) { + Serial.printf("Firmware version on LittleFS: %04X\n", fsversion); + + Serial.printf("We're going to try to update the AP's FW in\n"); + flashCountDown(30); + Serial.printf("\n"); + notifySegmentedFlash(); + apInfo.isOnline = false; + apInfo.state = AP_STATE_FLASHING; + if (doAPUpdate(apInfo.type)) { + checkWaitPowerCycle(); + Serial.printf("Flash completed, let's try to boot the AP!\n"); + if (bringAPOnline()) { + // AP works + ShowAPInfo(); + setAPchannel(); + } else { + Serial.printf("Failed to bring up the AP after flashing seemed successful... That's not supposed to happen!\n"); + Serial.printf("This can be caused by a bad AP firmware, failed or failing hardware, or the inability to fully power-cycle the AP\n"); + apInfo.state = AP_STATE_FAILED; + #ifdef HAS_RGB_LED + showColorPattern(CRGB::Red, CRGB::Yellow, CRGB::Red); + #endif + } } else { - Serial.printf("Failed to bring up the AP after flashing seemed successful... That's not supposed to happen!\n"); - Serial.printf("This can be caused by a bad AP firmware, failed or failing hardware, or the inability to fully power-cycle the AP\n"); apInfo.state = AP_STATE_FAILED; -#ifdef HAS_RGB_LED - showColorPattern(CRGB::Red, CRGB::Yellow, CRGB::Red); -#endif + checkWaitPowerCycle(); + Serial.println("Failed to update version on the AP :(\n"); + #ifdef HAS_RGB_LED + showColorPattern(CRGB::Red, CRGB::Red, CRGB::Red); + #endif } - } else { - apInfo.state = AP_STATE_FAILED; - checkWaitPowerCycle(); - Serial.println("Failed to update version on the AP :(\n"); -#ifdef HAS_RGB_LED - showColorPattern(CRGB::Red, CRGB::Red, CRGB::Red); -#endif } } refreshAllPending(); @@ -774,14 +785,23 @@ void APTask(void* parameter) { #define FLASH_TIMEOUT 30 #endif - // AP unavailable, maybe time to flash? - apInfo.isOnline = false; - apInfo.state = AP_STATE_OFFLINE; - Serial.printf("I wasn't able to connect to a ZBS (AP) tag.\n"); - Serial.printf("This could be the first time this AP is booted and the AP-tag may be unflashed.\n"); - Serial.printf("If this tag was previously flashed succesfully but this message still shows up, there's probably something wrong with the serial connections.\n"); - Serial.printf("The build of this firmware expects an AP tag with TXD/RXD on ESP32 pins %d and %d, does this match with your wiring?\n", FLASHER_AP_RXD, FLASHER_AP_TXD); - if (FLASHER_AP_MOSI != -1) { + if (FLASHER_AP_MOSI == -1) { + Serial.printf("I wasn't able to connect to the AP radio. Did you flash it?\n"); + Serial.printf("The build of this firmware expects an AP tag with TXD/RXD on ESP32 pins %d and %d, does this match with your wiring?\n", FLASHER_AP_RXD, FLASHER_AP_TXD); +#ifdef HAS_RGB_LED + showColorPattern(CRGB::Red, CRGB::Yellow, CRGB::Red); +#endif + apInfo.isOnline = false; + apInfo.state = AP_STATE_FAILED; + } else { + // AP unavailable, maybe time to flash? + apInfo.isOnline = false; + apInfo.state = AP_STATE_OFFLINE; + + Serial.printf("I wasn't able to connect to a ZBS (AP) tag.\n"); + Serial.printf("This could be the first time this AP is booted and the AP-tag may be unflashed.\n"); + Serial.printf("If this tag was previously flashed succesfully but this message still shows up, there's probably something wrong with the serial connections.\n"); + Serial.printf("The build of this firmware expects an AP tag with TXD/RXD on ESP32 pins %d and %d, does this match with your wiring?\n", FLASHER_AP_RXD, FLASHER_AP_TXD); Serial.printf("Performing firmware flash in about %d seconds!\n", FLASH_TIMEOUT); flashCountDown(FLASH_TIMEOUT); if (doAPFlash()) { diff --git a/ESP32_AP-Flasher/src/web.cpp b/ESP32_AP-Flasher/src/web.cpp index ee845054..28c0f9c5 100644 --- a/ESP32_AP-Flasher/src/web.cpp +++ b/ESP32_AP-Flasher/src/web.cpp @@ -578,6 +578,7 @@ void init_web() { server.on("/sysinfo", HTTP_GET, handleSysinfoRequest); server.on("/check_file", HTTP_GET, handleCheckFile); server.on("/rollback", HTTP_POST, handleRollback); + server.on("/update_c6", HTTP_POST, handleUpdateC6); server.on("/update_actions", HTTP_POST, handleUpdateActions); server.on("/update_ota", HTTP_POST, [](AsyncWebServerRequest *request) { handleUpdateOTA(request); diff --git a/ESP32_AP-Flasher/wwwroot/index.html b/ESP32_AP-Flasher/wwwroot/index.html index 364bb9da..cdbd1048 100644 --- a/ESP32_AP-Flasher/wwwroot/index.html +++ b/ESP32_AP-Flasher/wwwroot/index.html @@ -224,7 +224,10 @@ to save file system space">
- +
+ +
+
diff --git a/ESP32_AP-Flasher/wwwroot/main.css b/ESP32_AP-Flasher/wwwroot/main.css index aad740d8..38904656 100644 --- a/ESP32_AP-Flasher/wwwroot/main.css +++ b/ESP32_AP-Flasher/wwwroot/main.css @@ -532,6 +532,11 @@ ul.messages li.new { display: none; } +#advanceddiv div:nth-child(2) { + display: flex; + gap: 10px; +} + #releasetable { margin: 10px 0px; } diff --git a/ESP32_AP-Flasher/wwwroot/ota.js b/ESP32_AP-Flasher/wwwroot/ota.js index 7b41b106..b77d9312 100644 --- a/ESP32_AP-Flasher/wwwroot/ota.js +++ b/ESP32_AP-Flasher/wwwroot/ota.js @@ -336,6 +336,25 @@ $('#rollbackBtn').onclick = function () { disableButtons(false); } +$('#updateC6Btn').onclick = function () { + if (running) return; + disableButtons(true); + running = true; + errors = 0; + const consoleDiv = document.getElementById('updateconsole'); + consoleDiv.scrollTop = consoleDiv.scrollHeight; + + print("Flashing ESP32-C6..."); + + fetch("/update_c6", { + method: "POST", + body: '' + }) + + running = false; + disableButtons(false); +} + export function print(line, color = "white") { const consoleDiv = document.getElementById('updateconsole'); if (consoleDiv) {