Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spiflash: Make STM32 spiflash code common for all BSP #3356

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) && 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)
{
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
Loading