Refer to the official Realtek documentation:
https://aiot.realmcu.com/cn/latest/rst_rtos/rst_sdk/0_ameba_sdk_download/index.html
II. Development Environment Setup1. SDK Downloadgit clone https://github.com/Ameba-AIoT/ameba-rtos.git
Or:
git clone https://gitee.com/ameba-aiot/ameba-rtos.git
2. Python InstallationAPT Installation:
sudo apt install python3 python3-pip python3-venv
Since UnionTech OS (UOS) APT installation only supports up to Python 3.7, which does not meet the requirements. Therefore, use pyenv to install Python.
# 1. Install pyenv
curl https://pyenv.run | bash
# 2. Reconfigure shell (choose according to your shell)
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc
# 3. Install dependencies and Python 3.12.0
sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
pyenv install 3.12.0
pyenv global 3.12.03. Software Suite DownloadMainly includes CMake, ninja, etc. If these are already installed on your system, you can skip this step.
mkdir /opt/rtk-toolchain
cd /opt/rtk-toolchaintar -xzf prebuilts-linux-1.0.3.tar.gzYou can also use the Aliyun address:
wget https://rs-wn.oss-cn-shanghai.aliyuncs.com/prebuilts-linux-1.0.3.tar.gz
The cross-compilation toolchain will also be downloaded to this path later. You can modify the permissions to avoid download failures:
chmod 777 /opt/rtk-toolchain4. Install Dependency Librariessudo apt install libssl-dev libncurses55. Configure EnvironmentEnter the SDK root directory and run the ameba.sh script to automatically configure environment variables:
source ameba.shThe toolchain is automatically installed to the default path /opt/rtk-toolchain during the first project compilation:
cd amebadplus_gcc_project
build.pyThe toolchain package is hosted on GitHub by default, and the system will attempt to download it from GitHub during the first compilation.If you have difficulty accessing GitHub, you can use the Aliyun URL:
build.py -D USE_ALIYUN_URL=TrueIII. LED Blinking TestEvery time you enter the development environment, you must first run: source ameba.sh
Create a new led_test directory:
#include "ameba_soc.h"
#include "gpio_ext.h"
#include "os_wrapper.h"
#include <stdio.h>
void raw_gpio_demo(void)
{
/* Enable GPIO function and clock */
// RCC_PeriphClockCmd(APBPeriph_GPIO, APBPeriph_GPIO_CLOCK, ENABLE);
printf("example_raw_gpio_light_weight\n");
GPIO_InitTypeDef GPIO_InitStruct_LED;
// init LED control pin
GPIO_InitStruct_LED.GPIO_Pin = GPIO_LED_PIN1;
GPIO_InitStruct_LED.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(&GPIO_InitStruct_LED);
GPIO_InitStruct_LED.GPIO_Pin = GPIO_LED_PIN2;
GPIO_Init(&GPIO_InitStruct_LED);
GPIO_InitStruct_LED.GPIO_Pin = GPIO_LED_PIN3;
GPIO_Init(&GPIO_InitStruct_LED);
GPIO_InitStruct_LED.GPIO_Pin = GPIO_LED_PIN4;
GPIO_Init(&GPIO_InitStruct_LED);
GPIO_InitStruct_LED.GPIO_Pin = GPIO_LED_PIN5;
GPIO_Init(&GPIO_InitStruct_LED);
while (1) {
GPIO_WriteBit(GPIO_LED_PIN1, 1);
GPIO_WriteBit(GPIO_LED_PIN5, 0);
rtos_time_delay_ms(1000);
GPIO_WriteBit(GPIO_LED_PIN1, 0);
GPIO_WriteBit(GPIO_LED_PIN2, 1);
rtos_time_delay_ms(1000);
GPIO_WriteBit(GPIO_LED_PIN2, 0);
GPIO_WriteBit(GPIO_LED_PIN3, 1);
rtos_time_delay_ms(1000);
GPIO_WriteBit(GPIO_LED_PIN3, 0);
GPIO_WriteBit(GPIO_LED_PIN4, 1);
rtos_time_delay_ms(1000);
GPIO_WriteBit(GPIO_LED_PIN4, 0);
GPIO_WriteBit(GPIO_LED_PIN5, 1);
rtos_time_delay_ms(1000);
}
}
int example_raw_gpio_light_weight(void)
{
if (RTK_SUCCESS != rtos_task_create(NULL, "RAW_GPIO_DEMO_TASK", (rtos_task_t)raw_gpio_demo, (void *)NULL, (128 * 16),
(1))) {
printf("Create RAW_GPIO_DEMO_TASK Err!!!\n");
}
// rtos_sched_start();
return 0;
}2、led_example.c#include "gpio_ext.h"
void app_example(void)
{
example_raw_gpio_light_weight();
}3、gpio_ext.hifndef GPIO_EXT_H
#define GPIO_EXT_H
#include "platform_autoconf.h"
#if defined (CONFIG_AMEBADPLUS)
#define GPIO_LED_PIN1 _PB_17
#define GPIO_LED_PIN2 _PB_18
#define GPIO_LED_PIN3 _PB_19
#define GPIO_LED_PIN4 _PB_20
#define GPIO_LED_PIN5 _PB_21
#define GPIO_PUSHBT_PIN _PA_12
extern int example_raw_gpio_light_weight(void);
#endif4、CMakeLists.txt.##########################################################################################
## * This part defines public part of the component
## * Public part will be used as global build configures for all component
set(public_includes) #public include directories, NOTE: relative path is OK
set(public_definitions) #public definitions
set(public_libraries) #public libraries(files), NOTE: linked with whole-archive options
#----------------------------------------#
# Component public part, user config begin
# Component public part, user config end
#----------------------------------------#
#WARNING: Fixed section, DO NOT change!
ameba_global_include(${public_includes})
ameba_global_define(${public_definitions})
ameba_global_library(${public_libraries}) #default: whole-archived
##########################################################################################
## * This part defines private part of the component
## * Private part is used to build target of current component
## * NOTE: The build API guarantees the global build configures(mentioned above)
## * applied to the target automatically. So if any configure was already added
## * to public above, it's unnecessary to add again below.
#NOTE: User defined section, add your private build configures here
# You may use if-else condition to set these predefined variable
# They are only for ameba_add_internal_library/ameba_add_external_app_library/ameba_add_external_soc_library
set(private_sources) #private source files, NOTE: relative path is OK
set(private_includes) #private include directories, NOTE: relative path is OK
set(private_definitions) #private definitions
set(private_compile_options) #private compile_options
#------------------------------#
# Component private part, user config begin
ameba_list_append(private_sources
led.c
led_example.c
)
# Component private part, user config end
#------------------------------#
#WARNING: Select right API based on your component's release/not-release/standalone
###NOTE: For open-source component, always build from source
ameba_add_internal_library(led_test
p_SOURCES
${private_sources}
p_INCLUDES
${private_includes}
p_DEFINITIONS
${private_definitions}
p_COMPILE_OPTIONS
${private_compile_options}
)
##########################################################################################5. Compilationcd amebadplus_gcc_project
build.py -a ~/mcu/Ameba-rtos/my_project/led_testflash.py -p /dev/ttyCH341USB0





Comments