Precautions for transplanting EasyFlash and ulog_easyflash by RT-Thread Studio

Github official source code and documentation see here:
https://github.com/armink/EasyFlash
https://github.com/armink-rtt-pkgs/ulog_easyflash

The transplantation process can refer to the official documentation. Here is a brief introduction to the pits I stepped on during the transplantation process and some precautions:

  1. Try to use a log in RT-Thread, ulog and easylogger can choose one as much as possible, otherwise it will cause some unnecessary trouble. When I originally configured easylogger on the basis of opening ulog, I encountered a problem during INFO initialization. Later, I found that the ulog configuration and EasyLogger were partly linked, and it was troublesome to modify. ulog_easyflash is actually a kind of backend of ulog, which can be perfectly connected to easyflash, so if you can use ulog, you should choose the official recommended ulog as much as possible.

  2. EasyFlash currently supports only 3 hardware platforms (as of my blogging time 2020/8/15): stm32f10x and stm32f40x on-chip Flash, and off-chip FLASH based on SPI (QSPI), so if it is not an f1 or f4 chip It is better to use off-chip FLASH. There are two ways to transplant the off-chip Flash: based on the fal library and based on the SFUD library. Therefore, if you are using off-chip Flash, remember to configure the above two libraries first. The configuration method given in the official manual is as follows. This blogger uses the F7 series chip, so it uses QSPI and SFUD-based configuration (see my previous blog: RT-Thread Studio configures QSPI and SFUD ).
    Insert picture description here
    Insert picture description here

  3. When configuring the software package in RT-Thread Studio, adding ulog_easyflash directly will configure easyflash as much as possible, and then enter the more configuration options of the software package, mainly to configure EasyFlash, refer to the official configuration information, if it is Based on SPI-based off-chip Flash, the minimum erasing granularity is 4K=4096, and the minimum writing granularity is 1bit. In order to cooperate with ulog and enable the log function, the size of the log area saved in the configuration is 255*4096=1044480. And turn on the Flash backend function of the ulog_easyflash software package.
    Insert picture description here

  4. After the configuration is complete, save and update the software package, and then copy the ef_sfud_port.c file (path/ports/ef_sfud_port.c) in the port folder of the EasyFlash software package to the src path. If the migration is unsuccessful, please carefully check the header file under /inc and the internal configuration of rtconfig.h. Generally, there is a problem when the internal macro defines the relevant parameters. Note that in RT-Thread Studio, RT-Thread Settings basically replaces the role of ENV, so various application checks, configurations and enabling are mainly completed here.

  5. If an error such as "sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'" occurs during the compilation process, it is because RT-Studio uses gcc compilation internally, and some embedded bottom layers Compilation of the C language library may not be supported, so please select to enable libc in the "Component and Service Layer" menu bar of RT-Thread Settings .

  6. Note that you need to declare the device first to find this thing when EasyFlash is initialized, and then the initialization can be successful. The following functions are defined in the ef_sfud_port.c file. Mainly look at the bottom of the remarks, it declares a spi_flash device called w25q64, which means you should also use this name when you declare the device before EasyFlash is initialized.

static const sfud_flash *flash;
EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size) {
    
    
    EfErrCode result = EF_NO_ERR;
    ...
    /* 从 RT-Thread 的 SPI Flash 设备中获取 SFUD Flash 设备对象 */
    extern rt_spi_flash_device_t w25q64;
    flash = (sfud_flash_t)(w25q64->user_data);
    return result;
}
  1. Of course, you can also modify it. Since the F7 development board I use is the off-chip FLASH of W25Q254, I will directly modify the name in this section of the program, and then initialize it in the main function.
EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size) {
    
    
    EfErrCode result = EF_NO_ERR;

    *default_env = default_env_set;
    *default_env_size = sizeof(default_env_set) / sizeof(default_env_set[0]);

    rt_sem_init(&env_cache_lock, "env lock", 1, RT_IPC_FLAG_PRIO);

    extern rt_spi_flash_device_t w25q256;
    flash = (sfud_flash_t)(w25q256->user_data);

    return result;
}
  1. Note that ulog can only be successfully read after writing to the log, so we can configure the program in main as follows
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <sfud.h>
#include <sfud_def.h>
#include <spi_flash_sfud.h>
#include <easyflash.h>

#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

rt_spi_flash_device_t w25q256;

int main(void)
{
    
    
    if ((w25q256 = rt_sfud_flash_probe("W25Q256FV", "qspi10")) == NULL) {
    
    
        rt_kprintf("Error! W25Q256FV NOT FOUND!");
    }
    easyflash_init();
    LOG_D("Hello world!");
    
    while (1)
    {
    
    
        rt_thread_mdelay(1000);
    }

    return RT_EOK;
}

After you see the following output, it proves that EasyFlash initialization is completed. A
Insert picture description here
simple test. Since we have output a log "Hello world" in the main() function, the result of using the ulog_easyflash command ulog_flash read is as follows (please ignore the previous clean Information, this is the legacy result when I wrote the program test myself) The
Insert picture description here
above is all, if there is an error, please leave a message in time.

Guess you like

Origin blog.csdn.net/moumde/article/details/108027100