Contributed by End, curated by Ai-Thinker
04 - Lighting an LED from Scratch on the Ai-M61-32S
Reference Posts
Software and hardware platform

Operation Steps
Set up the environment
Most people joining this activity have already set up the environment; basically, as long as make succeeds, you’re good. The post above also provides a tutorial, so I won’t repeat it. The key next step is finding the SDK — that’s the most important thing for development.

Choose an example
In Ai-M6X-SDK, find the gpio peripheral files under examples. The examples provide rich development cases worth learning.


Write the code
Copy gpio_input_output and rename it gpio_input_output_rgb. Of course, you can directly use the provided example without creating a new one; I just did this for clarity.

Modify cmakelist.txt: project(gpio_input_output_rgb)
Write the code:
#include "bflb_gpio.h"
#include "board.h"
struct bflb_device_s *gpio;
uint32_t gpio_group[] = {GPIO_PIN_12, GPIO_PIN_14, GPIO_PIN_15};
int main(void)
{
board_init();
gpio = bflb_device_get_by_name("gpio"); // get gpio device
// set gpio pin mode
bflb_gpio_init(gpio, GPIO_PIN_12, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_0);
bflb_gpio_init(gpio, GPIO_PIN_14, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_0);
bflb_gpio_init(gpio, GPIO_PIN_15, GPIO_OUTPUT | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_0);
bflb_gpio_reset(gpio, GPIO_PIN_12);
bflb_gpio_reset(gpio, GPIO_PIN_14);
bflb_gpio_reset(gpio, GPIO_PIN_15);
uint8_t i = 0;
while (1) {
for(uint8_t j = 0; j < 2; j++) {
bflb_gpio_set(gpio, gpio_group);
bflb_mtimer_delay_ms(200);
bflb_gpio_reset(gpio, gpio_group);
bflb_mtimer_delay_ms(200);
}
bflb_gpio_set(gpio, gpio_group);
bflb_mtimer_delay_ms(500);
bflb_gpio_reset(gpio, gpio_group);
i = (i + 1) % 3;
}
}
Download the code
Connect the board to the computer with a Type-C cable, open Device Manager, and check the ports. Since the board has an onboard CH340 chip, no other tools are needed.
Open a terminal and run make clean to clear any build files from previous compilations, then run make again.

Ready to download. First hold the IO2 button to enter flash mode — keep holding it. Then press the EN button and release, and enter make flash COMX=COM16 in the command line to start flashing.

After flashing, press EN to reset and you can see the RGB LED blinking.
Observe the result


