This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new fc8e949fd spiflash: Make STM32 spiflash code common for all BSP
fc8e949fd is described below
commit fc8e949fd31e44f60a23fe336ce24d075a07ddb6
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Thu Dec 5 14:38:14 2024 +0100
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 <[email protected]>
---
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 c63c10a72..4ae74eb30 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 c87ddb9a0..3b6017cb4 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 ce74dbdf6..d31c4667d 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 53fe12429..96434bf91 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 400897ef6..bad64c1d9 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 5c1073f0b..ef2663613 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 8146b9117..39f6cf767 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 0de8f1c9c..3e93b909b 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 9098a1db6..1b3ecead9 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 2a2bd293c..fc5593560 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 2ed29cd22..ccfba5aa8 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 <spiflash/spiflash.h>
+#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) && 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),
+};
+
+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 a6bdc785e..475ff0d22 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.