From c4d0c915021c8a520dcba2dcaeea2fb39e6422dd Mon Sep 17 00:00:00 2001 From: tyustli <1225613647@qq.com> Date: Wed, 21 Aug 2019 18:39:14 +0800 Subject: [PATCH] [bsp] [stm32] fix drv_flash_l4.c bug --- .../HAL_Drivers/drv_flash/drv_flash_l4.c | 10 ++-- bsp/stm32/stm32l452-st-nucleo/board/Kconfig | 8 +-- .../stm32l452-st-nucleo/board/SConscript | 1 + .../stm32l452-st-nucleo/board/ports/fal_cfg.h | 51 +++++++++++++++++++ 4 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 bsp/stm32/stm32l452-st-nucleo/board/ports/fal_cfg.h diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_flash/drv_flash_l4.c b/bsp/stm32/libraries/HAL_Drivers/drv_flash/drv_flash_l4.c index a05be7ce6b..2f724de718 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_flash/drv_flash_l4.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_flash/drv_flash_l4.c @@ -12,8 +12,8 @@ #ifdef BSP_USING_ON_CHIP_FLASH #include "drv_config.h" -#include "drv_flash.h" - +#include "drv_flash.h" + #if defined(PKG_USING_FAL) #include "fal.h" #endif @@ -53,8 +53,8 @@ static uint32_t GetPage(uint32_t Addr) static uint32_t GetBank(uint32_t Addr) { uint32_t bank = 0; -#if defined (STM32L432xx) - bank = FLASH_BANK_1; +#ifndef FLASH_BANK_2 + bank = FLASH_BANK_1; #else if (READ_BIT(SYSCFG->MEMRMP, SYSCFG_MEMRMP_FB_MODE) == 0) { @@ -135,7 +135,7 @@ int stm32_flash_write(rt_uint32_t addr, const uint8_t *buf, size_t size) LOG_E("ERROR: write outrange flash size! addr is (0x%p)\n", (void*)(addr + size)); return -RT_EINVAL; } - + if(addr % 8 != 0) { LOG_E("write addr must be 8-byte alignment"); diff --git a/bsp/stm32/stm32l452-st-nucleo/board/Kconfig b/bsp/stm32/stm32l452-st-nucleo/board/Kconfig index e757acf26d..a0c9e1f009 100644 --- a/bsp/stm32/stm32l452-st-nucleo/board/Kconfig +++ b/bsp/stm32/stm32l452-st-nucleo/board/Kconfig @@ -29,8 +29,8 @@ menu "On-chip Peripheral Drivers" bool "Enable UART1 RX DMA" depends on BSP_USING_UART1 && RT_SERIAL_USING_DMA default n - - config BSP_USING_UART2 + + config BSP_USING_UART2 bool "Enable UART2" default y @@ -60,7 +60,9 @@ menu "On-chip Peripheral Drivers" select BSP_SPI1_TX_USING_DMA default n endif - + config BSP_USING_ON_CHIP_FLASH + bool "Enable on-chip FLASH" + default n menuconfig BSP_USING_I2C1 bool "Enable I2C1 BUS (software simulation)" default n diff --git a/bsp/stm32/stm32l452-st-nucleo/board/SConscript b/bsp/stm32/stm32l452-st-nucleo/board/SConscript index ab57c2310a..cdc93c9ac8 100644 --- a/bsp/stm32/stm32l452-st-nucleo/board/SConscript +++ b/bsp/stm32/stm32l452-st-nucleo/board/SConscript @@ -14,6 +14,7 @@ CubeMX_Config/Src/stm32l4xx_hal_msp.c path = [cwd] path += [cwd + '/CubeMX_Config/Inc'] +path += [cwd + '/ports'] startup_path_prefix = SDK_LIB diff --git a/bsp/stm32/stm32l452-st-nucleo/board/ports/fal_cfg.h b/bsp/stm32/stm32l452-st-nucleo/board/ports/fal_cfg.h new file mode 100644 index 0000000000..db782a5991 --- /dev/null +++ b/bsp/stm32/stm32l452-st-nucleo/board/ports/fal_cfg.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-12-5 SummerGift first version + */ + +#ifndef _FAL_CFG_H_ +#define _FAL_CFG_H_ + +#include +#include + +#if defined(BSP_USING_ON_CHIP_FLASH) +extern const struct fal_flash_dev stm32_onchip_flash; +#endif /* BSP_USING_ON_CHIP_FLASH */ + +/* ========================= Device Configuration ========================== */ +#ifdef BSP_USING_ON_CHIP_FLASH +#define ONCHIP_FLASH_DEV &stm32_onchip_flash, +#else +#define ONCHIP_FLASH_DEV +#endif /* BSP_USING_ON_CHIP_FLASH */ + +/* flash device table */ +#define FAL_FLASH_DEV_TABLE \ +{ \ + ONCHIP_FLASH_DEV \ +} + +/* ====================== Partition Configuration ========================== */ +#ifdef FAL_PART_HAS_TABLE_CFG + +#ifdef BSP_USING_ON_CHIP_FLASH +#define ONCHIP_FLASH_PATITION {FAL_PART_MAGIC_WROD, "app", "onchip_flash", 0, 496 * 1024, 0}, \ + {FAL_PART_MAGIC_WROD, "param", "onchip_flash", 496* 1024, 16 * 1024, 0}, +#else +#define ONCHIP_FLASH_PATITION +#endif + +/* partition table */ +#define FAL_PART_TABLE \ +{ \ + ONCHIP_FLASH_PATITION \ +} +#endif /* FAL_PART_HAS_TABLE_CFG */ + +#endif /* _FAL_CFG_H_ */