diff --git a/src/shared/drivers/qspi-flash/qspi-flash.cpp b/src/shared/drivers/qspi-flash/qspi-flash.cpp index 3f9fe9701be841e65513370ef00412462250994a..1b23868e8721d4103f6f02a92937b003f096e93d 100644 --- a/src/shared/drivers/qspi-flash/qspi-flash.cpp +++ b/src/shared/drivers/qspi-flash/qspi-flash.cpp @@ -459,6 +459,10 @@ bool qspi_flash::chip_erase() // 3 erase chip command // 4 wait till flash has completed the erase operation + // if chip_erase operation will not be completed properly resulting in a + // timeout event and a forced reset (after some seconds by the command), + // some post-operations may fail! + // check if memory has been initialised if (initialised == false) { @@ -492,8 +496,10 @@ bool qspi_flash::chip_erase() { Thread::sleep(1); dt = dt + 1; - if (dt >= 130000) // (2 min and 10sec) mac chip erase time = 2 min + if (dt >= 130000) // (2 min and 10sec) max chip erase time = 2 min { + software_reset(); // device forced reset to default status + Thread::sleep(20); // recovery time = 12 ms return false; } } @@ -557,6 +563,7 @@ bool qspi_flash::sector_erase(uint32_t address) dt = dt + 1; if (dt >= 260) // max sector erase cycle time = 240 ms { + software_reset(); // device forced reset to default status return false; } } @@ -621,6 +628,7 @@ bool qspi_flash::block32_erase(uint32_t address) dt = dt + 1; if (dt >= 3000) // block_32 erase cycle max time = 1.8s { + software_reset(); // device forced reset to default status return false; } } @@ -685,6 +693,7 @@ bool qspi_flash::block64_erase(uint32_t address) dt = dt + 1; if (dt >= 4500) // erase block_64K cycle max time = 3.5s { + software_reset(); // device forced reset to default status return false; } } @@ -753,6 +762,7 @@ bool qspi_flash::byte_program(uint8_t data, uint32_t address, bool verify) dt = dt + 1; if (dt >= 5000) // max program byte cycle time = 100us { + software_reset(); // device forced reset to default status return false; } } @@ -874,6 +884,7 @@ void qspi_flash::software_reset() QSPI::disable(); + // wait for flash to go back in power-on default status Thread::sleep(1); } @@ -1049,6 +1060,7 @@ bool qspi_flash::page_program(std::vector<uint8_t>& vector, dt = dt + 1; if (dt >= 20) // max page program cycle time = 10ms { + software_reset(); // device forced reset to default status return false; } } diff --git a/src/shared/drivers/qspi-flash/qspi-flash.h b/src/shared/drivers/qspi-flash/qspi-flash.h index 6c996b0dd1d3908c20bc88a12b009ca6b6f8f6d0..cc8afb94de21776d3a3a413029cd370679d1af0a 100644 --- a/src/shared/drivers/qspi-flash/qspi-flash.h +++ b/src/shared/drivers/qspi-flash/qspi-flash.h @@ -184,9 +184,11 @@ public: bool verify); /** - * @brief erase the entire memory chip + * @brief erase the entire memory chip. since this operation is not so + * reliable and it may take a lot of time, you should use block32_erase() + * and block64_erase() methods. * @return true/false - if the operation has been successful - * @warning THIS OPERATION WILL TAKE A WHILE !! (at least 30 sec) + * @warning THIS OPERATION WILL TAKE A WHILE !! (at least 1 min) */ bool chip_erase(); @@ -231,9 +233,9 @@ public: bool byte_program(uint8_t data, uint32_t address, bool verify); /** - * @brief make the flash go back to power-on default state. altough that's - * not a "must-do" operation, it may be used when you have done with the - * memory. + * @brief make the flash go back to power-on default state. if the device + * is performing any program/erase operation, that operation will be deleted + * and some data could be lost! * @warning THIS FUNCTION MAY TAKE A WHILE ! */ void software_reset(); diff --git a/src/tests/drivers/QuadSpi-Flash/test-Qflash.cpp b/src/tests/drivers/QuadSpi-Flash/test-Qflash.cpp index c92f7eae5d80825737906c79822ce115ee8d7584..3f60f1e674d567d822445bb67ff64a6ae9410e45 100644 --- a/src/tests/drivers/QuadSpi-Flash/test-Qflash.cpp +++ b/src/tests/drivers/QuadSpi-Flash/test-Qflash.cpp @@ -31,23 +31,11 @@ qspi_flash mymemory; int main() { - // solo testare i timeout - // finire di mettere timeout poi test e commit - // ATTENZIONE SUL TIMEOUT DELLA FUNZIONE WAITPROGRESS() e ritorno false - // sulle funzioni. - // testare funzioni senza utilizzo di waitPogress() e nuovi timeout, - // eliminare waitProgress() e while in page_program. controllare che non sia - // possibile chiamare funzioni con operazioni ancora in corso. - - /* - uint32_t t = 0; - while(1) { - t = t + 1; - printf("%u\n", t); - } - - return 0; - */ + // aggiunti software_reset con timeout: disaccoppiano le operazioni, anche + // senza delay - permettendo alle operazioni di erase che falliscono di non + // far fallire le altre operazioni successive. chip_erase se fallisce dopo + // circa 10 sec fa fallire alcune operazioni come write_vector() e + // page_program. // init qspi-flash communication mymemory.init();