mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 04:15:44 +03:00
Comment updates, allow CLI flash read to read more in one operation
This commit is contained in:
parent
3eb28f16ea
commit
2e14faeef6
3 changed files with 21 additions and 16 deletions
|
@ -97,6 +97,7 @@ static uint8_t m25p16_readStatus()
|
||||||
|
|
||||||
bool m25p16_isReady()
|
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);
|
couldBeBusy = couldBeBusy && ((m25p16_readStatus() & M25P16_STATUS_FLAG_WRITE_IN_PROGRESS) != 0);
|
||||||
|
|
||||||
return !couldBeBusy;
|
return !couldBeBusy;
|
||||||
|
@ -126,7 +127,10 @@ static bool m25p16_readIdentification()
|
||||||
|
|
||||||
delay(50); // short delay required after initialisation of SPI device instance.
|
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;
|
ENABLE_M25P16;
|
||||||
|
|
||||||
|
|
|
@ -114,15 +114,11 @@ static uint32_t flashfsTransmitBufferUsed()
|
||||||
|
|
||||||
static uint32_t flashfsTransmitBufferRemaining()
|
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();
|
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
|
* Advances the address of the beginning of the supplied buffers and reduces the size of the buffers according to how
|
||||||
* many bytes get written.
|
* many bytes get written.
|
||||||
|
@ -150,7 +146,10 @@ static void flashfsWriteBuffers(uint8_t const **buffers, uint32_t *bufferSizes,
|
||||||
uint32_t bytesTotalThisIteration;
|
uint32_t bytesTotalThisIteration;
|
||||||
uint32_t bytesRemainThisIteration;
|
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) {
|
if (tailIndexInPage + bytesTotalRemaining > geometry->pageSize) {
|
||||||
bytesTotalThisIteration = geometry->pageSize - tailIndexInPage;
|
bytesTotalThisIteration = geometry->pageSize - tailIndexInPage;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
#include "drivers/gpio.h"
|
#include "drivers/gpio.h"
|
||||||
#include "drivers/timer.h"
|
#include "drivers/timer.h"
|
||||||
#include "drivers/pwm_rx.h"
|
#include "drivers/pwm_rx.h"
|
||||||
#include "drivers/flash_m25p16.h"
|
|
||||||
#include "flight/flight.h"
|
#include "flight/flight.h"
|
||||||
#include "flight/mixer.h"
|
#include "flight/mixer.h"
|
||||||
#include "flight/navigation.h"
|
#include "flight/navigation.h"
|
||||||
|
@ -794,18 +793,21 @@ static void cliFlashRead(char *cmdline)
|
||||||
printf("Missing length argument.\r\n");
|
printf("Missing length argument.\r\n");
|
||||||
} else {
|
} else {
|
||||||
length = atoi(nextArg);
|
length = atoi(nextArg);
|
||||||
if (length > 32) {
|
|
||||||
length = 32;
|
printf("Reading %u bytes at %u:\r\n", length, address);
|
||||||
printf("Length truncated to 32 bytes.\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
flashfsSeekAbs(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++) {
|
flashfsRead(buffer, bytesToRead);
|
||||||
printf("%c", (char) buffer[i]);
|
|
||||||
|
for (i = 0; i < bytesToRead; i++) {
|
||||||
|
printf("%c", (char) buffer[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
length -= bytesToRead;
|
||||||
}
|
}
|
||||||
printf("\r\n");
|
printf("\r\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue