这次简单的给py32移植一下rt-thread nano
开发板:py32f003_startkit (py32f003f16u flash 32k sram 4k)
ide:mdk5
1.准备工作
这里bsp我直接使用厂商提供的bsp,原本想要直接选择芯片自己新建工程的,但是根据官方的教程一直没有成功于是就直接用现成的bsp了
下载:点击pack installer
选择rt-thread进行下载
manage rum-time environment,本次我们就只移植kernel,shell暂时我还用不上所以就先不移植了
2.清除重定义
rt-thread在运行过程中会使用到handfault_handler和pendsv_handler用于线程切换,异常处理,所以需要将py32f0xx_it.c中的这两个函数删除,否则链接时会提示重定义
还有mdk中main函数的入口函数extern int super$main(void);原来是在system_py32f0xx.c中实现的,rtthread也进行了接管在启动流程中是如下流程
rt_application_init->main_thread_entry->super$main(void),所以我们需要把system_py32f0xx.c中的删除
3.完成rt_hw_board_init
void rt_hw_board_init(void)
{
/*
todo 1: os tick configurationenable the hardware timer and call the rt_os_tick_callback functionperiodically with the frequency rt_tick_per_second.
/
/ call components board initial (use init_board_export()) */
hal_init();
app_systemclockconfig(); // 配置系统时钟
systemcoreclockupdate(); // 对系统时钟进行更新
systick_config(systemcoreclock / rt_tick_per_second);
#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
}
4.修改内存堆
因为这个芯片sram很小所以我这里就给了2kb#define rt_heap_size (2*1024)
static rt_uint8_t rt_heap[rt_heap_size];
5.愉快的点灯
/**
@file main.c
@author mcu application team
@brief main program body
@attention
© copyright (c) puya semiconductor co. all rights reserved.© copyright (c) 2016 stmicroelectronics. all rights reserved.this software component is licensed by st under bsd 3-clause license,
the license; you may not use this file except in compliance with the
license. you may obtain a copy of the license at:
opensource.org/licenses/bsd-3-clause/
/ includes ------------------------------------------------------------------/
#include main.h
#include
/ private define ------------------------------------------------------------/
/ private variables ---------------------------------------------------------/
/ private user code ---------------------------------------------------------/
/ private macro -------------------------------------------------------------/
/ private function prototypes -----------------------------------------------*/
/**
@brief 应用程序入口函数.
@retval int
/
static void app_ledconfig(void);
int main(void)
{
app_ledconfig();
while (1)
{
rt_thread_delay(500);
hal_gpio_togglepin(gpiob, gpio_pin_5);
}
}
/ *
@brief 错误执行函数
@param 无
@retval 无
/
void app_errorhandler(void)
{
/ 无限循环 /
while (1)
{
}
}
static void app_ledconfig(void)
{
gpio_inittypedef gpio_initstruct;
__hal_rcc_gpiob_clk_enable(); / gpiob时钟使能 /
gpio_initstruct.pin = gpio_pin_5;
gpio_initstruct.mode = gpio_mode_output_pp; / 推挽输出 /
gpio_initstruct.pull = gpio_pullup; / 使能上拉 /
gpio_initstruct.speed = gpio_speed_freq_high; / gpio速度 /
hal_gpio_init(gpiob, &gpio_initstruct); / gpio初始化 /
}
#ifdef use_full_assert
/ *
@brief 输出产生断言错误的源文件名及行号
@param file:源文件名指针
@param line:发生断言错误的行号
@retval 无
/
void assert_failed(uint8_t file, uint32_t line)
{
/ 用户可以根据需要添加自己的打印信息,
例如: printf(wrong parameters value: file %s on line %drn, file, line) /
/ 无限循环 /
while (1)
{
}
}
#endif / use_full_assert /
/ ********************** (c) copyright puya end of file *************/
结果:led亮灭500ms
打破空间限制 彰显激光电视灵活优势
数控冲剪复合机床在钣金加工工艺中的应用
台积电进退两难,对华为真的是雪中送炭?
mos管噪声计算方法
浅谈Sub-6 GHz和毫米波技术
PY32移植RT-Thread Nano记录
iQOO Neo5携骁龙870和独显芯片于3月16日正式亮相
金属激光打标机:在精细工艺中展现卓越性能
电池技术的停滞是阻碍小屏手机重回市场主要原因之一
Accurate DC-DC Converter Minim
基于快消行业的仓储管理系统解决方案
区块链技术在网络安全方面的主要优势介绍
看看协议中是如何描述Buffer Status Reporting的?
[视频]HP Touchpad深入评测
在Simulink环境中对空气弹簧进行建模
AI正在重塑动力电池制造
MAX6023精密的、低功耗、低压差、UCSP封装电压基准
现场仪表基础知识汇总
华为Sound X立体声套装正式开售
荣耀Magic V2折叠屏手机将于年底发布