全球最实用的IT互联网信息网站!

AI人工智能P2P分享&下载搜索网页发布信息网站地图

当前位置:诺佳网 > 电子/半导体 > 控制/MCU >

PY32移植RT-Thread Nano记录

时间:2023-06-07 15:17

人气:

作者:admin

标签: 记录  RT-Thread  Nano  移植  PY32 

导读:这里bsp我直接使用厂商提供的bsp,原本想要直接选择芯片自己新建工程的,但是根据官方的教程一直没有成功于是就直接用现成的bsp了...

这次简单的给PY32移植一下RT-Thread Nano

开发板:PY32F003_StartKit (PY32F003F16U Flash 32K SRAM 4K)

IDE:MDK5

1.准备工作

这里bsp我直接使用厂商提供的bsp,原本想要直接选择芯片自己新建工程的,但是根据官方的教程一直没有成功于是就直接用现成的bsp了

下载:点击Pack installer

1.jpg

选择RT-Thread进行下载

1.jpg

Manage Rum-Time Environment,本次我们就只移植kernel,shell暂时我还用不上所以就先不移植了

1.jpg

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 Configuration

Enable the hardware timer and call the rt_os_tick_callback function

periodically 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 %d\\r\\n", file, line) */

/* 无限循环 */

while (1)

{

}

}

#endif /* USE_FULL_ASSERT */

/** ********************** (C) COPYRIGHT Puya END OF FILE *************/

结果:LED亮灭500ms.

温馨提示:以上内容整理于网络,仅供参考,如果对您有帮助,留下您的阅读感言吧!
相关阅读
本类排行
相关标签
本类推荐

CPU | 内存 | 硬盘 | 显卡 | 显示器 | 主板 | 电源 | 键鼠 | 网站地图

Copyright © 2025-2035 诺佳网 版权所有 备案号:赣ICP备2025066733号
本站资料均来源互联网收集整理,作品版权归作者所有,如果侵犯了您的版权,请跟我们联系。

关注微信