mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 03:50:02 +03:00
Nonblocking w25n01g code tidy up (#13562)
* In case of BUS_ABORT still process and linked segments * Tidy up segments * Set SPI clock speed for w25n01g
This commit is contained in:
parent
d447d795f4
commit
e0c0b64a4b
2 changed files with 31 additions and 22 deletions
|
@ -417,8 +417,13 @@ FAST_IRQ_HANDLER static void spiIrqHandler(const extDevice_t *dev)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BUS_ABORT:
|
case BUS_ABORT:
|
||||||
bus->curSegment = (busSegment_t *)BUS_SPI_FREE;
|
// Skip to the end of the segment list
|
||||||
return;
|
nextSegment = (busSegment_t *)bus->curSegment + 1;
|
||||||
|
while (nextSegment->len != 0) {
|
||||||
|
bus->curSegment = nextSegment;
|
||||||
|
nextSegment = (busSegment_t *)bus->curSegment + 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case BUS_READY:
|
case BUS_READY:
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -353,7 +353,10 @@ bool w25n01g_identify(flashDevice_t *fdevice, uint32_t jedecID)
|
||||||
fdevice->couldBeBusy = true; // Just for luck we'll assume the chip could be busy even though it isn't specced to be
|
fdevice->couldBeBusy = true; // Just for luck we'll assume the chip could be busy even though it isn't specced to be
|
||||||
fdevice->vTable = &w25n01g_vTable;
|
fdevice->vTable = &w25n01g_vTable;
|
||||||
|
|
||||||
|
#ifndef USE_QUADSPI
|
||||||
|
// Need to set clock speed for 8kHz logging support with SPI
|
||||||
spiSetClkDivisor(fdevice->io.handle.dev, spiCalculateDivider(100000000));
|
spiSetClkDivisor(fdevice->io.handle.dev, spiCalculateDivider(100000000));
|
||||||
|
#endif // USE_QUADSPI
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -663,18 +666,10 @@ uint32_t w25n01g_pageProgramContinue(flashDevice_t *fdevice, uint8_t const **buf
|
||||||
STATIC_DMA_DATA_AUTO uint8_t progExecDataLoad[] = { W25N01G_INSTRUCTION_PROGRAM_DATA_LOAD, 0, 0};
|
STATIC_DMA_DATA_AUTO uint8_t progExecDataLoad[] = { W25N01G_INSTRUCTION_PROGRAM_DATA_LOAD, 0, 0};
|
||||||
STATIC_DMA_DATA_AUTO uint8_t progRandomProgDataLoad[] = { W25N01G_INSTRUCTION_RANDOM_PROGRAM_DATA_LOAD, 0, 0};
|
STATIC_DMA_DATA_AUTO uint8_t progRandomProgDataLoad[] = { W25N01G_INSTRUCTION_RANDOM_PROGRAM_DATA_LOAD, 0, 0};
|
||||||
|
|
||||||
static busSegment_t segmentsFlash[] = {
|
|
||||||
{.u.buffers = {readStatus, readyStatus}, sizeof(readStatus), true, w25n01g_callbackReady},
|
|
||||||
{.u.buffers = {writeEnable, NULL}, sizeof(writeEnable), true, w25n01g_callbackWriteEnable},
|
|
||||||
{.u.buffers = {progExecCmd, NULL}, sizeof(progExecCmd), true, w25n01g_callbackWriteComplete},
|
|
||||||
{.u.link = {NULL, NULL}, 0, true, NULL},
|
|
||||||
};
|
|
||||||
|
|
||||||
static busSegment_t segmentsDataLoad[] = {
|
static busSegment_t segmentsDataLoad[] = {
|
||||||
{.u.buffers = {readStatus, readyStatus}, sizeof(readStatus), true, w25n01g_callbackReady},
|
{.u.buffers = {readStatus, readyStatus}, sizeof(readStatus), true, w25n01g_callbackReady},
|
||||||
{.u.buffers = {writeEnable, NULL}, sizeof(writeEnable), true, w25n01g_callbackWriteEnable},
|
{.u.buffers = {writeEnable, NULL}, sizeof(writeEnable), true, w25n01g_callbackWriteEnable},
|
||||||
{.u.buffers = {progExecDataLoad, NULL}, sizeof(progExecDataLoad), false, NULL},
|
{.u.buffers = {progExecDataLoad, NULL}, sizeof(progExecDataLoad), false, NULL},
|
||||||
{.u.buffers = {NULL, NULL}, 0, true, NULL}, // Patch in pointer to data buffer here
|
|
||||||
{.u.link = {NULL, NULL}, 0, true, NULL},
|
{.u.link = {NULL, NULL}, 0, true, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -682,7 +677,18 @@ uint32_t w25n01g_pageProgramContinue(flashDevice_t *fdevice, uint8_t const **buf
|
||||||
{.u.buffers = {readStatus, readyStatus}, sizeof(readStatus), true, w25n01g_callbackReady},
|
{.u.buffers = {readStatus, readyStatus}, sizeof(readStatus), true, w25n01g_callbackReady},
|
||||||
{.u.buffers = {writeEnable, NULL}, sizeof(writeEnable), true, w25n01g_callbackWriteEnable},
|
{.u.buffers = {writeEnable, NULL}, sizeof(writeEnable), true, w25n01g_callbackWriteEnable},
|
||||||
{.u.buffers = {progRandomProgDataLoad, NULL}, sizeof(progRandomProgDataLoad), false, NULL},
|
{.u.buffers = {progRandomProgDataLoad, NULL}, sizeof(progRandomProgDataLoad), false, NULL},
|
||||||
{.u.buffers = {NULL, NULL}, 0, true, NULL}, // Patch in pointer to data buffer here
|
{.u.link = {NULL, NULL}, 0, true, NULL},
|
||||||
|
};
|
||||||
|
|
||||||
|
static busSegment_t segmentsBuffer[] = {
|
||||||
|
{.u.buffers = {NULL, NULL}, 0, true, NULL},
|
||||||
|
{.u.link = {NULL, NULL}, 0, true, NULL},
|
||||||
|
};
|
||||||
|
|
||||||
|
static busSegment_t segmentsFlash[] = {
|
||||||
|
{.u.buffers = {readStatus, readyStatus}, sizeof(readStatus), true, w25n01g_callbackReady},
|
||||||
|
{.u.buffers = {writeEnable, NULL}, sizeof(writeEnable), true, w25n01g_callbackWriteEnable},
|
||||||
|
{.u.buffers = {progExecCmd, NULL}, sizeof(progExecCmd), true, w25n01g_callbackWriteComplete},
|
||||||
{.u.link = {NULL, NULL}, 0, true, NULL},
|
{.u.link = {NULL, NULL}, 0, true, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -698,9 +704,6 @@ uint32_t w25n01g_pageProgramContinue(flashDevice_t *fdevice, uint8_t const **buf
|
||||||
// Set the address and buffer details for the random data load
|
// Set the address and buffer details for the random data load
|
||||||
progRandomProgDataLoad[1] = (columnAddress >> 8) & 0xff;
|
progRandomProgDataLoad[1] = (columnAddress >> 8) & 0xff;
|
||||||
progRandomProgDataLoad[2] = columnAddress & 0xff;
|
progRandomProgDataLoad[2] = columnAddress & 0xff;
|
||||||
segmentsRandomDataLoad[3].u.buffers.txData = (uint8_t *)buffers[0];
|
|
||||||
segmentsRandomDataLoad[3].len = bufferSizes[0];
|
|
||||||
|
|
||||||
programSegment = segmentsRandomDataLoad;
|
programSegment = segmentsRandomDataLoad;
|
||||||
} else {
|
} else {
|
||||||
programStartAddress = programLoadAddress = fdevice->currentWriteAddress;
|
programStartAddress = programLoadAddress = fdevice->currentWriteAddress;
|
||||||
|
@ -708,12 +711,16 @@ uint32_t w25n01g_pageProgramContinue(flashDevice_t *fdevice, uint8_t const **buf
|
||||||
// Set the address and buffer details for the data load
|
// Set the address and buffer details for the data load
|
||||||
progExecDataLoad[1] = (columnAddress >> 8) & 0xff;
|
progExecDataLoad[1] = (columnAddress >> 8) & 0xff;
|
||||||
progExecDataLoad[2] = columnAddress & 0xff;
|
progExecDataLoad[2] = columnAddress & 0xff;
|
||||||
segmentsDataLoad[3].u.buffers.txData = (uint8_t *)buffers[0];
|
|
||||||
segmentsDataLoad[3].len = bufferSizes[0];
|
|
||||||
|
|
||||||
programSegment = segmentsDataLoad;
|
programSegment = segmentsDataLoad;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the data buffer
|
||||||
|
segmentsBuffer[0].u.buffers.txData = (uint8_t *)buffers[0];
|
||||||
|
segmentsBuffer[0].len = bufferSizes[0];
|
||||||
|
segmentsBuffer[0].callback = NULL;
|
||||||
|
|
||||||
|
spiLinkSegments(fdevice->io.handle.dev, programSegment, segmentsBuffer);
|
||||||
|
|
||||||
bufferDirty = true;
|
bufferDirty = true;
|
||||||
programLoadAddress += bufferSizes[0];
|
programLoadAddress += bufferSizes[0];
|
||||||
|
|
||||||
|
@ -724,17 +731,14 @@ uint32_t w25n01g_pageProgramContinue(flashDevice_t *fdevice, uint8_t const **buf
|
||||||
progExecCmd[2] = (currentPage >> 8) & 0xff;
|
progExecCmd[2] = (currentPage >> 8) & 0xff;
|
||||||
progExecCmd[3] = currentPage & 0xff;
|
progExecCmd[3] = currentPage & 0xff;
|
||||||
|
|
||||||
// Don't callback on completion of data load but rather after flashing
|
spiLinkSegments(fdevice->io.handle.dev, segmentsBuffer, segmentsFlash);
|
||||||
programSegment[3].callback = NULL;
|
|
||||||
|
|
||||||
spiLinkSegments(fdevice->io.handle.dev, programSegment, segmentsFlash);
|
|
||||||
|
|
||||||
bufferDirty = false;
|
bufferDirty = false;
|
||||||
|
|
||||||
programStartAddress = programLoadAddress;
|
programStartAddress = programLoadAddress;
|
||||||
} else {
|
} else {
|
||||||
// Callback on completion of data load
|
// Callback on completion of data load
|
||||||
programSegment[3].callback = w25n01g_callbackWriteComplete;
|
segmentsBuffer[0].callback = w25n01g_callbackWriteComplete;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fdevice->couldBeBusy) {
|
if (!fdevice->couldBeBusy) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue