Skip to content

Concepts First

  • Software reset: the program actively calls a reset API to restart the chip — commonly used after "config changed, restart now" or after an OTA upgrade.
  • Two reset APIs: bl_sys_reset_system() (software reset, immediate restart) and bl_sys_reset_por() (simulated power-on reset, deeper reset that clears more peripheral state).
  • Reset counter: after reset the program restarts from main and in-memory counters are cleared, so seeing the counter start over confirms the reset.
  • Avoid reset loops: calling a reset API unconditionally at the top of main reboots forever; the example uses a counter to control when to reset.

Example Overview

This page is a self-authored example (the SDK has no dedicated software-reboot example), written with the chip system driver APIs bl_sys_reset_por() / bl_sys_reset_system():

  • A static counter in main simulates "working for a while";
  • When the counter reaches 3, it prints a message and calls bl_sys_reset_system() for a software reset;
  • The serial port shows the loop: counter 0→3 → reset → counter 0→3 → reset;
  • bl_sys_reset_por() is commented out in the source; uncomment it to compare the deeper "simulated power-on reset".

Note

This self-authored example is for learning only: the API names match the SDK header (bl616_sys.h), but there is no same-named example in the official SDK repository. In real projects, scenarios like "restart after OTA" also need partition switching and persisted flags to avoid an endless reset loop.

Operation Steps

1
Create a Project Directory

The SDK has no dedicated software-reboot example, so this page is a self-authored example. Create a project directory under the SDK’s examples folder and enter it:

cd examples
mkdir soft_reboot_demo
cd soft_reboot_demo
2
Write the Code

Save the main.c from the Complete Code section into soft_reboot_demo/main.c, then create a Makefile (see the Build step):

vim main.c
3
Build the Project

A custom project needs a Makefile (this example does not use FreeRTOS, so FreeRTOSConfig.h can be omitted). A minimal Makefile looks like:

# Makefile (place in soft_reboot_demo, one level under examples)
SDK_DEMO_PATH ?= $(abspath .)
BL_SDK_BASE ?= $(abspath ./../..)
export BL_SDK_BASE

include $(BL_SDK_BASE)/project.build

Then build. The Ai-M62 (BL616) and Ai-M61 (BL618) belong to the same series, so both use bl616:

make CHIP=bl616 BOARD=bl616dk
4
Flash the Firmware

Connect the board with a USB cable, hold the BOOT button (IO2 on the Ai-M61-32S-Kit), briefly press EN/RST to enter download mode, then flash (replace the serial port with the one on your computer):

make flash CHIP=bl616 COMX=/dev/ttyUSB0
5
Run and Verify

Open a serial tool (baud rate 2000000). The program prints a counter; when it reaches 3 it prints soft reset by bl_sys_reset_system and resets. After reset the counter restarts from 0 and resets again at 3 — an endless loop. Replace bl_sys_reset_system() with bl_sys_reset_por() and re-flash to compare the two reset APIs.

Code Execution Flow

The complete flow from startup to reset is shown below (loop arrows mean repeated execution):

APIs Used by the Example

bl_sys_reset_system()

Software reset: triggers a system reset and the program restarts from the beginning. Local/global variables in main are re-initialized after reset.

Parameters: none

Return: void (never returns after the reset)

bl_sys_reset_por()

Simulated power-on reset (POR): deeper than a software reset; peripheral and power-domain state is restored more thoroughly.

Parameters: none

Return: int (never returns after the reset)

bl_sys_rstinfo_get()

Reads the reset reason (software reset, watchdog reset, brown-out reset, etc.) as a BL_RST_REASON_E enum. Real projects often read this at startup to learn why the chip restarted.

Parameters: none

Return: BL_RST_REASON_E reset-reason enum

Complete Code

The complete source below is the self-authored soft_reboot_demo/main.c (there is no same-named official SDK example; APIs match bl616_sys.h). Collapsed by default, click to expand:

📜 Click to expand soft_reboot_demo/main.c full code
c
#include "board.h"
#include "bflb_mtimer.h"
#include "bl616_sys.h"

int main(void)
{
    static uint32_t count = 0;

    board_init();

    while (1) {
        count++;
        printf("reboot count = %lu\r\n", count);

        if (count >= 3) {
            printf("soft reset by bl_sys_reset_system\r\n");
            bflb_mtimer_delay_ms(100);

            /* Software reset: restart the system immediately */
            bl_sys_reset_system();

            /* Deeper "simulated power-on reset", uncomment to compare */
            // bl_sys_reset_por();
        }

        bflb_mtimer_delay_ms(1000);
    }
}

FAQ

The program hangs instead of resetting

Confirm the header (bl616_sys.h) is included and the system driver is linked. If the custom project is missing drivers, copy the examples/helloworld project and replace its main.c.

The program resets endlessly

After reset the program runs from the top; an unconditional reset call reboots forever. The example uses a counter; in real projects persist a "reboot requested" flag in Flash, clear it after startup, and then decide whether to reset again.

bl_sys_reset_system vs. bl_sys_reset_por: which one to use

Use bl_sys_reset_system() for a normal software reset; use bl_sys_reset_por() when peripheral/power state needs a more thorough restore. Both clear running memory; the difference is reset depth.

Have questions?

For any other questions, visit the unified Q&A and discussion board: Ai-Thinker Discussions

Released under the MIT License. Build Time 2026-09-11 14:52:23