10 系统

10.1 Lcpu中ROM空间中固化的Function;和变量该如何调用和替换?

In order to save the code of Lcpu RAM space, the ROM has solidified the BLE protocol stack, RTT OS, complete HAL code and some driver code;,
In Lcpu, the functions and variables that can be called by customers are placed in a symble file;:
SDK\example\ble\lcpu_general\project\ec-lb551\rom.sym 文件中,并且声明为Not;带__weakParameter;的强Function;.

Therefore, when writing code, if the ROM code can be called, the code in the ROM will be called as much as possible;. 比如:
The function HAL_I2C_Mem_Read in the file bf0_hal_i2c.c that you see in the SDK will participate in the compilation, but at the time of linking, it is defined as a weak function;:

#define __HAL_ROM_USED __weak 


alt text

而在Corresponding;的example\ble\lcpu_general\project\ec-lb551\rom.sym 文件中,As follows;Figure;:

alt text

There are also functions with the same name, and they are not __weak functions, so they will be linked to the strong function code in the ROM, so the above rt_kprintf will not be printed;.
If you want to run the function of HAL_I2C_Mem_Read and replace the function in the ROM, first delete example\ble\lcpu_general\project\ec-lb551\rom.sym; # 该路径项目Not;同Will;Not;一样,Can;Check;编译过程log来定位,As follows;Figure;:

alt text

Then command scons -c to clear the lcpu compilation result and recompile. The corresponding line 0x00005621 T HAL_I2C_Mem_Read in the file, during compilation and linking, since there is only this one HAL_I2C_Mem_Read weak function, this __weak function will be linked;
At this time, in the figure above, the rt_kprintf(“my own HAL_I2C_Mem_Read\r\n”); print you added will be able to print out;.
To confirm whether the function used is in the ROM or in the code, you can search for the corresponding address of this function in the map file compiled by Lcpu;。

10.2 获取当前重启方式接口

The identifiable startup states of the current SF32LB55X chip are as follows;:

/** power on mode */
typedef enum
{
    PM_COLD_BOOT = 0  /**< cold boot */
    PM_STANDBY_BOOT,   /**< boot from standby power mode */
    PM_HIBERNATE_BOOT, /**< boot from hibernate mode, system can be woken up by RTC and PIN precisely */
    PM_SHUTDOWN_BOOT   /**< boot from shutdown mode, system can be woken by RTC and PIN, but wakeup time is not accurate */
} pm_power_on_mode_t;

Can;Through;调用:

pm_power_on_mode_t SystemPowerOnModeGet(void)
{
    return g_pwron_mode;
}

To get the startup mode;;
Note;: 上电, wdt,Button;reset和HAL_PMU_Reboot四种cold root是没法区分;

10.3 mainFunction;是lcpu的入口Function;吗

lcpuReset;地址在

alt text

The main function is the main function of one of the threads started after the initialization is completed;;

10.4 Lcpu如何唤醒Hcpu

a,Lcpu can send messages to hcpu through ipc_send_msg_from_sensor_to_app as follows, this message can wake up Hcpu;

static void battery_send_event_to_app(event_type_t type)
{
    event_remind_t remind_ind;

    rt_kprintf("battery_send_event_to_app: event %d\n", type);
    remind_ind.event = type;
    ipc_send_msg_from_sensor_to_app(SENSOR_APP_EVENT_BATTERY_IND, sizeof(event_remind_t), &remind_ind);
}

b,After the Hcpu wakes up, add the code to handle this message in the task;,As follows;:
alt text

10.5 MCU进入Boot_Mode的方法

The internal ROM of the SiFli series MCU has solidified a boot code. In the case where the MCU does not need to burn any code, it will enter the boot code when powered on. The boot code already has common flash storage drivers, and decides how the code jumps by reading the configuration of the fixed address Flashtable of the external storage. If the flashtable read by the boot code is incorrect, it will always be within the boot_mode code. You can check whether it is in the boot_mode code interval by comparing the address of the PC pointer with the HPSYS address mapping in the chip manual. The ROM interval address where the boot code is located is usually as follows;:

Memory

Address space

Starting Address

