From 2e14faeef6caf05fd8de603d4fbb45e765b31e6a Mon Sep 17 00:00:00 2001 From: Nicholas Sherlock Date: Wed, 28 Jan 2015 20:48:06 +1300 Subject: [PATCH] Comment updates, allow CLI flash read to read more in one operation --- src/main/drivers/flash_m25p16.c | 6 +++++- src/main/io/flashfs.c | 11 +++++------ src/main/io/serial_cli.c | 20 +++++++++++--------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/main/drivers/flash_m25p16.c b/src/main/drivers/flash_m25p16.c index 864eacd77..3eac01041 100644 --- a/src/main/drivers/flash_m25p16.c +++ b/src/main/drivers/flash_m25p16.c @@ -97,6 +97,7 @@ static uint8_t m25p16_readStatus() bool m25p16_isReady() { + // If couldBeBusy is false, don't bother to poll the flash chip for its status couldBeBusy = couldBeBusy && ((m25p16_readStatus() & M25P16_STATUS_FLAG_WRITE_IN_PROGRESS) != 0); return !couldBeBusy; @@ -126,7 +127,10 @@ static bool m25p16_readIdentification() delay(50); // short delay required after initialisation of SPI device instance. - in[1] = 0; // Just in case transfer fails and writes nothing + /* Just in case transfer fails and writes nothing, so we don't try to verify the ID against random garbage + * from the stack: + */ + in[1] = 0; ENABLE_M25P16; diff --git a/src/main/io/flashfs.c b/src/main/io/flashfs.c index 3a6795ff1..015738eb3 100644 --- a/src/main/io/flashfs.c +++ b/src/main/io/flashfs.c @@ -114,15 +114,11 @@ static uint32_t flashfsTransmitBufferUsed() static uint32_t flashfsTransmitBufferRemaining() { - /* - * We subtract one from the actual transmit buffer remaining space to allow us to distinguish - * between completely full and completely empty states, that would otherwise both have head = tail - */ return FLASHFS_WRITE_BUFFER_USABLE - flashfsTransmitBufferUsed(); } /** - * Waits for the flash device to be ready to accept writes, then write the given buffers to flash. + * Waits for the flash device to be ready to accept writes, then write the given buffers to flash sequentially. * * Advances the address of the beginning of the supplied buffers and reduces the size of the buffers according to how * many bytes get written. @@ -150,7 +146,10 @@ static void flashfsWriteBuffers(uint8_t const **buffers, uint32_t *bufferSizes, uint32_t bytesTotalThisIteration; uint32_t bytesRemainThisIteration; - // If we would cross a page boundary, only write up to the boundary in this iteration: + /* + * Each page needs to be saved in a separate program operation, so + * if we would cross a page boundary, only write up to the boundary in this iteration: + */ if (tailIndexInPage + bytesTotalRemaining > geometry->pageSize) { bytesTotalThisIteration = geometry->pageSize - tailIndexInPage; } else { diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index 66aaf3464..c4e010cc5 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -44,7 +44,6 @@ #include "drivers/gpio.h" #include "drivers/timer.h" #include "drivers/pwm_rx.h" -#include "drivers/flash_m25p16.h" #include "flight/flight.h" #include "flight/mixer.h" #include "flight/navigation.h" @@ -794,18 +793,21 @@ static void cliFlashRead(char *cmdline) printf("Missing length argument.\r\n"); } else { length = atoi(nextArg); - if (length > 32) { - length = 32; - printf("Length truncated to 32 bytes.\r\n"); - } + + printf("Reading %u bytes at %u:\r\n", length, address); flashfsSeekAbs(address); - flashfsRead(buffer, length); - printf("Read %u bytes at %u:\r\n", length, address); + while (length > 0) { + int bytesToRead = length < 32 ? length : 32; - for (i = 0; i < length; i++) { - printf("%c", (char) buffer[i]); + flashfsRead(buffer, bytesToRead); + + for (i = 0; i < bytesToRead; i++) { + printf("%c", (char) buffer[i]); + } + + length -= bytesToRead; } printf("\r\n"); }