Skip to content

Commit 961f74b

Browse files
authored
Merge pull request #1160 from bitcraze/krichardsson/ai-deck-flash
AI-deck GAP8 flash write error check
2 parents e82ba19 + 620abe0 commit 961f74b

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

src/deck/drivers/src/aideck.c

+13-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include "debug.h"
4444
#include "deck.h"
4545
#include "esp_deck_flasher.h"
46-
#include "FreeRTOS.h"
4746
#include "task.h"
4847
#include "event_groups.h"
4948
#include "queue.h"
@@ -78,6 +77,9 @@ static bool isInit = false;
7877

7978
#define CPX_ENABLE_CRTP_BRIDGE 0x10
8079

80+
#define GAP8_MAX_MEM_WRITE_TIMEOUT_MS 5000
81+
#define GAP8_MAX_MEM_VERIFY_TIMEOUT_MS 5000
82+
8183
typedef struct {
8284
uint8_t cmd;
8385
uint32_t startAddress;
@@ -126,7 +128,8 @@ static bool gap8DeckFlasherWrite(const uint32_t memAddr, const uint8_t writeLen,
126128
gap8BlPacket->startAddress = 0x40000;
127129
gap8BlPacket->writeSize = *(memDef->newFwSizeP);
128130
bootPacket.dataLength = sizeof(GAP8BlCmdPacket_t);
129-
cpxSendPacketBlocking(&bootPacket);
131+
bool writeOk = cpxSendPacketBlockingTimeout(&bootPacket, M2T(GAP8_MAX_MEM_WRITE_TIMEOUT_MS));
132+
ASSERT(writeOk);
130133
}
131134

132135
// The GAP8 can only flash data in multiples of 4 bytes,
@@ -144,7 +147,8 @@ static bool gap8DeckFlasherWrite(const uint32_t memAddr, const uint8_t writeLen,
144147
memcpy(&bootPacket.data, flashBuffer, flashBufferIndex);
145148
bootPacket.dataLength = flashBufferIndex;
146149

147-
cpxSendPacketBlocking(&bootPacket);
150+
bool writeOk = cpxSendPacketBlockingTimeout(&bootPacket, M2T(GAP8_MAX_MEM_WRITE_TIMEOUT_MS));
151+
ASSERT(writeOk);
148152

149153
flashBufferIndex = 0;
150154
int sizeLeftToBuffer = writeLen - sizeLeftToBufferFull;
@@ -163,13 +167,16 @@ static bool gap8DeckFlasherWrite(const uint32_t memAddr, const uint8_t writeLen,
163167
gap8BlPacket->startAddress = 0x40000;
164168
gap8BlPacket->writeSize = *(memDef->newFwSizeP);
165169
bootPacket.dataLength = sizeof(GAP8BlCmdPacket_t);
166-
cpxSendPacketBlocking(&bootPacket);
170+
bool writeOk = cpxSendPacketBlockingTimeout(&bootPacket, M2T(GAP8_MAX_MEM_WRITE_TIMEOUT_MS));
171+
ASSERT(writeOk);
167172

168-
xEventGroupWaitBits(bootloaderSync,
173+
EventBits_t bits = xEventGroupWaitBits(bootloaderSync,
169174
CPX_WAIT_FOR_BOOTLOADER_REPLY,
170175
pdTRUE, // Clear bits before returning
171176
pdFALSE, // Wait for any bit
172-
portMAX_DELAY);
177+
M2T(GAP8_MAX_MEM_VERIFY_TIMEOUT_MS));
178+
bool flashWritten = (bits & CPX_WAIT_FOR_BOOTLOADER_REPLY);
179+
ASSERT(flashWritten);
173180
}
174181

175182
return true;

src/modules/interface/cpx/cpx_internal_router.h

+15-7
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929

3030
/**
3131
* @brief Initialize the internal router
32-
*
32+
*
3333
* Initialize the internal router, used for routing CPX packets
3434
* on function inside the STM32.
3535
*
3636
*/
3737
void cpxInternalRouterInit(void);
3838

3939
/**
40-
* @brief Send a CPX packet
40+
* @brief Send a CPX packet, blocking
4141
*
4242
* This will send a packet to the ESP32 to be routed using CPX. This
4343
* will block until the packet can be queued up for sending.
@@ -46,17 +46,26 @@ void cpxInternalRouterInit(void);
4646
*/
4747
void cpxSendPacketBlocking(const CPXPacket_t * packet);
4848

49+
/**
50+
* @brief Send a CPX packet, blocking with timeout
51+
*
52+
* @param packet packet to be sent
53+
* @param timeout Timeout in ticks
54+
* @return True if sent, false if timeout
55+
*/
56+
bool cpxSendPacketBlockingTimeout(const CPXPacket_t * packet, const uint32_t timeout);
57+
4958
/**
5059
* @brief Receive a CPX packet sent with the CRTP function
51-
*
60+
*
5261
* @param packet CPX packet where received packet is stored
5362
* @return int 0 if no packet was received otherwise non zero.
5463
*/
5564
int cpxInternalRouterReceiveCRTP(CPXPacket_t * packet);
5665

5766
/**
5867
* @brief Receive a CPX packet sent with another function than CRTP
59-
*
68+
*
6069
* @param packet CPX packet where received packet is stored
6170
* @return int 0 if no packet was received otherwise non zero.
6271
*/
@@ -65,16 +74,15 @@ void cpxInternalRouterReceiveOthers(CPXPacket_t * packet);
6574
/**
6675
* @brief Send a CPX packet from the external router into the internal
6776
* router
68-
*
77+
*
6978
* @param packet CPX packet to send
7079
*/
7180
void cpxInternalRouterRouteIn(const CPXRoutablePacket_t* packet);
7281

7382
/**
7483
* @brief Retrieve a CPX packet from the internal router to be
7584
* routed externally.
76-
*
85+
*
7786
* @param packet CPX packet where retrieved packet is stored
7887
*/
7988
void cpxInternalRouterRouteOut(CPXRoutablePacket_t* packet);
80-

src/modules/src/cpx/cpx_internal_router.c

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ void cpxSendPacketBlocking(const CPXPacket_t * packet) {
5454
xQueueSend(txq, packet, portMAX_DELAY);
5555
}
5656

57+
bool cpxSendPacketBlockingTimeout(const CPXPacket_t * packet, const uint32_t timeout) {
58+
return xQueueSend(txq, packet, timeout) == pdTRUE;
59+
}
60+
5761
bool cpxSendPacket(const CPXPacket_t * packet, uint32_t timeout) {
5862
return true;
5963
}

0 commit comments

Comments
 (0)