From bb4728465f4545f755974f31b4d39023447d2e3f Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 4 Nov 2018 16:54:51 +0000 Subject: Fixed a race condition. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12408 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- .../serial_nor/devices/macronix_mx25/hal_flash_device.c | 14 +++++++++++--- .../serial_nor/devices/macronix_mx25/hal_flash_device.h | 11 +++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/os/hal/lib/complex/serial_nor/devices/macronix_mx25/hal_flash_device.c b/os/hal/lib/complex/serial_nor/devices/macronix_mx25/hal_flash_device.c index c587712c4..44b1018cb 100644 --- a/os/hal/lib/complex/serial_nor/devices/macronix_mx25/hal_flash_device.c +++ b/os/hal/lib/complex/serial_nor/devices/macronix_mx25/hal_flash_device.c @@ -381,9 +381,17 @@ void snor_device_init(SNORDriver *devp) { #else /* SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI */ - /* Attempting a reset of the device, it could be in an unexpected state - because a CPU reset does not reset the memory too.*/ - mx25_reset(devp); +#if MX25_RESET_ON_INIT == TRUE + { + /* Attempting a reset of the device, it could be in an unexpected state + because a CPU reset does not reset the memory too.*/ + mx25_reset(devp); + + /* The device requires at least 10uS to recover after a reset, it could + need up to 100mS in cause a reset occurred during a chip erase.*/ + osalThreadSleepMicroseconds(40); + } +#endif /* Reading device ID and unique ID.*/ wspiReceive(devp->config->busp, &mx25_cmd_read_id, 3U, devp->device_id); diff --git a/os/hal/lib/complex/serial_nor/devices/macronix_mx25/hal_flash_device.h b/os/hal/lib/complex/serial_nor/devices/macronix_mx25/hal_flash_device.h index f70f73985..f2a7ceb06 100644 --- a/os/hal/lib/complex/serial_nor/devices/macronix_mx25/hal_flash_device.h +++ b/os/hal/lib/complex/serial_nor/devices/macronix_mx25/hal_flash_device.h @@ -174,6 +174,17 @@ /* Driver pre-compile time settings. */ /*===========================================================================*/ +/** + * @brief SW reset on initialization. + * @details Enforces a reset on initialization, this could be required if + * the device is not reset in HW or during debugging. + * @note It is only effective if the WSPI driver is in use, it does + * nothing when SPI driver is used. + */ +#if !defined(MX25_RESET_ON_INIT) || defined(__DOXYGEN__) +#define MX25_RESET_ON_INIT TRUE +#endif + /** * @brief Switch WSPI bus width on initialization. * @details A bus width initialization is performed by writing the -- cgit v1.2.3