2 在线调试方法

2.1 断点调试方法

Crashes that occur in the bootloader code, during system startup, and during sleep wake-up may cause Jlink or the serial port to be unresponsive, and the crash phenomenon is often difficult to locate;,You can add breakpoints at the confirmed non-crash code locations, then connect online via SifliUsartServer or Jlink, and perform online single-step operation to locate the issue;,Breakpoints can be added at the very beginning of system reset;:
The HCPU startup assembly code is drivers/cmsis/sf32lb55x/Templates/arm/startup_bf0_hcpu.S; The LCPU startup assembly code is drivers/cmsis/sf32lb55x/Templates/arm/startup_bf0_lcpu.S;
在Reset_Handler中的第一条指令去掉注释 ‘;’, 变为B .

; Reset Handler
Reset_Handler   PROC
                EXPORT   Reset_Handler             [WEAK]
                IMPORT   SystemInit
                IMPORT   __main

                B        . ;//MCU复位后第一条指令执行的位置,添加断点

                LDR      R0, =__stack_limit
                MSR      MSPLIM, R0                          ; Non-secure version of MSPLIM is RAZ/WI

                LDR      R0, =SystemInit ;//对应c语言函数void SystemInit(void)
                BLX      R0
                LDR      R0, =__main ;//对应c语言函数int $Sub$$main(void)->rtthread_startup();
                BX       R0
                ENDP

This way, when the MCU starts up, it will stay at the first instruction. After Jlink connects successfully, you can change the PC register (+2) using Ozone or Keil, set the required breakpoints, and thus debug the initialization process;。
You can also add the assembly instruction __asm("B ."); inside the C files SystemInit() or rtthread_startup();

__ROM_USED int rtthread_startup(void)
{
    rt_hw_interrupt_disable();

    /* board level initialization
     * NOTE: please initialize heap inside board initialization.
     */
#ifdef RT_USING_PM
    rt_application_init_power_on_mode();
#endif // RT_USING_PM
    __asm("B ."); //设置断点
    rt_hw_board_init();

This makes the system stay at this instruction. At this point, connect Jlink again, use Ozone or Keil to change the PC register (+2), and continue single-step or breakpoint debugging;.

2.2 Ozone单步调试配置

Please refer to the relevant chapter on the Ozone tool;:
4.3 Ozone单步调试Debug

2.3 Keil单步调试配置


alt textalt textalt textalt textalt textalt text

  • Methods for importing axf files;:

  1. Import via command;
    alt text

  2. Import via script file;
    Add the script file loadaxf.ini in the keil root directory, with the following content;;
    alt text
    Note: The axf file bf0_ap.axf needs to be placed in the keil root directory;; Add loadaxf.ini to the configuration interface;;
    alt text