Porting Guide
The main work of transplantation is on the FAL side. Other interfaces are not strongly dependent, and can be connected according to your own situation.
It is recommended to understand the FAL function introduction before transplantation, see: http://packages.rt-thread.org/detail.html?package=fal
The bottom layer of FAL encapsulates different Flash storage media in a unified manner and provides a partition table mechanism to expose it to upper users.
Each database of FlashDB is based on the partitioning mechanism provided by FAL. Each database is located on a FAL partition, which is equivalent to a partition corresponding to a database.
The following will explain the FAL porting process in detail. For more porting demonstrations, please refer to the demo provided.
FAL migration
Before defining the Flash device table, you need to define the Flash device first. It can be on-chip flash, or off-chip SFUD-based spi flash:
- : read operation.
static int write(long offset, const uint8_t *buf, size_t size)
: write operation.
static int erase(long offset, size_t size)
: erase operation.
Users need to implement these operation functions according to their own Flash conditions. A specific Flash device object is defined at the bottom of the file. The following example defines stm32f2 on-chip flash: stm32f2_onchip_flash
"stm32_onchip"
: the name of the flash device.0x08000000
: Start address for flash operation.1024*1024
: Total size of Flash (1MB).: Flash block/sector size (because the STM32F2 blocks have uneven sizes, the erase granularity is the largest block size: 128K).
8
: Set the write granularity, the unit is bit, 0 means not effective (default value is 0), this member is a new member whose fal version is greater than 0.4.0. Each flash write granularity is not the same, it can be set by this member, the following are several common Flash write granularities:- nor flash: 1 bit
- stm32f2/f4: 8 bit
- stm32f1: 32 bit
- stm32l4: 64 bit
Equipment table example:
In the Flash device table, there are two Flash objects, one is the on-chip Flash of STM32F2, and the other is the off-chip Nor Flash.
The partition table is also defined in the fal_cfg.h
header file. Flash partitions are based on Flash devices, and each Flash device can have N partitions. The collection of these partitions is the partition table. Before configuring the partition table, make sure that the Flash device and device table have been defined. fal_cfg.h can be completed by referring to Sample file fal/samples/porting/fal_cfg.h.
Partition table example:
The detailed description of the above partition table is as follows:
The partition parameters that users need to modify include: partition name, associated Flash device name, offset address (relative to the internal Flash device), and size. Pay attention to the following points:
- Partition name guarantee cannot be repeated;
- The associated Flash device must have been defined in the Flash device table, and the name is the same, otherwise there will be an error that the Flash device cannot be found;