Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI-deck GAP8 flash write error check #1160

Merged
merged 1 commit into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/deck/drivers/src/aideck.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include "debug.h"
#include "deck.h"
#include "esp_deck_flasher.h"
#include "FreeRTOS.h"
#include "task.h"
#include "event_groups.h"
#include "queue.h"
Expand Down Expand Up @@ -78,6 +77,9 @@ static bool isInit = false;

#define CPX_ENABLE_CRTP_BRIDGE 0x10

#define GAP8_MAX_MEM_WRITE_TIMEOUT_MS 5000
#define GAP8_MAX_MEM_VERIFY_TIMEOUT_MS 5000

typedef struct {
uint8_t cmd;
uint32_t startAddress;
Expand Down Expand Up @@ -126,7 +128,8 @@ static bool gap8DeckFlasherWrite(const uint32_t memAddr, const uint8_t writeLen,
gap8BlPacket->startAddress = 0x40000;
gap8BlPacket->writeSize = *(memDef->newFwSizeP);
bootPacket.dataLength = sizeof(GAP8BlCmdPacket_t);
cpxSendPacketBlocking(&bootPacket);
bool writeOk = cpxSendPacketBlockingTimeout(&bootPacket, M2T(GAP8_MAX_MEM_WRITE_TIMEOUT_MS));
ASSERT(writeOk);
}

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

cpxSendPacketBlocking(&bootPacket);
bool writeOk = cpxSendPacketBlockingTimeout(&bootPacket, M2T(GAP8_MAX_MEM_WRITE_TIMEOUT_MS));
ASSERT(writeOk);

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

xEventGroupWaitBits(bootloaderSync,
EventBits_t bits = xEventGroupWaitBits(bootloaderSync,
CPX_WAIT_FOR_BOOTLOADER_REPLY,
pdTRUE, // Clear bits before returning
pdFALSE, // Wait for any bit
portMAX_DELAY);
M2T(GAP8_MAX_MEM_VERIFY_TIMEOUT_MS));
bool flashWritten = (bits & CPX_WAIT_FOR_BOOTLOADER_REPLY);
ASSERT(flashWritten);
}

return true;
Expand Down
22 changes: 15 additions & 7 deletions src/modules/interface/cpx/cpx_internal_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@

/**
* @brief Initialize the internal router
*
*
* Initialize the internal router, used for routing CPX packets
* on function inside the STM32.
*
*/
void cpxInternalRouterInit(void);

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

/**
* @brief Send a CPX packet, blocking with timeout
*
* @param packet packet to be sent
* @param timeout Timeout in ticks
* @return True if sent, false if timeout
*/
bool cpxSendPacketBlockingTimeout(const CPXPacket_t * packet, const uint32_t timeout);

/**
* @brief Receive a CPX packet sent with the CRTP function
*
*
* @param packet CPX packet where received packet is stored
* @return int 0 if no packet was received otherwise non zero.
*/
int cpxInternalRouterReceiveCRTP(CPXPacket_t * packet);

/**
* @brief Receive a CPX packet sent with another function than CRTP
*
*
* @param packet CPX packet where received packet is stored
* @return int 0 if no packet was received otherwise non zero.
*/
Expand All @@ -65,16 +74,15 @@ void cpxInternalRouterReceiveOthers(CPXPacket_t * packet);
/**
* @brief Send a CPX packet from the external router into the internal
* router
*
*
* @param packet CPX packet to send
*/
void cpxInternalRouterRouteIn(const CPXRoutablePacket_t* packet);

/**
* @brief Retrieve a CPX packet from the internal router to be
* routed externally.
*
*
* @param packet CPX packet where retrieved packet is stored
*/
void cpxInternalRouterRouteOut(CPXRoutablePacket_t* packet);

4 changes: 4 additions & 0 deletions src/modules/src/cpx/cpx_internal_router.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ void cpxSendPacketBlocking(const CPXPacket_t * packet) {
xQueueSend(txq, packet, portMAX_DELAY);
}

bool cpxSendPacketBlockingTimeout(const CPXPacket_t * packet, const uint32_t timeout) {
return xQueueSend(txq, packet, timeout) == pdTRUE;
}

bool cpxSendPacket(const CPXPacket_t * packet, uint32_t timeout) {
return true;
}
Expand Down