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 39a7475ae..271c19946 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 @@ -135,7 +135,6 @@ static bool mx25_find_id(const uint8_t *set, size_t size, uint8_t element) { } static flash_error_t mx25_poll_status(SNORDriver *devp) { - uint8_t sts[2], sec[2]; do { #if MX25_NICE_WAITING == TRUE @@ -143,21 +142,24 @@ static flash_error_t mx25_poll_status(SNORDriver *devp) { #endif /* Read status command.*/ #if MX25_BUS_MODE == MX25_BUS_MODE_SPI - bus_cmd_receive(devp->config->busp, MX25_CMD_SPI_RDSR, 1U, sts); + bus_cmd_receive(devp->config->busp, MX25_CMD_SPI_RDSR, 1U, devp->nocache->buf1); #else bus_cmd_addr_dummy_receive(devp->config->busp, MX25_CMD_OPI_RDSR, - 0U, 4U, 2U, sts); /*Note: always 4 dummies.*/ + 0U, 4U, 2U, + devp->nocache->buf); /* Note: always 4 dummies.*/ #endif - } while ((sts[0] & 1U) != 0U); + } while ((devp->nocache->buf[0] & 1U) != 0U); /* Reading security register and checking for errors.*/ #if MX25_BUS_MODE == MX25_BUS_MODE_SPI - bus_cmd_receive(devp->config->busp, MX25_CMD_SPI_RDSCUR, 1U, sec); + bus_cmd_receive(devp->config->busp, MX25_CMD_SPI_RDSCUR, + 1U, devp->nocache->buf1); #else bus_cmd_addr_dummy_receive(devp->config->busp, MX25_CMD_OPI_RDSCUR, - 0U, 4U, 2U, sec); /*Note: always 4 dummies.*/ + 0U, 4U, 2U, + devp->nocache->buf); /* Note: always 4 dummies.*/ #endif - if ((sec[0] & MX25_FLAGS_ALL_ERRORS) != 0U) { + if ((devp->nocache->buf[0] & MX25_FLAGS_ALL_ERRORS) != 0U) { return FLASH_ERROR_PROGRAM; } @@ -338,17 +340,18 @@ void snor_device_init(SNORDriver *devp) { #endif /* Reading device ID and unique ID.*/ - wspiReceive(devp->config->busp, &mx25_cmd_read_id, 3U, devp->device_id); + wspiReceive(devp->config->busp, &mx25_cmd_read_id, 3U, + &devp->nocache->buf[0]); #endif /* SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI */ /* Checking if the device is white listed.*/ osalDbgAssert(mx25_find_id(mx25_manufacturer_ids, sizeof mx25_manufacturer_ids, - devp->device_id[0]), + devp->nocache->buf[0]), "invalid manufacturer id"); osalDbgAssert(mx25_find_id(mx25_memory_type_ids, sizeof mx25_memory_type_ids, - devp->device_id[1]), + devp->nocache->buf[1]), "invalid memory type id"); #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI @@ -361,7 +364,6 @@ void snor_device_init(SNORDriver *devp) { #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) && (MX25_SWITCH_WIDTH == TRUE) { - uint8_t id[8]; #if MX25_BUS_MODE == MX25_BUS_MODE_SPI static const uint8_t v[1] = {0x00}; #elif MX25_BUS_MODE == MX25_BUS_MODE_OPI_STR @@ -376,25 +378,29 @@ void snor_device_init(SNORDriver *devp) { /* Reading ID again for confirmation, in DTR mode bytes are read twice, it needs adjusting.*/ #if MX25_BUS_MODE == MX25_BUS_MODE_SPI - bus_cmd_receive(devp->config->busp, MX25_CMD_SPI_RDID, 3U, id); + bus_cmd_receive(devp->config->busp, MX25_CMD_SPI_RDID, 3U, + &devp->nocache->buf[16]); #elif MX25_BUS_MODE == MX25_BUS_MODE_OPI_STR bus_cmd_addr_dummy_receive(devp->config->busp, MX25_CMD_OPI_RDID, - 0U, 4U, 3U, id); /*Note: always 4 dummies. */ + 0U, 4U, 3U, + &devp->nocache->buf[16]); /*Note: always 4 dummies.*/ #elif MX25_BUS_MODE == MX25_BUS_MODE_OPI_DTR bus_cmd_addr_dummy_receive(devp->config->busp, MX25_CMD_OPI_RDID, - 0U, 4U, 6U, id); /*Note: always 4 dummies. */ - id[1] = id[2]; - id[2] = id[4]; + 0U, 4U, 6U, + &devp->nocache->buf[16]); /*Note: always 4 dummies.*/ + devp->nocache->buf[16 + 1] = devp->nocache->buf[16 + 2]; + devp->nocache->buf[16 + 2] = devp->nocache->buf[16 + 4]; #endif /* Checking if the device is white listed.*/ - osalDbgAssert(memcmp(id, devp->device_id, 3) == 0, + osalDbgAssert(memcmp(&devp->nocache->buf[0], + &devp->nocache->buf[16], 3) == 0, "id confirmation failed"); } #endif /* Setting up the device size.*/ - snor_descriptor.sectors_count = (1U << ((size_t)devp->device_id[2] & 0x1FU)) / + snor_descriptor.sectors_count = (1U << ((size_t)devp->nocache->buf[2] & 0x1FU)) / SECTOR_SIZE; snor_descriptor.size = (size_t)snor_descriptor.sectors_count * SECTOR_SIZE; } @@ -556,7 +562,6 @@ flash_error_t snor_device_start_erase_sector(SNORDriver *devp, */ flash_error_t snor_device_verify_erase(SNORDriver *devp, flash_sector_t sector) { - uint8_t cmpbuf[MX25_COMPARE_BUFFER_SIZE]; flash_offset_t offset; size_t n; @@ -569,16 +574,16 @@ flash_error_t snor_device_verify_erase(SNORDriver *devp, #if SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI #if MX25_BUS_MODE == MX25_BUS_MODE_SPI bus_cmd_addr_dummy_receive(devp->config->busp, MX25_CMD_SPI_FAST_READ4B, - offset, 8, /* Note, always 8 dummy cycles. */ - sizeof cmpbuf, cmpbuf); + offset, 8, /* Note, always 8 dummy cycles.*/ + SNOR_BUFFER_SIZE, devp->nocache->buf); #elif MX25_BUS_MODE == MX25_BUS_MODE_OPI_STR bus_cmd_addr_dummy_receive(devp->config->busp, MX25_CMD_OPI_8READ, offset, MX25_READ_DUMMY_CYCLES, - sizeof cmpbuf, cmpbuf); + SNOR_BUFFER_SIZE, devp->nocache->buf); #elif MX25_BUS_MODE == MX25_BUS_MODE_OPI_DTR bus_cmd_addr_dummy_receive(devp->config->busp, MX25_CMD_OPI_8DTRD, offset, MX25_READ_DUMMY_CYCLES, - sizeof cmpbuf, cmpbuf); + SNOR_BUFFER_SIZE, devp->nocache->buf); #endif #else /* Normal read command in SPI mode.*/ @@ -587,7 +592,7 @@ flash_error_t snor_device_verify_erase(SNORDriver *devp, #endif /* Checking for erased state of current buffer.*/ - for (p = cmpbuf; p < &cmpbuf[MX25_COMPARE_BUFFER_SIZE]; p++) { + for (p = devp->nocache->buf; p < &devp->nocache->buf[SNOR_BUFFER_SIZE]; p++) { if (*p != 0xFFU) { /* Ready state again.*/ devp->state = FLASH_READY; @@ -596,8 +601,8 @@ flash_error_t snor_device_verify_erase(SNORDriver *devp, } } - offset += sizeof cmpbuf; - n -= sizeof cmpbuf; + offset += SNOR_BUFFER_SIZE; + n -= SNOR_BUFFER_SIZE; } return FLASH_NO_ERROR; 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 45a8ef96a..0f47895d1 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 @@ -315,17 +315,6 @@ #define MX25_USE_SUB_SECTORS FALSE #endif -/** - * @brief Size of the compare buffer. - * @details This buffer is allocated in the stack frame of the function - * @p flashVerifyErase() and its size must be a power of two. - * Larger buffers lead to better verify performance but increase - * stack usage for that function. - */ -#if !defined(MX25_COMPARE_BUFFER_SIZE) || defined(__DOXYGEN__) -#define MX25_COMPARE_BUFFER_SIZE 32 -#endif - /** * @brief Number of dummy cycles for fast read (1..15). * @details This is the number of dummy cycles to be used for fast read @@ -339,10 +328,6 @@ /* Derived constants and error checks. */ /*===========================================================================*/ -#if (MX25_COMPARE_BUFFER_SIZE & (MX25_COMPARE_BUFFER_SIZE - 1)) != 0 -#error "invalid MX25_COMPARE_BUFFER_SIZE value" -#endif - #if (MX25_READ_DUMMY_CYCLES < 6) || (MX25_READ_DUMMY_CYCLES > 20) || \ ((MX25_READ_DUMMY_CYCLES & 1) != 0) #error "invalid MX25_READ_DUMMY_CYCLES value (6, 8, 10, 12, 14, 16, 18, 20)" diff --git a/os/hal/lib/complex/serial_nor/hal_serial_nor.c b/os/hal/lib/complex/serial_nor/hal_serial_nor.c index 6dda195b1..4b127bfbd 100644 --- a/os/hal/lib/complex/serial_nor/hal_serial_nor.c +++ b/os/hal/lib/complex/serial_nor/hal_serial_nor.c @@ -662,16 +662,18 @@ void bus_cmd_addr_dummy_receive(BUSDriver *busp, * @brief Initializes an instance. * * @param[out] devp pointer to the @p SNORDriver object + * @param[in] nocache pointer to the non-cacheable buffers * * @init */ -void snorObjectInit(SNORDriver *devp) { +void snorObjectInit(SNORDriver *devp, snor_nocache_buffer_t *nocache) { osalDbgCheck(devp != NULL); devp->vmt = &snor_vmt; devp->state = FLASH_STOP; devp->config = NULL; + devp->nocache = nocache; #if SNOR_USE_MUTUAL_EXCLUSION == TRUE osalMutexObjectInit(&devp->mutex); #endif diff --git a/os/hal/lib/complex/serial_nor/hal_serial_nor.h b/os/hal/lib/complex/serial_nor/hal_serial_nor.h index f8411b8ed..ae1ee457d 100644 --- a/os/hal/lib/complex/serial_nor/hal_serial_nor.h +++ b/os/hal/lib/complex/serial_nor/hal_serial_nor.h @@ -39,6 +39,11 @@ #define SNOR_BUS_DRIVER_WSPI 1U /** @} */ +/** + * @brief Size of the buffer for internal operations. + */ +#define SNOR_BUFFER_SIZE 32 + /*===========================================================================*/ /* Driver pre-compile time settings. */ /*===========================================================================*/ @@ -127,6 +132,13 @@ struct SNORDriverVMT { _snor_flash_methods }; +typedef struct snor_nocache_buffer { + /** + * @brief Temporary buffer. + */ + uint8_t buf[SNOR_BUFFER_SIZE]; +} snor_nocache_buffer_t; + /** * @extends BaseFlash * @@ -143,14 +155,14 @@ typedef struct { */ const SNORConfig *config; /** - * @brief Device ID and unique ID. + * @brief Non-cacheable buffer associated to this instance. */ - uint8_t device_id[20]; + snor_nocache_buffer_t *nocache; #if (SNOR_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__) /** * @brief Mutex protecting SNOR. */ - mutex_t mutex; + mutex_t mutex; #endif /* EFL_USE_MUTUAL_EXCLUSION == TRUE */ } SNORDriver; @@ -204,7 +216,7 @@ extern "C" { size_t n, uint8_t *p); #endif - void snorObjectInit(SNORDriver *devp); + void snorObjectInit(SNORDriver *devp, snor_nocache_buffer_t *nocache); void snorStart(SNORDriver *devp, const SNORConfig *config); void snorStop(SNORDriver *devp); #if (SNOR_BUS_DRIVER == SNOR_BUS_DRIVER_WSPI) || defined(__DOXYGEN__) diff --git a/os/hal/ports/STM32/LLD/OCTOSPIv2/hal_wspi_lld.c b/os/hal/ports/STM32/LLD/OCTOSPIv2/hal_wspi_lld.c index 281ed5481..bd4be92c5 100644 --- a/os/hal/ports/STM32/LLD/OCTOSPIv2/hal_wspi_lld.c +++ b/os/hal/ports/STM32/LLD/OCTOSPIv2/hal_wspi_lld.c @@ -419,6 +419,9 @@ void wspi_lld_unmap_flash(WSPIDriver *wspip) { */ void wspi_lld_serve_interrupt(WSPIDriver *wspip) { + wspip->ospi->FCR = OCTOSPI_FCR_CTEF | OCTOSPI_FCR_CTCF | + OCTOSPI_FCR_CSMF | OCTOSPI_FCR_CTOF; + /* Portable WSPI ISR code defined in the high level driver, note, it is a macro.*/ _wspi_isr_code(wspip); diff --git a/readme.txt b/readme.txt index 2cacce53a..330e9c03e 100644 --- a/readme.txt +++ b/readme.txt @@ -74,8 +74,9 @@ ***************************************************************************** *** Next *** +- NEW: FatFS now functional on STM32H7xx, added a target to the VFS demo. - NEW: Improved cache settings in STM32H7xx mcuconf.h. -- NEW: Modified SDMMCv2 to allow for uncached buffers. +- NEW: Modified SDMMCv2 to allow for uncached buffers, tested on STM32H7xx. - NEW: Added OCTOSPIv2 driver using MDMA for STM32H7xx. - NEW: Added demos for STM32H723ZG Nucleo144 and STM32H735ZI Discovery boards. - NEW: Added support for STM32H723/25/33/35. diff --git a/testhal/STM32/multi/WSPI-MFS/.cproject b/testhal/STM32/multi/WSPI-MFS/.cproject index 09f2531d6..293f302b9 100644 --- a/testhal/STM32/multi/WSPI-MFS/.cproject +++ b/testhal/STM32/multi/WSPI-MFS/.cproject @@ -103,6 +103,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -129,10 +163,10 @@ - + - + @@ -180,4 +214,4 @@ - + \ No newline at end of file diff --git a/testhal/STM32/multi/WSPI-MFS/Makefile b/testhal/STM32/multi/WSPI-MFS/Makefile index 44b42fe0a..98f9817e8 100644 --- a/testhal/STM32/multi/WSPI-MFS/Makefile +++ b/testhal/STM32/multi/WSPI-MFS/Makefile @@ -3,9 +3,14 @@ # all: + @echo + @echo === Building for STM32H735IG-Discovery ============================= + +@make --no-print-directory -f ./make/stm32h735ig_discovery.make all + @echo ==================================================================== @echo @echo === Building for STM32L4R9-Discovery =============================== +@make --no-print-directory -f ./make/stm32l4r9_discovery.make all + @echo ==================================================================== @echo @echo === Building for STM32L476-Discovery =============================== +@make --no-print-directory -f ./make/stm32l476_discovery.make all @@ -13,6 +18,8 @@ all: @echo clean: + @echo + +@make --no-print-directory -f ./make/stm32h735ig_discovery.make clean @echo +@make --no-print-directory -f ./make/stm32l4r9_discovery.make clean @echo diff --git a/testhal/STM32/multi/WSPI-MFS/main.c b/testhal/STM32/multi/WSPI-MFS/main.c index 73dcfb065..b38c00762 100644 --- a/testhal/STM32/multi/WSPI-MFS/main.c +++ b/testhal/STM32/multi/WSPI-MFS/main.c @@ -32,6 +32,7 @@ const SNORConfig snorcfg1 = { }; SNORDriver snor1; +snor_nocache_buffer_t __nocache_snor1buf; const MFSConfig mfscfg1 = { .flashp = (BaseFlash *)&snor1, @@ -54,8 +55,6 @@ static THD_FUNCTION(Thread1, arg) { while (true) { palToggleLine(PORTAB_LINE_LED1); chThdSleepMilliseconds(500); - palToggleLine(PORTAB_LINE_LED1); - chThdSleepMilliseconds(500); } } @@ -81,7 +80,7 @@ int main(void) { sdStart(&PORTAB_SD1, NULL); /* Initializing and starting snor1 driver.*/ - snorObjectInit(&snor1); + snorObjectInit(&snor1, &__nocache_snor1buf); snorStart(&snor1, &snorcfg1); #if 1 /* Testing memory mapped mode.*/