Skip to content

Commit f8f9a30

Browse files
committed
[stm32f407-explorer] 优化FAL相关设置
1 parent edf7e90 commit f8f9a30

File tree

6 files changed

+91
-12
lines changed

6 files changed

+91
-12
lines changed

bsp/stm32/stm32f407-atk-explorer/board/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ menu "Onboard Peripheral Drivers"
100100
select BSP_USING_SPI_FLASH
101101
select BSP_USING_FS
102102
select PKG_USING_FAL
103-
select FAL_USING_SFUD_PORT
103+
select FAL_USING_AUTO_INIT
104+
select FAL_PART_HAS_TABLE_CFG
104105
select PKG_USING_LITTLEFS
105106
select RT_USING_SYSTEM_WORKQUEUE
106107
default n

bsp/stm32/stm32f407-atk-explorer/board/SConscript

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ if GetDepend(['BSP_USING_SPI_FLASH']):
2020

2121
if GetDepend(['BSP_USING_FS']):
2222
src += Glob('ports/drv_filesystem.c')
23+
if GetDepend(['BSP_USING_SPI_FLASH_LITTLEFS']):
24+
src += Glob('ports/fal_spi_flash_sfud_port.c')
2325

2426
if GetDepend(['BSP_USING_SRAM']):
2527
src += Glob('ports/drv_sram.c')

bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ static int onboard_spiflash_mount(void)
8383
{
8484
struct rt_device *mtd_dev = RT_NULL;
8585

86+
#ifndef FAL_USING_AUTO_INIT
8687
fal_init();
88+
#endif
8789

8890
mtd_dev = fal_mtd_nor_device_create(FS_PARTITION_NAME);
8991
if (!mtd_dev)

bsp/stm32/stm32f407-atk-explorer/board/ports/fal_cfg.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <board.h>
1616

1717
#ifdef BSP_USING_SPI_FLASH_LITTLEFS
18-
extern struct fal_flash_dev nor_flash0;
18+
extern struct fal_flash_dev w25q128;
1919
#else
2020
#define FLASH_SIZE_GRANULARITY_16K (4 * 16 * 1024)
2121
#define FLASH_SIZE_GRANULARITY_64K (64 * 1024)
@@ -34,7 +34,7 @@ extern const struct fal_flash_dev stm32_onchip_flash_128k;
3434
#ifdef BSP_USING_SPI_FLASH_LITTLEFS
3535
#define FAL_FLASH_DEV_TABLE \
3636
{ \
37-
&nor_flash0, \
37+
&w25q128, \
3838
}
3939
#else
4040
#define FAL_FLASH_DEV_TABLE \
@@ -52,7 +52,7 @@ extern const struct fal_flash_dev stm32_onchip_flash_128k;
5252
#ifdef BSP_USING_SPI_FLASH_LITTLEFS
5353
#define FAL_PART_TABLE \
5454
{ \
55-
{FAL_PART_MAGIC_WROD, "spiflash0", FAL_USING_NOR_FLASH_DEV_NAME, 0 , 16 * 1024 * 1024, 0}, \
55+
{FAL_PART_MAGIC_WROD, "spiflash0", "W25Q128", 0 , 16 * 1024 * 1024, 0}, \
5656
}
5757
#else
5858
#define FAL_PART_TABLE \
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-08-07 Meco Man first version
9+
*/
10+
11+
#include <fal.h>
12+
#include <sfud.h>
13+
14+
#ifdef RT_USING_SFUD
15+
#include <spi_flash_sfud.h>
16+
#endif
17+
18+
static int init(void);
19+
static int read(long offset, uint8_t *buf, size_t size);
20+
static int write(long offset, const uint8_t *buf, size_t size);
21+
static int erase(long offset, size_t size);
22+
23+
static sfud_flash_t sfud_dev = NULL;
24+
struct fal_flash_dev w25q128 =
25+
{
26+
.name = "W25Q128",
27+
.addr = 0,
28+
.len = 16 * 1024 * 1024,
29+
.blk_size = 4096,
30+
.ops = {init, read, write, erase},
31+
.write_gran = 1
32+
};
33+
34+
static int init(void)
35+
{
36+
sfud_dev = rt_sfud_flash_find_by_dev_name("W25Q128");
37+
if (RT_NULL == sfud_dev)
38+
{
39+
return -1;
40+
}
41+
42+
/* update the flash chip information */
43+
w25q128.blk_size = sfud_dev->chip.erase_gran;
44+
w25q128.len = sfud_dev->chip.capacity;
45+
46+
return 0;
47+
}
48+
49+
static int read(long offset, uint8_t *buf, size_t size)
50+
{
51+
assert(sfud_dev);
52+
assert(sfud_dev->init_ok);
53+
sfud_read(sfud_dev, w25q128.addr + offset, size, buf);
54+
55+
return size;
56+
}
57+
58+
static int write(long offset, const uint8_t *buf, size_t size)
59+
{
60+
assert(sfud_dev);
61+
assert(sfud_dev->init_ok);
62+
if (sfud_write(sfud_dev, w25q128.addr + offset, size, buf) != SFUD_SUCCESS)
63+
{
64+
return -1;
65+
}
66+
67+
return size;
68+
}
69+
70+
static int erase(long offset, size_t size)
71+
{
72+
assert(sfud_dev);
73+
assert(sfud_dev->init_ok);
74+
if (sfud_erase(sfud_dev, w25q128.addr + offset, size) != SFUD_SUCCESS)
75+
{
76+
return -1;
77+
}
78+
79+
return size;
80+
}

bsp/stm32/stm32f407-atk-explorer/board/ports/spi_flash_init.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,15 @@
1515

1616
#if defined(BSP_USING_SPI_FLASH)
1717

18-
#ifdef FAL_USING_NOR_FLASH_DEV_NAME
19-
#define _SPI_FLASH_NAME FAL_USING_NOR_FLASH_DEV_NAME
20-
#else
21-
#define _SPI_FLASH_NAME "W25Q128"
22-
#endif
23-
2418
static int rt_hw_spi_flash_init(void)
2519
{
2620
__HAL_RCC_GPIOB_CLK_ENABLE();
2721
rt_hw_spi_device_attach("spi1", "spi10", GPIOB, GPIO_PIN_14);
2822

29-
if (RT_NULL == rt_sfud_flash_probe(_SPI_FLASH_NAME, "spi10"))
23+
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "spi10"))
3024
{
3125
return -RT_ERROR;
32-
};
26+
}
3327

3428
return RT_EOK;
3529
}

0 commit comments

Comments
 (0)