[fal] Add blocks mechanism to fal. (#8252)

This commit is contained in:
guo 2023-11-13 22:49:16 +08:00 committed by GitHub
parent 3aa19af301
commit 6d7e393ce9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -73,6 +73,16 @@ if (!(EXPR)) \
#define FAL_DEV_NAME_MAX 24
#endif
#ifndef FAL_DEV_BLK_MAX
#define FAL_DEV_BLK_MAX 6
#endif
struct flash_blk
{
size_t size;
size_t count;
};
struct fal_flash_dev
{
char name[FAL_DEV_NAME_MAX];
@ -95,6 +105,7 @@ struct fal_flash_dev
1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1)/ 64(stm32l4)
0 will not take effect. */
size_t write_gran;
struct flash_blk blocks[FAL_DEV_BLK_MAX];
};
typedef struct fal_flash_dev *fal_flash_dev_t;

View File

@ -27,7 +27,7 @@ static uint8_t init_ok = 0;
*/
int fal_flash_init(void)
{
size_t i;
size_t i, j, offset;
if (init_ok)
{
@ -47,6 +47,17 @@ int fal_flash_init(void)
log_d("Flash device | %*.*s | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
FAL_DEV_NAME_MAX, FAL_DEV_NAME_MAX, device_table[i]->name, device_table[i]->addr, device_table[i]->len,
device_table[i]->blk_size);
offset = 0;
for (j = 0; j < FAL_DEV_BLK_MAX; j ++)
{
const struct flash_blk *blk = &device_table[i]->blocks[j];
size_t blk_len = blk->count * blk->size;
if (blk->count == 0 || blk->size == 0)
break;
log_d(" blk%2d | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
j, device_table[i]->addr + offset, blk_len, blk->size);
offset += blk_len;
}
}
init_ok = 1;