【AT32A403A Automotive MCU Development Board】 TobudOS Porting
[Copy link]
This post was last edited by TL-LED on 2024-1-26 14:54
Learn to port TobudOS system to AT32A403 development board.
1. Introduction to TobudOS
TobudOS is a real-time operating system developed for the Internet of Things field. It is based on Tencent's self-developed Internet of Things operating system TencentOS Tiny open source project. In 2020, Tencent donated it to the Open Atom Open Source Foundation for incubation. In 2023, it was officially renamed TobudOS. TobudOS has the characteristics of low power consumption, low resource usage, modularization, security and reliability, which can effectively improve the efficiency of IoT terminal product development, provide a streamlined RTOS kernel, and the kernel components can be cut and configured, which can be quickly ported to a variety of mainstream MCUs (such as the full range of STM32) and module chips. Moreover, based on the RTOS kernel, it provides a wealth of IoT components, and integrates mainstream IoT protocol stacks (such as CoAP/MQTT/TLS/DTLS/LoRaWAN/NB-IoT, etc.), which can help IoT terminal devices and services quickly access the IoT cloud platform.
2. Source code download
Download address: https://atomgit.com/OpenAtomFoundation/TobudOS
3. Copy files
3.1. Copy files to project files
3.2. Add files to the project
4. Procedure
4.1, tos_config.h
#ifndef _TOS_CONFIG_H_
#define _TOS_CONFIG_H_
#include "at32a403a.h" // 目标芯片头文件,用户需要根据情况更改
#define TOS_CFG_TASK_PRIO_MAX 10u // 配置TencentOS tiny默认支持的最大优先级数量
#define TOS_CFG_ROUND_ROBIN_EN 0u // 配置TencentOS tiny的内核是否开启时间片轮转
#define TOS_CFG_OBJECT_VERIFY_EN 1u // 配置TencentOS tiny是否校验指针合法
#define TOS_CFG_TASK_DYNAMIC_CREATE_EN 1u // TencentOS tiny 动态任务创建功能宏
#define TOS_CFG_EVENT_EN 1u // TencentOS tiny 事件模块功能宏
#define TOS_CFG_MMBLK_EN 1u //配置TencentOS tiny是否开启内存块管理模块
#define TOS_CFG_MMHEAP_EN 1u //配置TencentOS tiny是否开启动态内存模块
#define TOS_CFG_MMHEAP_DEFAULT_POOL_EN 1u // TencentOS tiny 默认动态内存池功能宏
#define TOS_CFG_MMHEAP_DEFAULT_POOL_SIZE 0x100 // 配置TencentOS tiny默认动态内存池大小
#define TOS_CFG_MUTEX_EN 1u // 配置TencentOS tiny是否开启互斥锁模块
#define TOS_CFG_MESSAGE_QUEUE_EN 1u // 配置TencentOS tiny是否开启消息队列模块
#define TOS_CFG_MAIL_QUEUE_EN 1u // 配置TencentOS tiny是否开启消息邮箱模块
#define TOS_CFG_PRIORITY_MESSAGE_QUEUE_EN 1u // 配置TencentOS tiny是否开启优先级消息队列模块
#define TOS_CFG_PRIORITY_MAIL_QUEUE_EN 1u // 配置TencentOS tiny是否开启优先级消息邮箱模块
#define TOS_CFG_TIMER_EN 1u // 配置TencentOS tiny是否开启软件定时器模块
#define TOS_CFG_PWR_MGR_EN 0u // 配置TencentOS tiny是否开启外设电源管理模块
#define TOS_CFG_TICKLESS_EN 0u // 配置Tickless 低功耗模块开关
#define TOS_CFG_SEM_EN 1u // 配置TencentOS tiny是否开启信号量模块
#define TOS_CFG_TASK_STACK_DRAUGHT_DEPTH_DETACT_EN 1u // 配置TencentOS tiny是否开启任务栈深度检测
#define TOS_CFG_FAULT_BACKTRACE_EN 0u // 配置TencentOS tiny是否开启异常栈回溯功能
#define TOS_CFG_IDLE_TASK_STK_SIZE 128u // 配置TencentOS tiny空闲任务栈大小
#define TOS_CFG_CPU_TICK_PER_SECOND 1000u // 配置TencentOS tiny的tick频率
#define TOS_CFG_CPU_CLOCK (SystemCoreClock) // 配置TencentOS tiny CPU频率
#define TOS_CFG_TIMER_AS_PROC 1u // 配置是否将TIMER配置成函数模式
#define TOS_CFG_OBJ_DYNAMIC_CREATE_EN 1u // 配置是否开启任务的动态分配处理和堆栈
#endif
4.2, fun_task.c
#include "main.h"
//task1
#define TASK1_STK_SIZE 256
void task1(void *pdata);
osThreadDef(task1, osPriorityNormal, 1, TASK1_STK_SIZE);
//task2
#define TASK2_STK_SIZE 256
void task2(void *pdata);
osThreadDef(task2, osPriorityNormal, 1, TASK2_STK_SIZE);
void task1(void *pdata)
{
int count = 1;
while(1)
{
printf("\r\nHello world!\r\n###This is task1 ,count is %d \r\n", count++);
led2_tog();
osDelay(2000);
}
}
void task2(void *pdata)
{
int count = 1;
while(1)
{
printf("\r\nHello TencentOS !\r\n***This is task2 ,count is %d \r\n", count++);
led3_tog();
osDelay(1000);
}
}
void task_create(void)
{
osThreadCreate(osThread(task1), NULL);// Create task1
osThreadCreate(osThread(task2), NULL);// Create task2
osKernelStart();//Start TOS Tiny
}
int fputc(int ch, FILE *f)
{
if (ch == '\n')
{
while(usart_flag_get(USART1, USART_TDBE_FLAG) == RESET);
usart_data_transmit(USART1, (uint16_t)ch);
while(usart_flag_get(USART1, USART_TDC_FLAG) == RESET);
}
while(usart_flag_get(USART1, USART_TDBE_FLAG) == RESET);
usart_data_transmit(USART1, (uint16_t)ch);
while(usart_flag_get(USART1, USART_TDC_FLAG) == RESET);
return ch;
}
4.3, main.c
#include "main.h"
int main(void)
{
system_clock_config();
delay_init();
init_usart(115200);
init_led();
// init_eint();
// init_key();
osKernelInitialize(); //TOS Tiny kernel initialize
task_create();
while(1)
{
}
}
5. Program running
Download the program to the development board, run it, and the serial port outputs
|