This project is ideal for learning embedded development fundamentals, including GPIO control, Wi-Fi connectivity, and FreeRTOS task management.

2. Development Environment Setup

2.1 Hardware Requirements

  • BW20-12F development board ×1
  • USB data cable
  • Ubuntu virtual machine (VMware Workstation)

 

2.2 Software Environment

I am using Ubuntu 22.04, and the Ameba RTOS SDK has been downloaded to the desktop.

First, we must resolve a common issue: Python package installation timeout. Because the default PyPI mirror is overseas, the download is slow. So we first configure the Tsinghua University mirror:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

After configuration, enter the SDK directory and initialize the environment: cd ~/Desktop/ameba/ameba-rtos

source ameba.sh

The first run will automatically install Python dependencies. Please wait patiently.

2.3 Fixing Serial Port Permission Issues

When using a USB serial port inside a virtual machine, the device may fail to be recognized. This is because a service called brltty (Braille device tool) occupies the USB port.

Disable it using:

sudo systemctl stop brltty-udev.service sudo systemctl mask brltty-udev.service sudo systemctl disable brltty.service

Then connect the USB device in VMware:

VM -> Removable Devices -> QinHeng Electronics CH340 -> Connect

Check whether the device is available:

ls -la /dev/ttyUSB*

Normally you should see /dev/ttyUSB0.

3. Project Directory Structure

I created a project folder under the SDK’s my_project directory:

mkdir -p ~/Desktop/ameba/ameba-rtos/my_project/wifi_led_component cd ~/Desktop/ameba/ameba-rtos/my_project/wifi_led_component

Project structure:

wifi_led_component/

├── CMakeLists.txt            # CMake build configuration

├── include/                  # Header files (optional)

├── wifi_led.h                # LED & Wi-Fi control header

├── wifi_led.c                # LED & Wi-Fi control implementation

└── wifi_led_example.c        # Example main program

 

4. Code Implementation

4.1 CMakeLists.txt

This file instructs the build system on how to compile the project.

There are two sections:

  • Public section: headers/macros available to other modules
  • Private section: source files for this component only

At first, my source file path was incorrect. I put files in the root directory but wrote:

src/wifi_led.c

The correct configuration:

ameba_list_append(private_sources

    wifi_led.c

    wifi_led_example.c

)

 

4.2 GPIO & Header File Issues

I initially used many incorrect header files found online, such as: wifi_conf.h, osdep_service.h, etc., which caused compilation errors.

After checking the SDK, the correct headers are:

  • wifi_api.h — Wi-Fi API declarations
  • wifi_api_types.h — Wi-Fi type definitions
  • wifi_api_event.h — Wi-Fi event definitions (though later I found event callback APIs were not available)
  • PB17 — green LED
  • PB18 — red LED
  • PB19 — blue LED
  • unused parameters → add (void)param;
  • type mismatch → use  for >span class="16"###s32
  • header not found → verify #include

Search header files using:

find ~/Desktop/ameba/ameba-rtos/component/wifi/api -name "*.h" LED pin mapping on the board:

 

4.3 Key Points for Wi-Fi Connection

I encountered several issues when implementing Wi-Fi connectivity.

Issue 1: Struct initialization error causing crash

I initially used strncpy to copy the password into the struct, but password in...

Read more »