From bb6fa13db65a972949f54c078033518cc4e1aa2e Mon Sep 17 00:00:00 2001 From: Jerzy Kasenberg Date: Thu, 5 Dec 2024 14:38:14 +0100 Subject: [PATCH] spiflash: Make STM32 spiflash code common for all BSP Code and settings for making SPI flash as hal_flash were put in several BSP (not all had SPI flash on board). Now code is move to common folder so any stm32 base BSP can simply enable SPI flash. Signed-off-by: Jerzy Kasenberg --- hw/bsp/black_vet6/src/hal_bsp.c | 12 -------- hw/bsp/nucleo-g0b1re/src/hal_bsp.c | 18 ------------ hw/bsp/nucleo-g0b1re/syscfg.yml | 8 ------ hw/bsp/nucleo-g491re/src/hal_bsp.c | 18 ------------ hw/bsp/nucleo-g491re/syscfg.yml | 8 ------ hw/bsp/nucleo-h723zg/src/hal_bsp.c | 18 ------------ hw/bsp/nucleo-h723zg/syscfg.yml | 8 ------ hw/bsp/nucleo-u575zi-q/src/hal_bsp.c | 18 ------------ hw/bsp/nucleo-u575zi-q/syscfg.yml | 8 ------ hw/bsp/weact_g431cb/syscfg.yml | 8 ------ hw/mcu/stm/stm32_common/src/stm32_periph.c | 33 ++++++++++++++++++++++ hw/mcu/stm/stm32_common/syscfg.yml | 8 ++++++ 12 files changed, 41 insertions(+), 124 deletions(-) diff --git a/hw/bsp/black_vet6/src/hal_bsp.c b/hw/bsp/black_vet6/src/hal_bsp.c index c63c10a722..4ae74eb30a 100644 --- a/hw/bsp/black_vet6/src/hal_bsp.c +++ b/hw/bsp/black_vet6/src/hal_bsp.c @@ -286,18 +286,6 @@ static const struct hal_bsp_mem_dump dump_cfg[] = { extern const struct hal_flash stm32_flash_dev; -#if MYNEWT_VAL(SPIFLASH) -#if MYNEWT_VAL(BUS_DRIVER_PRESENT) -struct bus_spi_node_cfg flash_spi_cfg = { - .node_cfg.bus_name = MYNEWT_VAL(BSP_FLASH_SPI_BUS), - .pin_cs = MYNEWT_VAL(SPIFLASH_SPI_CS_PIN), - .mode = MYNEWT_VAL(SPIFLASH_SPI_MODE), - .data_order = HAL_SPI_MSB_FIRST, - .freq = MYNEWT_VAL(SPIFLASH_BAUDRATE), -}; -#endif -#endif - static const struct hal_flash *flash_devs[] = { [0] = &stm32_flash_dev, #if MYNEWT_VAL(SPIFLASH) diff --git a/hw/bsp/nucleo-g0b1re/src/hal_bsp.c b/hw/bsp/nucleo-g0b1re/src/hal_bsp.c index c87ddb9a0b..3b6017cb4e 100644 --- a/hw/bsp/nucleo-g0b1re/src/hal_bsp.c +++ b/hw/bsp/nucleo-g0b1re/src/hal_bsp.c @@ -198,18 +198,6 @@ static const struct hal_bsp_mem_dump dump_cfg[] = { extern const struct hal_flash stm32_flash_dev; -#if MYNEWT_VAL(SPIFLASH) -#if MYNEWT_VAL(BUS_DRIVER_PRESENT) -struct bus_spi_node_cfg flash_spi_cfg = { - .node_cfg.bus_name = MYNEWT_VAL(BSP_FLASH_SPI_BUS), - .pin_cs = MYNEWT_VAL(SPIFLASH_SPI_CS_PIN), - .mode = MYNEWT_VAL(SPIFLASH_SPI_MODE), - .data_order = HAL_SPI_MSB_FIRST, - .freq = MYNEWT_VAL(SPIFLASH_BAUDRATE), -}; -#endif -#endif - static const struct hal_flash *flash_devs[] = { [0] = &stm32_flash_dev, #if MYNEWT_VAL(SPIFLASH) @@ -244,12 +232,6 @@ hal_bsp_init(void) (void)rc; stm32_periph_create(); - -#if MYNEWT_VAL(SPIFLASH) && MYNEWT_VAL(BUS_DRIVER_PRESENT) - rc = spiflash_create_spi_dev(&spiflash_dev.dev, - MYNEWT_VAL(BSP_FLASH_SPI_NAME), &flash_spi_cfg); - assert(rc == 0); -#endif } void diff --git a/hw/bsp/nucleo-g0b1re/syscfg.yml b/hw/bsp/nucleo-g0b1re/syscfg.yml index ce74dbdf6b..d31c4667d6 100644 --- a/hw/bsp/nucleo-g0b1re/syscfg.yml +++ b/hw/bsp/nucleo-g0b1re/syscfg.yml @@ -22,14 +22,6 @@ syscfg.defs: description: 'Total flash size in KB.' value: 512 - BSP_FLASH_SPI_BUS: - description: 'bus name SPIFLASH is connected to' - value: '"spi0"' - - BSP_FLASH_SPI_NAME: - description: 'SPIFLASH device name' - value: '"spiflash0"' - syscfg.vals: REBOOT_LOG_FLASH_AREA: FLASH_AREA_REBOOT_LOG CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS diff --git a/hw/bsp/nucleo-g491re/src/hal_bsp.c b/hw/bsp/nucleo-g491re/src/hal_bsp.c index 53fe12429b..96434bf918 100644 --- a/hw/bsp/nucleo-g491re/src/hal_bsp.c +++ b/hw/bsp/nucleo-g491re/src/hal_bsp.c @@ -155,18 +155,6 @@ static const struct hal_bsp_mem_dump dump_cfg[] = { extern const struct hal_flash stm32_flash_dev; -#if MYNEWT_VAL(SPIFLASH) -#if MYNEWT_VAL(BUS_DRIVER_PRESENT) -struct bus_spi_node_cfg flash_spi_cfg = { - .node_cfg.bus_name = MYNEWT_VAL(BSP_FLASH_SPI_BUS), - .pin_cs = MYNEWT_VAL(SPIFLASH_SPI_CS_PIN), - .mode = MYNEWT_VAL(SPIFLASH_SPI_MODE), - .data_order = HAL_SPI_MSB_FIRST, - .freq = MYNEWT_VAL(SPIFLASH_BAUDRATE), -}; -#endif -#endif - static const struct hal_flash *flash_devs[] = { [0] = &stm32_flash_dev, #if MYNEWT_VAL(SPIFLASH) @@ -201,12 +189,6 @@ hal_bsp_init(void) (void)rc; stm32_periph_create(); - -#if MYNEWT_VAL(SPIFLASH) && MYNEWT_VAL(BUS_DRIVER_PRESENT) - rc = spiflash_create_spi_dev(&spiflash_dev.dev, - MYNEWT_VAL(BSP_FLASH_SPI_NAME), &flash_spi_cfg); - assert(rc == 0); -#endif } void diff --git a/hw/bsp/nucleo-g491re/syscfg.yml b/hw/bsp/nucleo-g491re/syscfg.yml index 400897ef64..bad64c1d9f 100644 --- a/hw/bsp/nucleo-g491re/syscfg.yml +++ b/hw/bsp/nucleo-g491re/syscfg.yml @@ -22,14 +22,6 @@ syscfg.defs: description: 'Total flash size in KB.' value: 512 - BSP_FLASH_SPI_BUS: - description: 'bus name SPIFLASH is connected to' - value: '"spi0"' - - BSP_FLASH_SPI_NAME: - description: 'SPIFLASH device name' - value: '"spiflash0"' - syscfg.vals: REBOOT_LOG_FLASH_AREA: FLASH_AREA_REBOOT_LOG CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS diff --git a/hw/bsp/nucleo-h723zg/src/hal_bsp.c b/hw/bsp/nucleo-h723zg/src/hal_bsp.c index 5c1073f0be..ef26636131 100644 --- a/hw/bsp/nucleo-h723zg/src/hal_bsp.c +++ b/hw/bsp/nucleo-h723zg/src/hal_bsp.c @@ -184,18 +184,6 @@ static const struct hal_bsp_mem_dump dump_cfg[] = { extern const struct hal_flash stm32_flash_dev; -#if MYNEWT_VAL(SPIFLASH) -#if MYNEWT_VAL(BUS_DRIVER_PRESENT) -struct bus_spi_node_cfg flash_spi_cfg = { - .node_cfg.bus_name = MYNEWT_VAL(BSP_FLASH_SPI_BUS), - .pin_cs = MYNEWT_VAL(SPIFLASH_SPI_CS_PIN), - .mode = MYNEWT_VAL(SPIFLASH_SPI_MODE), - .data_order = HAL_SPI_MSB_FIRST, - .freq = MYNEWT_VAL(SPIFLASH_BAUDRATE), -}; -#endif -#endif - static const struct hal_flash *flash_devs[] = { [0] = &stm32_flash_dev, #if MYNEWT_VAL(SPIFLASH) @@ -227,12 +215,6 @@ hal_bsp_init(void) (void)rc; stm32_periph_create(); - -#if MYNEWT_VAL(SPIFLASH) && MYNEWT_VAL(BUS_DRIVER_PRESENT) - rc = spiflash_create_spi_dev(&spiflash_dev.dev, - MYNEWT_VAL(BSP_FLASH_SPI_NAME), &flash_spi_cfg); - assert(rc == 0); -#endif } void diff --git a/hw/bsp/nucleo-h723zg/syscfg.yml b/hw/bsp/nucleo-h723zg/syscfg.yml index 8146b91177..39f6cf7670 100644 --- a/hw/bsp/nucleo-h723zg/syscfg.yml +++ b/hw/bsp/nucleo-h723zg/syscfg.yml @@ -26,14 +26,6 @@ syscfg.defs: description: 'Number of flash sectors for a non-linear STM32 MCU.' value: 8 - BSP_FLASH_SPI_BUS: - description: 'bus name SPIFLASH is connected to' - value: '"spi0"' - - BSP_FLASH_SPI_NAME: - description: 'SPIFLASH device name' - value: '"spiflash0"' - syscfg.vals: REBOOT_LOG_FLASH_AREA: FLASH_AREA_REBOOT_LOG CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS diff --git a/hw/bsp/nucleo-u575zi-q/src/hal_bsp.c b/hw/bsp/nucleo-u575zi-q/src/hal_bsp.c index 0de8f1c9c9..3e93b909b9 100644 --- a/hw/bsp/nucleo-u575zi-q/src/hal_bsp.c +++ b/hw/bsp/nucleo-u575zi-q/src/hal_bsp.c @@ -150,18 +150,6 @@ static const struct hal_bsp_mem_dump dump_cfg[] = { extern const struct hal_flash stm32_flash_dev; -#if MYNEWT_VAL(SPIFLASH) -#if MYNEWT_VAL(BUS_DRIVER_PRESENT) -struct bus_spi_node_cfg flash_spi_cfg = { - .node_cfg.bus_name = MYNEWT_VAL(BSP_FLASH_SPI_BUS), - .pin_cs = MYNEWT_VAL(SPIFLASH_SPI_CS_PIN), - .mode = MYNEWT_VAL(SPIFLASH_SPI_MODE), - .data_order = HAL_SPI_MSB_FIRST, - .freq = MYNEWT_VAL(SPIFLASH_BAUDRATE), -}; -#endif -#endif - static const struct hal_flash *flash_devs[] = { [0] = &stm32_flash_dev, #if MYNEWT_VAL(SPIFLASH) @@ -193,12 +181,6 @@ hal_bsp_init(void) (void)rc; stm32_periph_create(); - -#if MYNEWT_VAL(SPIFLASH) && MYNEWT_VAL(BUS_DRIVER_PRESENT) - rc = spiflash_create_spi_dev(&spiflash_dev.dev, - MYNEWT_VAL(BSP_FLASH_SPI_NAME), &flash_spi_cfg); - assert(rc == 0); -#endif } void diff --git a/hw/bsp/nucleo-u575zi-q/syscfg.yml b/hw/bsp/nucleo-u575zi-q/syscfg.yml index 9098a1db6e..1b3ecead98 100644 --- a/hw/bsp/nucleo-u575zi-q/syscfg.yml +++ b/hw/bsp/nucleo-u575zi-q/syscfg.yml @@ -22,14 +22,6 @@ syscfg.defs: description: 'Total flash size in KB.' value: 2048 - BSP_FLASH_SPI_BUS: - description: 'bus name SPIFLASH is connected to' - value: '"spi0"' - - BSP_FLASH_SPI_NAME: - description: 'SPIFLASH device name' - value: '"spiflash0"' - syscfg.vals: REBOOT_LOG_FLASH_AREA: FLASH_AREA_REBOOT_LOG CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS diff --git a/hw/bsp/weact_g431cb/syscfg.yml b/hw/bsp/weact_g431cb/syscfg.yml index 2a2bd293c2..fc55935609 100644 --- a/hw/bsp/weact_g431cb/syscfg.yml +++ b/hw/bsp/weact_g431cb/syscfg.yml @@ -22,14 +22,6 @@ syscfg.defs: description: 'Total flash size in KB.' value: 128 - BSP_FLASH_SPI_BUS: - description: 'bus name SPIFLASH is connected to' - value: '"spi0"' - - BSP_FLASH_SPI_NAME: - description: 'SPIFLASH device name' - value: '"spiflash0"' - BOOT_LOADER: description: 'Build everything as bootloader' value: 1 diff --git a/hw/mcu/stm/stm32_common/src/stm32_periph.c b/hw/mcu/stm/stm32_common/src/stm32_periph.c index 2ed29cd222..f6caf0a494 100644 --- a/hw/mcu/stm/stm32_common/src/stm32_periph.c +++ b/hw/mcu/stm/stm32_common/src/stm32_periph.c @@ -64,6 +64,10 @@ #include "os/os_cputime.h" #endif +#if MYNEWT_VAL(SPIFLASH) +#include +#endif + #include "mcu/stm32_hal.h" #if MYNEWT_VAL(PWM_0) @@ -646,6 +650,34 @@ stm32_periph_create_eth(void) #endif } +#if MYNEWT_VAL(SPIFLASH) + +#if MYNEWT_VAL(BUS_DRIVER_PRESENT) +struct bus_spi_node_cfg flash_spi_cfg = { + .node_cfg.bus_name = MYNEWT_VAL(BSP_FLASH_SPI_BUS), + .pin_cs = MYNEWT_VAL(SPIFLASH_SPI_CS_PIN), + .mode = MYNEWT_VAL(SPIFLASH_SPI_MODE), + .data_order = HAL_SPI_MSB_FIRST, + .freq = MYNEWT_VAL(SPIFLASH_BAUDRATE), +}; +#endif + +static void +create_spi_flash_device(void) +{ + int rc; + + rc = spiflash_create_spi_dev(&spiflash_dev.dev, + MYNEWT_VAL(BSP_FLASH_SPI_NAME), &flash_spi_cfg); + assert(rc == 0); +} +#else +static inline void +create_spi_flash_device(void) +{ +} +#endif + void stm32_periph_create(void) { @@ -659,4 +691,5 @@ stm32_periph_create(void) stm32_periph_create_spi(); stm32_periph_create_adc(); stm32_periph_create_eth(); + create_spi_flash_device(); } diff --git a/hw/mcu/stm/stm32_common/syscfg.yml b/hw/mcu/stm/stm32_common/syscfg.yml index a6bdc785e4..475ff0d22c 100644 --- a/hw/mcu/stm/stm32_common/syscfg.yml +++ b/hw/mcu/stm/stm32_common/syscfg.yml @@ -460,6 +460,14 @@ syscfg.defs: description: "ADC_2" value: 0 + BSP_FLASH_SPI_BUS: + description: 'bus name SPIFLASH is connected to' + value: '"spi0"' + + BSP_FLASH_SPI_NAME: + description: 'SPIFLASH device name' + value: '"spiflash0"' + OS_TICKS_USE_RTC: description: > Use RTC as source of system ticks.