Ending Address

ROM

64KB

0x0000_0000

0x0000_FFFF

The use of entering boot_mode;:
1,Hardware debugging, can determine whether the MCU is running normally without burning any program;;
2,In the case where the user program crashes or other situations cause Jlink or Uart to be disconnected, enter the boot_mdoe mode to ensure normal program download;;

10.5.1 55/58/56Series;MCU进入Boot Mode方法


alt text

The 55, 58, 56 series MCUs all have a BOOT_MODE pin, pulling BOOT_MODE high and resetting or powering on will enter boot_mode, the following log will appear on the default debug serial port of Lcpu, this serial port is also the default uart download port;

   Serial:c2,Chip:2,Package:0,Rev:0;
    \ | /;
   - SiFli Corporation
    / | \     build on Mar 20 2022, 1.2.0 build dbebac
    2020 - 2022 Copyright by SiFli team
   msh >

In boot_mode, to verify uart download, you can also enter the help command to verify whether the serial port is connected, the operation is as follows;:

   Serial:c2,Chip:2,Package:0,Rev:0;
    \ | /;
   - SiFli Corporation
    / | \     build on Mar 20 2022, 1.2.0 build dbebac
    2020 - 2022 Copyright by SiFli team
   msh >
TX:help
   help
   RT-Thread shell commands:
   list_mem 
   uart 
   spi_flash 
   reboot 
   regop 
   dump_config 
   dfu_recv 
   reset 
   lcpu 
   sysinfo 
   version 
   console 
   help 
   time 
   free 
   msh >


Note;
The log output of boot_mode after BOOT_MODE is pulled high comes from the internal solidified ROM code and does not depend on external code. If there is no such log, please check whether the serial port connection and MCU working conditions have been met;

10.5.2 52Series;MCU进入Boot Mode方法


alt text
As shown in the figure above, you need to use the tool SiFli-SDK\tools\SifliTrace\SifliTrace.exe to connect the serial port and check the BOOT option, then restart the machine. The boot code solidified in 52 will wait for 2 seconds. After checking the BOOT option, the tool SifliTrace will send a command to let 52 enter boot_mode. If you only see the SFBL log and do not see the last two logs, it may be that the uart from PC’s TX to MCU’s RX is not connected;;

SFBL
receive boot info, stop it!!!
enter boot mode flow success!!!

也Can;Adopt;Tool;SiFli-SDK\tools\SifliUsartServer.exe和SifliTrace.exeTogether;Use;,As follows;Figure;:
alt text


Note;
SFBLThis;log,Not;Depend;于Software;,If;No;This;log,Please;查Serial port;Connection;和MCUWork;Condition;Whether;Already;Satisfy;

10.6 52 PA34LongReset;Time;Modify;

58,56,52Series;MCU都Support;LongPower;Button; (PWRKEY) Reset;;If;Chip;的Power;Button; PB54(58Series;), PB32 (56Series;),PA32(52Series;)Continuous;High level;Exceed;10Second;,Will;Happen;PWRKEYReset;,Will;Except;RTCAnd;IWDT以外的All;Module;Reset;。Through;PMUCRegister;WSR的PWRKEYFlag;Can;Query;Whether;Happen;过PWRKEYReset;,Through;PMUCRegister;WCR的PWRKEYCan;Clear;该Flag;。
Among;52Series;Can;Modify;Long按Reset;Time;(The 58 and 56 series do not have this register and do not support modification;),PWRKEY_HARD_RESET_TIMEDefault;Parameter;10为10Second;,可按照Need;Carry out;Modify;,Internal counting uses RC32 and does not rely on an external 32768 crystal clock;,Besides, the polarity of the button cannot be modified;;

#ifndef PWRKEY_HARD_RESET_TIME
    #define PWRKEY_HARD_RESET_TIME     (10)   /* unit:s */
#endif

The corresponding code configuration is within the initialization function HAL_PreInit;:

hwp_pmuc->PWRKEY_CNT = PWRKEY_CNT_CLOCK_FREQ * PWRKEY_HARD_RESET_TIME ;  //Set pwrkey hard reset time time*32768;