From c55bb827c8d9f314bf304dbd124e92f22fe50b51 Mon Sep 17 00:00:00 2001 From: brucechousz <37708191+brucechousz@users.noreply.github.com> Date: Sun, 8 Jul 2018 17:48:11 +0800 Subject: [PATCH] =?UTF-8?q?[BSP][STM32F4xx-HAL]=E6=9B=B4=E6=96=B0norflash?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8,=E5=A2=9E=E5=8A=A0=E5=AF=B9sfud=E7=9A=84?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32f4xx-HAL/Kconfig | 10 +++---- bsp/stm32f4xx-HAL/drivers/SConscript | 2 +- bsp/stm32f4xx-HAL/drivers/drv_spiflash.c | 35 ++++++++++++++++++------ 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/bsp/stm32f4xx-HAL/Kconfig b/bsp/stm32f4xx-HAL/Kconfig index f953d8f8ce..24a3c1d784 100644 --- a/bsp/stm32f4xx-HAL/Kconfig +++ b/bsp/stm32f4xx-HAL/Kconfig @@ -325,12 +325,12 @@ config RT_USING_SPI3 endif -if RT_USING_W25QXX -config RT_W25QXX_CS_PIN - int "W25QXX CS Pin index" +if RT_USING_W25QXX || RT_USING_SFUD +config RT_FLASH_CS_PIN + int "SPI NOR Flash CS pin index" default 0 -config RT_W25QXX_SPI_BUS_NAME - string "W25QXX Spi bus name" +config RT_FLASH_SPI_BUS_NAME + string "SPI NOR Flash Spi bus name" default "spi1" endif diff --git a/bsp/stm32f4xx-HAL/drivers/SConscript b/bsp/stm32f4xx-HAL/drivers/SConscript index d99bda18b1..9fc1d73715 100644 --- a/bsp/stm32f4xx-HAL/drivers/SConscript +++ b/bsp/stm32f4xx-HAL/drivers/SConscript @@ -19,7 +19,7 @@ if GetDepend(['RT_USING_SERIAL']): if GetDepend(['RT_USING_SPI']): src += ['drv_spi.c'] -if GetDepend(['RT_USING_W25QXX']): +if GetDepend(['RT_USING_W25QXX']) or GetDepend(['RT_USING_SFUD']): src += ['drv_spiflash.c'] if GetDepend(['RT_USING_WDT']): diff --git a/bsp/stm32f4xx-HAL/drivers/drv_spiflash.c b/bsp/stm32f4xx-HAL/drivers/drv_spiflash.c index 2d16ddab5a..cf30b949a6 100644 --- a/bsp/stm32f4xx-HAL/drivers/drv_spiflash.c +++ b/bsp/stm32f4xx-HAL/drivers/drv_spiflash.c @@ -12,13 +12,32 @@ * 2017-11-08 ZYH the first version */ #include +#if defined(RT_USING_W25QXX) || defined(RT_USING_SFUD) + #include #ifdef RT_USING_W25QXX -#include -#include "spi_flash_w25qxx.h" -int rt_w25qxx_init(void) -{ - stm32_spi_bus_attach_device(RT_W25QXX_CS_PIN, RT_W25QXX_SPI_BUS_NAME, "w25qxx"); - return w25qxx_init("flash0", "w25qxx"); -} -INIT_DEVICE_EXPORT(rt_w25qxx_init); + #include "spi_flash_w25qxx.h" +#elif defined(RT_USING_SFUD) + #include "string.h" + #include "spi_flash.h" + #include "spi_flash_sfud.h" + sfud_flash sfud_norflash0; + rt_spi_flash_device_t spi_device; +#endif + +int rt_nor_flash_init(void) +{ + stm32_spi_bus_attach_device(RT_FLASH_CS_PIN, RT_FLASH_SPI_BUS_NAME, "norspi"); +#ifdef RT_USING_W25QXX + return w25qxx_init("flash0", "norspi"); +#elif defined(RT_USING_SFUD) + spi_device = rt_sfud_flash_probe("flash0", "norspi"); + if (spi_device == RT_NULL) + { + return -RT_ERROR; + } + memcpy(&sfud_norflash0, spi_device->user_data, sizeof(sfud_flash)); + return 0; +#endif +} +INIT_DEVICE_EXPORT(rt_nor_flash_init); #endif