提交 8d45e7f8 编写于 作者: whj123999's avatar whj123999

add drv_flash_h7.c

上级 b91f1ab5
......@@ -73,6 +73,9 @@ if GetDepend(['BSP_USING_ON_CHIP_FLASH', 'SOC_SERIES_STM32F7']):
if GetDepend(['BSP_USING_ON_CHIP_FLASH', 'SOC_SERIES_STM32L4']):
src += ['drv_flash/drv_flash_l4.c']
if GetDepend(['BSP_USING_ON_CHIP_FLASH', 'SOC_SERIES_STM32H7']):
src += ['drv_flash/drv_flash_h7.c']
if GetDepend('RT_USING_HWCRYPTO'):
src += ['drv_crypto.c']
......
......@@ -34,8 +34,6 @@
#define ADDR_FLASH_SECTOR_7 ((rt_uint32_t)0x080E0000) /* Base address of Sector 7, 128 Kbytes */
#define ADDR_FLASH_SECTOR_8 ((rt_uint32_t)0x08100000) /* Base address of Sector 8, 128 Kbytes */
#define FLASH_SECTOR_0 0U /* Sector Number 0 */
#define FLASH_SECTOR_1 1U /* Sector Number 1 */
#define FLASH_SECTOR_2 2U /* Sector Number 2 */
......@@ -53,15 +51,14 @@
*/
static void GetSector(rt_uint32_t Address,uint32_t* bank,uint32_t* sector)
{
#if defined (FLASH_OPTCR_nDBANK)
FLASH_OBProgramInitTypeDef OBInit;
uint32_t nbank = 0;
//get duel bank ability:nDBANK(Bit29)
/* get duel bank ability:nDBANK(Bit29) */
HAL_FLASHEx_OBGetConfig(&OBInit);
nbank = ((OBInit.USERConfig & 0x20000000U) >> 29);
//1:single bank mode
/* 1:single bank mode */
if (1 == nbank)
{
if ((Address < ADDR_FLASH_SECTOR_1) && (Address >= ADDR_FLASH_SECTOR_0))
......@@ -113,25 +110,25 @@ static void GetSector(rt_uint32_t Address,uint32_t* bank,uint32_t* sector)
sector = FLASH_SECTOR_11;
}
}
else //0:dual bank mode
else /* 0:dual bank mode */
{
LOG_E("rtthread doesn't support duel bank mode yet!");
RT_ASSERT(0);
}
#else //no dual bank ability
*sector = (Address&0xffffff)/FLASH_SIZE_GRANULARITY_128K;
if(*sector>7)
{
*bank = FLASH_BANK_1;
*sector = *sector/2;
}
else
*bank = FLASH_BANK_2;
#else /* no dual bank ability */
*sector = (Address&0xffffff)/FLASH_SIZE_GRANULARITY_128K;
if(*sector>7)
{
*bank = FLASH_BANK_1;
*sector = *sector/2;
}
else
{
*bank = FLASH_BANK_2;
}
#endif
}
/**
* Read data from flash.
* @note This operation's units is word.
......@@ -251,10 +248,10 @@ int stm32_flash_erase(rt_uint32_t addr, size_t size)
/* Get the 1st sector to erase */
GetSector(addr,&bank,&FirstSector);
/* Get the number of sector to erase from 1st sector*/
/* Get the number of sector to erase from 1st sector */
GetSector(addr + size,0,&NbOfSectors);
NbOfSectors = NbOfSectors - FirstSector + 1;
/* Fill EraseInit structure*/
/* Fill EraseInit structure */
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;
EraseInitStruct.Sector = FirstSector;
......@@ -281,14 +278,9 @@ __exit:
}
#if defined(PKG_USING_FAL)
static int fal_flash_read_128k(long offset, rt_uint8_t *buf, size_t size);
static int fal_flash_write_128k(long offset, const rt_uint8_t *buf, size_t size);
static int fal_flash_erase_128k(long offset, size_t size);
const struct fal_flash_dev stm32_onchip_flash_128k = { "onchip_flash_128k", STM32_FLASH_START_ADRESS, FLASH_SIZE_GRANULARITY_128K, (128 * 1024), {NULL, fal_flash_read_128k, fal_flash_write_128k, fal_flash_erase_128k} };
static int fal_flash_read_128k(long offset, rt_uint8_t *buf, size_t size)
......
......@@ -9,14 +9,13 @@
* 2020-5-17 yufanyufan77 support H7
*/
#ifndef _FAL_CFG_H_
#define _FAL_CFG_H_
#ifndef __FAL_CFG_H__
#define __FAL_CFG_H__
#include <rtthread.h>
#include <board.h>
#define FLASH_SIZE_GRANULARITY_128K (16 * 128 * 1024)
#define FLASH_SIZE_GRANULARITY_128K (16 * 128 * 1024)
#define STM32_FLASH_START_ADRESS_128K (0x8000000)
extern const struct fal_flash_dev stm32_onchip_flash_128k;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册