Skip to content

Commit 25d4f1e

Browse files
committed
add wait busy before flash commands
this should make coexistence with the adc work correctly
1 parent 32b18f5 commit 25d4f1e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/pbio/drv/block_device/block_device_ev3.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ pbio_error_t pbdrv_block_device_read(pbio_os_state_t *state, uint32_t offset, ui
536536

537537
// Set address for this read request and send it.
538538
set_address_be(&read_address[1], PBDRV_CONFIG_BLOCK_DEVICE_EV3_START_ADDRESS + offset + size_done);
539+
PBIO_OS_AWAIT_WHILE(state, bdev.spi_status & SPI_STATUS_WAIT_ANY);
539540
err = spi_begin_for_flash(read_address, sizeof(read_address), 0, buffer + size_done, size_now);
540541
if (err != PBIO_SUCCESS) {
541542
return err;
@@ -556,6 +557,7 @@ static pbio_error_t flash_wait_write(pbio_os_state_t *state) {
556557
PBIO_OS_ASYNC_BEGIN(state);
557558

558559
do {
560+
PBIO_OS_AWAIT_WHILE(state, bdev.spi_status & SPI_STATUS_WAIT_ANY);
559561
err = spi_begin_for_flash(cmd_status, sizeof(cmd_status), 0, 0, 0);
560562
if (err != PBIO_SUCCESS) {
561563
return err;
@@ -586,6 +588,7 @@ pbio_error_t pbdrv_block_device_store(pbio_os_state_t *state, uint8_t *buffer, u
586588
// Erase sector by sector.
587589
for (offset = 0; offset < size; offset += FLASH_SIZE_ERASE) {
588590
// Enable writing
591+
PBIO_OS_AWAIT_WHILE(state, bdev.spi_status & SPI_STATUS_WAIT_ANY);
589592
err = spi_begin_for_flash(cmd_write_enable, sizeof(cmd_write_enable), 0, 0, 0);
590593
if (err != PBIO_SUCCESS) {
591594
return err;
@@ -594,6 +597,7 @@ pbio_error_t pbdrv_block_device_store(pbio_os_state_t *state, uint8_t *buffer, u
594597

595598
// Erase this block
596599
set_address_be(&erase_address[1], PBDRV_CONFIG_BLOCK_DEVICE_EV3_START_ADDRESS + offset);
600+
PBIO_OS_AWAIT_WHILE(state, bdev.spi_status & SPI_STATUS_WAIT_ANY);
597601
err = spi_begin_for_flash(erase_address, sizeof(erase_address), 0, 0, 0);
598602
if (err != PBIO_SUCCESS) {
599603
return err;
@@ -612,6 +616,7 @@ pbio_error_t pbdrv_block_device_store(pbio_os_state_t *state, uint8_t *buffer, u
612616
size_now = pbio_int_math_min(size - size_done, FLASH_SIZE_WRITE);
613617

614618
// Enable writing
619+
PBIO_OS_AWAIT_WHILE(state, bdev.spi_status & SPI_STATUS_WAIT_ANY);
615620
err = spi_begin_for_flash(cmd_write_enable, sizeof(cmd_write_enable), 0, 0, 0);
616621
if (err != PBIO_SUCCESS) {
617622
return err;
@@ -620,6 +625,7 @@ pbio_error_t pbdrv_block_device_store(pbio_os_state_t *state, uint8_t *buffer, u
620625

621626
// Write this block
622627
set_address_be(&write_address[1], PBDRV_CONFIG_BLOCK_DEVICE_EV3_START_ADDRESS + size_done);
628+
PBIO_OS_AWAIT_WHILE(state, bdev.spi_status & SPI_STATUS_WAIT_ANY);
623629
err = spi_begin_for_flash(write_address, sizeof(write_address), buffer + size_done, 0, size_now);
624630
if (err != PBIO_SUCCESS) {
625631
return err;

0 commit comments

Comments
 (0)