Skip to content

Commit

Permalink
spiflash: Make STM32 spiflash code common for all BSP
Browse files Browse the repository at this point in the history
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 <jerzy.kasenberg@codecoup.pl>
  • Loading branch information
kasjer committed Dec 5, 2024
1 parent 5f8038e commit bb6fa13
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 124 deletions.
12 changes: 0 additions & 12 deletions hw/bsp/black_vet6/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 0 additions & 18 deletions hw/bsp/nucleo-g0b1re/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions hw/bsp/nucleo-g0b1re/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions hw/bsp/nucleo-g491re/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions hw/bsp/nucleo-g491re/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions hw/bsp/nucleo-h723zg/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions hw/bsp/nucleo-h723zg/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions hw/bsp/nucleo-u575zi-q/src/hal_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions hw/bsp/nucleo-u575zi-q/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions hw/bsp/weact_g431cb/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions hw/mcu/stm/stm32_common/src/stm32_periph.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand All @@ -659,4 +691,5 @@ stm32_periph_create(void)
stm32_periph_create_spi();
stm32_periph_create_adc();
stm32_periph_create_eth();
create_spi_flash_device();
}
8 changes: 8 additions & 0 deletions hw/mcu/stm/stm32_common/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit bb6fa13

Please sign in to comment.