lancaster-university / codal-stm32

MIT License
1 stars 3 forks source link

SPI blocked when using StandardSPIFlash API #15

Open tsunyi opened 4 years ago

tsunyi commented 4 years ago
(gdb) backtrace
#0 codal::ZSPI::startTransfer (this=0x2000050c <xn+692>, txBuffer=0x0, txSize=0, rxBuffer=0x0, rxSize=0,
doneHandler=0x0, arg=0x0)
at /mnt/c/Users/dare-/Documents/Workspace/xtron/codal/libraries/codal-stm32/src/ZSPI.cpp:357
#1 0x0801842a in codal::ZSPI::transfer (this=<optimized out>, txBuffer=0x0, txSize=0, rxBuffer=0x0, rxSize=0)
at /mnt/c/Users/dare-/Documents/Workspace/xtron/codal/libraries/codal-stm32/src/ZSPI.cpp:313
#2 0x08016380 in codal::StandardSPIFlash::sendCommand (this=this@entry=0x200008ec <storage>,
command=command@entry=6 '\006', addr=addr@entry=-1, resp=resp@entry=0x0, respSize=respSize@entry=0)
at /mnt/c/Users/dare-/Documents/Workspace/xtron/codal/libraries/codal-core/source/drivers/StandardSPIFlash.cpp:55 
#3 0x0801647e in codal::StandardSPIFlash::writeEnable (this=0x200008ec <storage>)
at /mnt/c/Users/dare-/Documents/Workspace/xtron/codal/libraries/codal-core/source/drivers/StandardSPIFlash.cpp:63 
#4 codal::StandardSPIFlash::writeBytes (this=0x200008ec <storage>, addr=1703948, buffer=0x20017f4c, len=4)
at /mnt/c/Users/dare-/Documents/Workspace/xtron/codal/libraries/codal-core/source/drivers/StandardSPIFlash.cpp:98 
#5 0x08010776 in codal::snorfs::FS::swapRow (this=this@entry=0x20000904 <storage+24>, row=28)
at /mnt/c/Users/dare-/Documents/Workspace/xtron/codal/source/SNORFS.cpp:295
#6 0x08010b42 in codal::snorfs::FS::gcCore (this=0x20000904 <storage+24>, force=<optimized out>,
isData=<optimized out>) at /mnt/c/Users/dare-/Documents/Workspace/xtron/codal/source/SNORFS.cpp:257
#7 0x08010e5e in codal::snorfs::FS::mount (this=0x20000904 <storage+24>)
at /mnt/c/Users/dare-/Documents/Workspace/xtron/codal/source/SNORFS.cpp:614
#8 codal::snorfs::FS::lock (this=this@entry=0x20000904 <storage+24>)
at /mnt/c/Users/dare-/Documents/Workspace/xtron/codal/source/SNORFS.cpp:613
#9 0x0801101e in codal::snorfs::FS::exists (this=this@entry=0x20000904 <storage+24>,
filename=filename@entry=0x801d86c "foobar")
at /mnt/c/Users/dare-/Documents/Workspace/xtron/codal/source/SNORFS.cpp:602
#10 0x08012bc4 in codal::WStorage::mountedStorage (this=this@entry=0x200008ec <storage>)
at /mnt/c/Users/dare-/Documents/Workspace/xtron/codal/source/storage.cpp:20
#11 0x0801286c in main () at /mnt/c/Users/dare-/Documents/Workspace/xtron/codal/source/main.cpp:74

When I try to mount storage, SPI was blocked because of invoke follow api with both txSize and rxSize equal to 0,so it can't receice transferCompleteEventCode event.

int ZSPI::startTransfer(const uint8_t *txBuffer, uint32_t txSize, uint8_t *rxBuffer,
                        uint32_t rxSize, PVoidCallback doneHandler, void *arg)
{
    int res;

    init_internal();

    LOG("SPI start %p/%d %p/%d D=%p", txBuffer, txSize, rxBuffer, rxSize, doneHandler);

    this->doneHandler = doneHandler;
    this->doneHandlerArg = arg;

    // disable IRQ or else risk a race in HAL, between starting DMA request
    // and getting the DMA-done IRQ
    if (doneHandler)
        target_disable_irq();

    if (txSize && rxSize)
    {
        CODAL_ASSERT(txSize == rxSize, DEVICE_SPI_ERROR); // we could support this if needed
        res = HAL_SPI_TransmitReceive_DMA(&spi, (uint8_t *)txBuffer, rxBuffer, txSize);
    }
    else if (txSize)
    {
        res = HAL_SPI_Transmit_DMA(&spi, (uint8_t *)txBuffer, txSize);
    }
    else if (rxSize)
    {
        res = HAL_SPI_Receive_DMA(&spi, rxBuffer, rxSize);
    }
    else
    {
        res = HAL_OK;
    }

    if (doneHandler)
        target_enable_irq();

    CODAL_ASSERT(res == HAL_OK, DEVICE_SPI_ERROR);
    return 0;
}