Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mozi
rt-thread
提交
b91f1ab5
R
rt-thread
项目概览
Mozi
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b91f1ab5
编写于
5月 20, 2020
作者:
whj123999
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[bsp/stm32/stm32h743-atk-apollo]support stm32h7 fal
上级
2cbb9c53
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
356 addition
and
0 deletion
+356
-0
bsp/stm32/libraries/HAL_Drivers/drv_flash/drv_flash_h7.c
bsp/stm32/libraries/HAL_Drivers/drv_flash/drv_flash_h7.c
+309
-0
bsp/stm32/stm32h743-atk-apollo/README.md
bsp/stm32/stm32h743-atk-apollo/README.md
+2
-0
bsp/stm32/stm32h743-atk-apollo/board/Kconfig
bsp/stm32/stm32h743-atk-apollo/board/Kconfig
+4
-0
bsp/stm32/stm32h743-atk-apollo/board/ports/fal_cfg.h
bsp/stm32/stm32h743-atk-apollo/board/ports/fal_cfg.h
+41
-0
未找到文件。
bsp/stm32/libraries/HAL_Drivers/drv_flash/drv_flash_h7.c
0 → 100644
浏览文件 @
b91f1ab5
/*
* 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
* 2019-3-2 jinsheng add Macro judgment
* 2020-1-6 duminmin support single bank mode
* 2020-5-17 yufanyufan77 support support H7
*/
#include "board.h"
#ifdef BSP_USING_ON_CHIP_FLASH
#include "drv_config.h"
#include "drv_flash.h"
#if defined(PKG_USING_FAL)
#include "fal.h"
#endif
//#define DRV_DEBUG
#define LOG_TAG "drv.flash"
#include <drv_log.h>
#define ADDR_FLASH_SECTOR_0 ((rt_uint32_t)0x08000000)
/* Base address of Sector 0, 128 Kbytes */
#define ADDR_FLASH_SECTOR_1 ((rt_uint32_t)0x08020000)
/* Base address of Sector 1, 128 Kbytes */
#define ADDR_FLASH_SECTOR_2 ((rt_uint32_t)0x08040000)
/* Base address of Sector 2, 128 Kbytes */
#define ADDR_FLASH_SECTOR_3 ((rt_uint32_t)0x08060000)
/* Base address of Sector 3, 128 Kbytes */
#define ADDR_FLASH_SECTOR_4 ((rt_uint32_t)0x08080000)
/* Base address of Sector 4, 128 Kbytes */
#define ADDR_FLASH_SECTOR_5 ((rt_uint32_t)0x080A0000)
/* Base address of Sector 5, 128 Kbytes */
#define ADDR_FLASH_SECTOR_6 ((rt_uint32_t)0x080C0000)
/* Base address of Sector 6, 128 Kbytes */
#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 */
#define FLASH_SECTOR_3 3U
/* Sector Number 3 */
#define FLASH_SECTOR_4 4U
/* Sector Number 4 */
#define FLASH_SECTOR_5 5U
/* Sector Number 5 */
#define FLASH_SECTOR_6 6U
/* Sector Number 6 */
#define FLASH_SECTOR_7 7U
/* Sector Number 7 */
/**
* @brief Gets the sector of a given address
* @param addr flash address
* @param flash bank
* @param flash sector
* @retval The sector of a given address
*/
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)
HAL_FLASHEx_OBGetConfig
(
&
OBInit
);
nbank
=
((
OBInit
.
USERConfig
&
0x20000000U
)
>>
29
);
//1:single bank mode
if
(
1
==
nbank
)
{
if
((
Address
<
ADDR_FLASH_SECTOR_1
)
&&
(
Address
>=
ADDR_FLASH_SECTOR_0
))
{
sector
=
FLASH_SECTOR_0
;
}
else
if
((
Address
<
ADDR_FLASH_SECTOR_2
)
&&
(
Address
>=
ADDR_FLASH_SECTOR_1
))
{
sector
=
FLASH_SECTOR_1
;
}
else
if
((
Address
<
ADDR_FLASH_SECTOR_3
)
&&
(
Address
>=
ADDR_FLASH_SECTOR_2
))
{
sector
=
FLASH_SECTOR_2
;
}
else
if
((
Address
<
ADDR_FLASH_SECTOR_4
)
&&
(
Address
>=
ADDR_FLASH_SECTOR_3
))
{
sector
=
FLASH_SECTOR_3
;
}
else
if
((
Address
<
ADDR_FLASH_SECTOR_5
)
&&
(
Address
>=
ADDR_FLASH_SECTOR_4
))
{
sector
=
FLASH_SECTOR_4
;
}
else
if
((
Address
<
ADDR_FLASH_SECTOR_6
)
&&
(
Address
>=
ADDR_FLASH_SECTOR_5
))
{
sector
=
FLASH_SECTOR_5
;
}
else
if
((
Address
<
ADDR_FLASH_SECTOR_7
)
&&
(
Address
>=
ADDR_FLASH_SECTOR_6
))
{
sector
=
FLASH_SECTOR_6
;
}
else
if
((
Address
<
ADDR_FLASH_SECTOR_8
)
&&
(
Address
>=
ADDR_FLASH_SECTOR_7
))
{
sector
=
FLASH_SECTOR_7
;
}
else
if
((
Address
<
ADDR_FLASH_SECTOR_9
)
&&
(
Address
>=
ADDR_FLASH_SECTOR_8
))
{
sector
=
FLASH_SECTOR_8
;
}
else
if
((
Address
<
ADDR_FLASH_SECTOR_10
)
&&
(
Address
>=
ADDR_FLASH_SECTOR_9
))
{
sector
=
FLASH_SECTOR_9
;
}
else
if
((
Address
<
ADDR_FLASH_SECTOR_11
)
&&
(
Address
>=
ADDR_FLASH_SECTOR_10
))
{
sector
=
FLASH_SECTOR_10
;
}
else
{
sector
=
FLASH_SECTOR_11
;
}
}
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
;
#endif
}
/**
* Read data from flash.
* @note This operation's units is word.
*
* @param addr flash address
* @param buf buffer to store read data
* @param size read bytes size
*
* @return result
*/
int
stm32_flash_read
(
rt_uint32_t
addr
,
rt_uint8_t
*
buf
,
size_t
size
)
{
size_t
i
;
if
((
addr
+
size
)
>
STM32_FLASH_END_ADDRESS
)
{
LOG_E
(
"read outrange flash size! addr is (0x%p)"
,
(
void
*
)(
addr
+
size
));
return
-
1
;
}
for
(
i
=
0
;
i
<
size
;
i
++
,
buf
++
,
addr
++
)
{
*
buf
=
*
(
rt_uint8_t
*
)
addr
;
}
return
size
;
}
/**
* Write data to flash.
* @note This operation's units is word.
* @note This operation must after erase. @see flash_erase.
*
* @param addr flash address
* @param buf the write data buffer
* @param size write bytes size
*
* @return result
*/
int
stm32_flash_write
(
rt_uint32_t
addr
,
const
rt_uint8_t
*
buf
,
size_t
size
)
{
rt_err_t
result
=
RT_EOK
;
rt_uint32_t
end_addr
=
addr
+
size
;
rt_uint32_t
bank
=
addr
/
ADDR_FLASH_SECTOR_8
;;
if
((
end_addr
)
>
STM32_FLASH_END_ADDRESS
)
{
LOG_E
(
"write outrange flash size! addr is (0x%p)"
,
(
void
*
)(
addr
+
size
));
return
-
RT_EINVAL
;
}
if
(
size
<
1
)
{
return
-
RT_EINVAL
;
}
/* Unlock the Flash to enable the flash control register access */
HAL_FLASH_Unlock
();
__HAL_FLASH_CLEAR_FLAG
(
FLASH_FLAG_EOP
|
FLASH_FLAG_OPERR
|
FLASH_FLAG_WRPERR
);
for
(
size_t
i
=
0
;
i
<
size
/
32
;
i
++
,
addr
+=
32
,
buf
+=
32
)
{
/* write data to flash */
if
(
HAL_FLASH_Program
(
FLASH_TYPEPROGRAM_FLASHWORD
,
addr
,
(
uint64_t
)((
uint32_t
)
buf
))
==
HAL_OK
)
{
if
(
*
(
rt_uint8_t
*
)
addr
!=
*
buf
)
{
result
=
-
RT_ERROR
;
break
;
}
}
else
{
result
=
-
RT_ERROR
;
break
;
}
}
HAL_FLASH_Lock
();
if
(
result
!=
RT_EOK
)
{
return
result
;
}
return
size
;
}
/**
* Erase data on flash.
* @note This operation is irreversible.
* @note This operation's units is different which on many chips.
*
* @param addr flash address
* @param size erase bytes size
*
* @return result
*/
int
stm32_flash_erase
(
rt_uint32_t
addr
,
size_t
size
)
{
rt_err_t
result
=
RT_EOK
;
rt_uint32_t
FirstSector
=
0
,
NbOfSectors
=
0
;
rt_uint32_t
SECTORError
=
0
;
rt_uint32_t
bank
=
0
;
if
((
addr
+
size
)
>
STM32_FLASH_END_ADDRESS
)
{
LOG_E
(
"ERROR: erase outrange flash size! addr is (0x%p)
\n
"
,
(
void
*
)(
addr
+
size
));
return
-
RT_EINVAL
;
}
/*Variable used for Erase procedure*/
FLASH_EraseInitTypeDef
EraseInitStruct
;
/* Unlock the Flash to enable the flash control register access */
HAL_FLASH_Unlock
();
/* Get the 1st sector to erase */
GetSector
(
addr
,
&
bank
,
&
FirstSector
);
/* Get the number of sector to erase from 1st sector*/
GetSector
(
addr
+
size
,
0
,
&
NbOfSectors
);
NbOfSectors
=
NbOfSectors
-
FirstSector
+
1
;
/* Fill EraseInit structure*/
EraseInitStruct
.
TypeErase
=
FLASH_TYPEERASE_SECTORS
;
EraseInitStruct
.
VoltageRange
=
FLASH_VOLTAGE_RANGE_3
;
EraseInitStruct
.
Sector
=
FirstSector
;
EraseInitStruct
.
NbSectors
=
NbOfSectors
;
EraseInitStruct
.
Banks
=
bank
;
if
(
HAL_FLASHEx_Erase
(
&
EraseInitStruct
,
&
SECTORError
)
!=
HAL_OK
)
{
result
=
-
RT_ERROR
;
goto
__exit
;
}
__exit:
HAL_FLASH_Lock
();
if
(
result
!=
RT_EOK
)
{
return
result
;
}
LOG_D
(
"erase done: addr (0x%p), size %d"
,
(
void
*
)
addr
,
size
);
return
size
;
}
#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
)
{
return
stm32_flash_read
(
stm32_onchip_flash_128k
.
addr
+
offset
,
buf
,
size
);
}
static
int
fal_flash_write_128k
(
long
offset
,
const
rt_uint8_t
*
buf
,
size_t
size
)
{
return
stm32_flash_write
(
stm32_onchip_flash_128k
.
addr
+
offset
,
buf
,
size
);
}
static
int
fal_flash_erase_128k
(
long
offset
,
size_t
size
)
{
return
stm32_flash_erase
(
stm32_onchip_flash_128k
.
addr
+
offset
,
size
);
}
#endif
#endif
/* BSP_USING_ON_CHIP_FLASH */
bsp/stm32/stm32h743-atk-apollo/README.md
浏览文件 @
b91f1ab5
...
...
@@ -60,6 +60,7 @@
| USB Device | 暂不支持 | |
| USB Host | 暂不支持 | |
| IWG | 支持 | |
| FLASH | 支持 | 已适配
[
FAL
](
https://github.com/RT-Thread-packages/fal
)
|
## 使用说明
...
...
@@ -118,6 +119,7 @@ msh >
## 注意事项
1.
使用UART2 DMA模式时,HEAP的CACHE策略设置了WT模式,所以在使用rt_device_read读取数据之前必须调用用SCB_InvalidateDCache_by_Addr或者SCB_InvalidateDCache,已确保读取到数据的正确性。
2.
使用FAL操作片内FLASH,每次读写必须是32字节的整数倍。
## 联系人信息
...
...
bsp/stm32/stm32h743-atk-apollo/board/Kconfig
浏览文件 @
b91f1ab5
...
...
@@ -110,6 +110,10 @@ menu "On-chip Peripheral Drivers"
default 117
endif
config BSP_USING_ON_CHIP_FLASH
bool "Enable on-chip FLASH"
default n
menuconfig BSP_USING_ONCHIP_RTC
bool "Enable RTC"
select RT_USING_RTC
...
...
bsp/stm32/stm32h743-atk-apollo/board/ports/fal_cfg.h
0 → 100644
浏览文件 @
b91f1ab5
/*
* 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
* 2020-5-17 yufanyufan77 support H7
*/
#ifndef _FAL_CFG_H_
#define _FAL_CFG_H_
#include <rtthread.h>
#include <board.h>
#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
;
/* flash device table */
#define FAL_FLASH_DEV_TABLE \
{ \
&stm32_onchip_flash_128k, \
}
/* ====================== Partition Configuration ========================== */
#ifdef FAL_PART_HAS_TABLE_CFG
/* partition table */
#define FAL_PART_TABLE \
{ \
{FAL_PART_MAGIC_WROD, "app", "onchip_flash_128k", 0 , 8*128*1024, 0}, \
{FAL_PART_MAGIC_WROD, "param", "onchip_flash_128k", 8*128*1024 , 128*1024, 0}, \
{FAL_PART_MAGIC_WROD, "factory", "onchip_flash_128k", 9*128*1024 , 7*128*1024, 0}, \
}
#endif
/* FAL_PART_HAS_TABLE_CFG */
#endif
/* _FAL_CFG_H_ */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录