Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
移植问题
NUC029
国产MCU移植
将RT-Thread移植到新唐NUC029上
发布于 2020-08-20 10:43:19 浏览:1358
订阅该版
board.c ```c /* * Copyright (c) 2006-2019, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2017-07-24 Tanek the first version * 2018-11-12 Ernest Chen modify copyright */ #include
#include
#include
#include
//#include "uart.h" #include "NUC029xGE.h" #define PLL_CLOCK 72000000 #define _SCB_BASE (0xE000E010UL) #define _SYSTICK_CTRL (*(rt_uint32_t *)(_SCB_BASE + 0x0)) #define _SYSTICK_LOAD (*(rt_uint32_t *)(_SCB_BASE + 0x4)) #define _SYSTICK_VAL (*(rt_uint32_t *)(_SCB_BASE + 0x8)) #define _SYSTICK_CALIB (*(rt_uint32_t *)(_SCB_BASE + 0xC)) #define _SYSTICK_PRI (*(rt_uint8_t *)(0xE000ED23UL)) // Updates the variable SystemCoreClock and must be called // whenever the core clock is changed during program execution. extern void SystemCoreClockUpdate(void); // Holds the system core clock, which is the system clock // frequency supplied to the SysTick timer and the processor // core clock. extern uint32_t SystemCoreClock; static uint32_t _SysTick_Config(rt_uint32_t ticks) { if ((ticks - 1) > 0xFFFFFF) { return 1; } _SYSTICK_LOAD = ticks - 1; _SYSTICK_PRI = 0xFF; _SYSTICK_VAL = 0; _SYSTICK_CTRL = 0x07; return 0; } #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) #define RT_HEAP_SIZE 1024 static uint32_t rt_heap[RT_HEAP_SIZE]; // heap default size: 4K(1024 * 4) RT_WEAK void *rt_heap_begin_get(void) { return rt_heap; } RT_WEAK void *rt_heap_end_get(void) { return rt_heap + RT_HEAP_SIZE; } #endif /*自己添加跟硬件有关的时钟初始化*/ static void rt_hw_system_init(void) { /*---------------------------------------------------------------------------------------------------------*/ /* Init System Clock */ /*---------------------------------------------------------------------------------------------------------*/ SYS_UnlockReg(); /* Enable HIRC clock (Internal RC 22.1184MHz) */ CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk); /* Wait for HIRC clock ready */ CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk); /* Select HCLK clock source as HIRC and HCLK clock divider as 1 */ CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1)); /* Set core clock as PLL_CLOCK from PLL */ CLK_SetCoreClock(PLL_CLOCK); /* Set SysTick clock source to HCLK source divide 2 */ CLK_SetSysTickClockSrc(CLK_CLKSEL0_STCLKSEL_HCLK_DIV2); SYS_LockReg(); } /*自己添加跟串口有关的时钟初始化*/ static void rt_hw_usart_init() { /* Unlock protected registers */ SYS_UnlockReg(); /* Enable HXT clock (external XTAL 12MHz) */ CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk); /* Wait for HXT clock ready */ CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk); /* Enable UART module clock */ CLK_EnableModuleClock(UART0_MODULE); /* Select UART module clock source as HXT and UART module clock divider as 1 */ CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UARTSEL_HXT, CLK_CLKDIV0_UART(1)); /*---------------------------------------------------------------------------------------------------------*/ /* Init I/O Multi-function */ /*---------------------------------------------------------------------------------------------------------*/ /* Set multi-function pins for UART0 RXD and TXD */ SYS->GPA_MFPL &= ~(SYS_GPA_MFPL_PA2MFP_Msk | SYS_GPA_MFPL_PA3MFP_Msk); SYS->GPA_MFPL |= (SYS_GPA_MFPL_PA3MFP_UART0_RXD | SYS_GPA_MFPL_PA2MFP_UART0_TXD); /* Lock protected registers */ SYS_LockReg(); /* Reset UART0 */ SYS_ResetModule(UART0_RST); /* Configure UART0 and set UART0 baud rate */ UART_Open(UART0, 115200); } /** * This function will initial your board. */ void rt_hw_board_init() { /* Configure the system clock */ rt_hw_system_init(); /* System Clock Update */ SystemCoreClockUpdate(); /* System Tick Configuration */ _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); /* Initial usart deriver, and set console device */ rt_hw_usart_init(); /* Call components board initial (use INIT_BOARD_EXPORT()) */ #ifdef RT_USING_COMPONENTS_INIT rt_components_board_init(); #endif #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get()); #endif } void SysTick_Handler(void) { /* enter interrupt */ rt_interrupt_enter(); rt_tick_increase(); /* leave interrupt */ rt_interrupt_leave(); } /*自己添加对接串口控制台*/ void rt_hw_console_output(const char *str) { printf("%s",str); } char rt_hw_console_getchar(void) { return getchar(); } ``` rtconfig.h ```c /* RT-Thread config file */ #ifndef __RTTHREAD_CFG_H__ #define __RTTHREAD_CFG_H__ #if defined(__CC_ARM) || defined(__CLANG_ARM) //#include "RTE_Components.h" //#if defined(RTE_USING_FINSH) #define RT_USING_FINSH //#endif //RTE_USING_FINSH #endif //(__CC_ARM) || (__CLANG_ARM) // <<< Use Configuration Wizard in Context Menu >>> //
Basic Configuration //
Maximal level of thread priority <8-256> //
Default: 32 #define RT_THREAD_PRIORITY_MAX 8 //
OS tick per second //
Default: 1000 (1ms) #define RT_TICK_PER_SECOND 1000 //
Alignment size for CPU architecture data access //
Default: 4 #define RT_ALIGN_SIZE 4 //
the max length of object name<2-16> //
Default: 8 #define RT_NAME_MAX 8 //
Using RT-Thread components initialization //
Using RT-Thread components initialization #define RT_USING_COMPONENTS_INIT // #define RT_USING_USER_MAIN //
the stack size of main thread<1-4086> //
Default: 512 #define RT_MAIN_THREAD_STACK_SIZE 256 //
//
Debug Configuration //
enable kernel debug configuration //
Default: enable kernel debug configuration #define RT_DEBUG // //
enable components initialization debug configuration<0-1> //
Default: 0 #define RT_DEBUG_INIT 0 //
thread stack over flow detect //
Diable Thread stack over flow detect //#define RT_USING_OVERFLOW_CHECK // //
//
Hook Configuration //
using hook //
using hook #define RT_USING_HOOK // //
using idle hook //
using idle hook //#define RT_USING_IDLE_HOOK // //
//
Software timers Configuration //
Enables user timers #define RT_USING_TIMER_SOFT 0 #if RT_USING_TIMER_SOFT == 0 #undef RT_USING_TIMER_SOFT #endif //
The priority level of timer thread <0-31> //
Default: 4 #define RT_TIMER_THREAD_PRIO 4 //
The stack size of timer thread <0-8192> //
Default: 512 #define RT_TIMER_THREAD_STACK_SIZE 512 //
//
IPC(Inter-process communication) Configuration //
Using Semaphore //
Using Semaphore #define RT_USING_SEMAPHORE // //
Using Mutex //
Using Mutex //#define RT_USING_MUTEX // //
Using Event //
Using Event //#define RT_USING_EVENT // //
Using MailBox //
Using MailBox #define RT_USING_MAILBOX // //
Using Message Queue //
Using Message Queue //#define RT_USING_MESSAGEQUEUE // //
//
Memory Management Configuration //
Dynamic Heap Management //
Dynamic Heap Management #define RT_USING_HEAP // //
using small memory //
using small memory #define RT_USING_SMALL_MEM // //
using tiny size of memory //
using tiny size of memory //#define RT_USING_TINY_SIZE // //
//
Console Configuration //
Using console //
Using console #define RT_USING_CONSOLE // //
the buffer size of console <1-1024> //
the buffer size of console //
Default: 128 (128Byte) #define RT_CONSOLEBUF_SIZE 128 //
#if defined(RT_USING_FINSH) #define FINSH_USING_MSH #define FINSH_USING_MSH_ONLY //
Finsh Configuration //
the priority of finsh thread <1-7> //
the priority of finsh thread //
Default: 6 #define __FINSH_THREAD_PRIORITY 5 #define FINSH_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 8 * __FINSH_THREAD_PRIORITY + 1) //
the stack of finsh thread <1-4096> //
the stack of finsh thread //
Default: 4096 (4096Byte) #define FINSH_THREAD_STACK_SIZE 512 //
the history lines of finsh thread <1-32> //
the history lines of finsh thread //
Default: 5 #define FINSH_HISTORY_LINES 1 #define FINSH_USING_SYMTAB //
#endif // <<< end of configuration section >>> #endif ```
2
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
gaoyang9992006
这家伙很懒,什么也没写!
文章
2
回答
2
被采纳
0
关注TA
发私信
相关文章
1
RT-Thread 在ARM926 EJSA 内核的移植
2
裸机工程移植 RT-Thread
3
Keil MDK 移植 RT-Thread Nano
4
移植 Nano,rt_thread_mdelay()延迟时间不对
5
裸机工程移植 RT-Thread内核
6
跳转不进去main函数
7
我从KEIL 移植过来的 time外部中断定时器是失败的
8
Ambiq Apollo3 移植链接脚本问题
9
可以把 RT-Thread Studio 创建的项目移植到 Keil上面吗?
10
RT_USING_COMPONENTS_INIT 这部分相关的有没有更详细的介绍
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
rt_mq_消息队列_msg_queue
keil_MDK
ulog
MicroPython
C++_cpp
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
a1012112796
20
个答案
2
次被采纳
张世争
11
个答案
2
次被采纳
rv666
9
个答案
2
次被采纳
用户名由3_15位
13
个答案
1
次被采纳
本月文章贡献
程序员阿伟
9
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
RTT_逍遥
1
篇文章
6
次点赞
大龄码农
1
篇文章
5
次点赞
ThinkCode
1
篇文章
1
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部