From 3e842b67d4d6b3f3d1d3dd381f0dcb8880a31eb0 Mon Sep 17 00:00:00 2001 From: Steve Evans Date: Sat, 10 Sep 2022 20:57:51 +0100 Subject: [PATCH] Correctly terminate segments list with u.link --- src/main/drivers/sdcard_spi.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/drivers/sdcard_spi.c b/src/main/drivers/sdcard_spi.c index e66fabffef..e728cbc4cf 100644 --- a/src/main/drivers/sdcard_spi.c +++ b/src/main/drivers/sdcard_spi.c @@ -169,7 +169,8 @@ static bool sdcard_waitForIdle(int maxBytesToWait) // Note that this does not release the CS at the end of the transaction busSegment_t segments[] = { {.u.buffers = {NULL, &idleByte}, sizeof(idleByte), false, sdcard_callbackIdle}, - {.u.buffers = {NULL, NULL}, 0, false, NULL}, + {.u.link = {NULL, NULL}, 0, true, NULL}, + }; sdcard.idleCount = maxBytesToWait; @@ -194,7 +195,8 @@ static uint8_t sdcard_waitForNonIdleByte(int maxDelay) // Note that this does not release the CS at the end of the transaction busSegment_t segments[] = { {.u.buffers = {NULL, &idleByte}, sizeof(idleByte), false, sdcard_callbackNotIdle}, - {.u.buffers = {NULL, NULL}, 0, false, NULL}, + {.u.link = {NULL, NULL}, 0, true, NULL}, + }; sdcard.idleCount = maxDelay; @@ -234,7 +236,8 @@ static uint8_t sdcard_sendCommand(uint8_t commandCode, uint32_t commandArgument) busSegment_t segments[] = { {.u.buffers = {command, NULL}, sizeof(command), false, NULL}, {.u.buffers = {NULL, &idleByte}, sizeof(idleByte), false, sdcard_callbackNotIdle}, - {.u.buffers = {NULL, NULL}, 0, false, NULL}, + {.u.link = {NULL, NULL}, 0, true, NULL}, + }; if (!sdcard_waitForIdle(SDCARD_MAXIMUM_BYTE_DELAY_FOR_CMD_REPLY) && commandCode != SDCARD_COMMAND_GO_IDLE_STATE) @@ -280,7 +283,8 @@ static bool sdcard_validateInterfaceCondition(void) // Note that this does not release the CS at the end of the transaction busSegment_t segments[] = { {.u.buffers = {NULL, ifCondReply}, sizeof(ifCondReply), false, NULL}, - {.u.buffers = {NULL, NULL}, 0, false, NULL}, + {.u.link = {NULL, NULL}, 0, true, NULL}, + }; spiSequence(&sdcard.dev, &segments[0]); @@ -313,7 +317,8 @@ static bool sdcard_readOCRRegister(uint32_t *result) // Note that this does not release the CS at the end of the transaction busSegment_t segments[] = { {.u.buffers = {NULL, response}, sizeof(response), false, NULL}, - {.u.buffers = {NULL, NULL}, 0, false, NULL}, + {.u.link = {NULL, NULL}, 0, true, NULL}, + }; spiSequence(&sdcard.dev, &segments[0]); @@ -362,7 +367,8 @@ static sdcardReceiveBlockStatus_e sdcard_receiveDataBlock(uint8_t *buffer, int c {.u.buffers = {NULL, buffer}, count, false, NULL}, // Discard trailing CRC, we don't care {.u.buffers = {NULL, NULL}, 2, false, NULL}, - {.u.buffers = {NULL, NULL}, 0, false, NULL}, + {.u.link = {NULL, NULL}, 0, true, NULL}, + }; spiSequence(&sdcard.dev, &segments[0]); @@ -381,7 +387,8 @@ static bool sdcard_sendDataBlockFinish(void) busSegment_t segments[] = { {.u.buffers = {(uint8_t *)&dummyCRC, NULL}, sizeof(dummyCRC), false, NULL}, {.u.buffers = {NULL, &dataResponseToken}, sizeof(dataResponseToken), false, NULL}, - {.u.buffers = {NULL, NULL}, 0, false, NULL}, + {.u.link = {NULL, NULL}, 0, true, NULL}, + }; spiSequence(&sdcard.dev, &segments[0]); @@ -419,7 +426,8 @@ static void sdcard_sendDataBlockBegin(uint8_t *buffer, bool multiBlockWrite) {.u.buffers = {NULL, NULL}, 1, false, NULL}, {.u.buffers = {&token, NULL}, sizeof(token), false, NULL}, {.u.buffers = {NULL, NULL}, 0, false, NULL}, - {.u.buffers = {NULL, NULL}, 0, false, NULL}, + {.u.link = {NULL, NULL}, 0, true, NULL}, + }; segments[2].u.buffers.txData = buffer; @@ -563,7 +571,7 @@ static void sdcardSpi_init(const sdcardConfig_t *config, const spiPinConfig_t *s busSegment_t segments[] = { // Write a single 0xff {.u.buffers = {NULL, NULL}, SDCARD_INIT_NUM_DUMMY_BYTES, false, NULL}, - {.u.buffers = {NULL, NULL}, 0, false, NULL}, + {.u.link = {NULL, NULL}, 0, true, NULL}, }; spiSequence(&sdcard.dev, &segments[0]); @@ -615,7 +623,8 @@ static sdcardOperationStatus_e sdcard_endWriteBlocks(void) // 8 dummy clocks to guarantee N_WR clocks between the last card response and this token {.u.buffers = {NULL, NULL}, 1, false, NULL}, {.u.buffers = {&token, NULL}, sizeof(token), false, NULL}, - {.u.buffers = {NULL, NULL}, 0, false, NULL}, + {.u.link = {NULL, NULL}, 0, true, NULL}, + }; spiSequence(&sdcard.dev, &segments[0]);