你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32 Rtthread启动流程基于GNU交叉编译

[复制链接]
STMCU小助手 发布时间:2022-12-29 17:00
STM32 Rtthread启动流程基于GNU交叉编译
Rtthread并不是直接从main函数开始启动的,而是从componets.c中通过entry函数启动的:
  1. //需要在board.c中开启这个宏RT_USING_USER_MAIN

  2. //我使用的时GNU编译器,所以入口函数在这,可以在ld命令中指定entry为入口地址,
  3. //也可以在startup_stm32f411xe.s中指定入口地址为entry
  4. /* Add -eentry to arm-none-eabi-gcc argument */
  5. int entry(void)
  6. {
  7.     rtthread_startup();
  8.     return 0;
  9. }

  10. int rtthread_startup(void)
  11. {
  12.     rt_hw_interrupt_disable();

  13.     /* board level initialization
  14.      * NOTE: please initialize heap inside board initialization.
  15.      */
  16.     rt_hw_board_init();

  17.     /* show RT-Thread version */
  18.     rt_show_version();

  19.     /* timer system initialization */
  20.     rt_system_timer_init();

  21.     /* scheduler system initialization */
  22.     rt_system_scheduler_init();

  23.     /* create init_thread */
  24.     rt_application_init();

  25.     /* timer thread initialization */
  26.     rt_system_timer_thread_init();

  27.     /* idle thread initialization */
  28.     rt_thread_idle_init();

  29.     /* start scheduler */
  30.     rt_system_scheduler_start();

  31.     /* never reach here */
  32.     return 0;
  33. }

  34. //rt_hw_board_init函数在board.c中定义,主要功能是做硬件初始化
  35. void rt_hw_board_init()
  36. {
  37.     USART1_Config(115200);//串口初始化
  38.     KEY_Init();//按键初始化
  39.     LED_init();//LED初始化
  40.     /* System Clock Update */
  41.     //该函数在system_stm32f4xx.c中定义,主要功能是获取SystemCoreClock 的值。
  42.     SystemCoreClockUpdate();
  43.    
  44.     /* System Tick Configuration */
  45.     _SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);//RT_TICK_PER_SECOND 1000

  46.     /* Call components board initial (use INIT_BOARD_EXPORT()) */
  47. #ifdef RT_USING_COMPONENTS_INIT
  48.     rt_components_board_init();
  49. #endif

  50. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  51.     //rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  52. #endif

  53. #if defined(RT_USING_USER_MAIN) && defined(RT_USING_HEAP) //初始化堆
  54.    rt_system_heap_init(rt_heap_begin_get(), rt_heap_end_get());
  55. #endif

  56. }

  57. static uint32_t _SysTick_Config(rt_uint32_t ticks)
  58. {
  59.     if ((ticks - 1) > 0xFFFFFF)
  60.     {
  61.         return 1;
  62.     }
  63.    
  64.     _SYSTICK_LOAD = ticks - 1; //RELOAD VALUE
  65.     _SYSTICK_PRI = 0xFF;       //PRIORITY OF SYSTICK LOW
  66.     _SYSTICK_VAL  = 0;         //CLEAR CURRENT VALUE OF SYSTICK COUNT
  67.     //systick ctrl寄存器bit2 为1时使用AHB作为systic频率,不分频
  68.     _SYSTICK_CTRL = 0x07;      //0x07 BIT2 ==1 使用AHB,0:使用内部时钟源,AHB/8

  69.     return 0;
  70. }
  71. //rt_components_board_init函数会初始化INIT_EXPORT(fn, level) 宏包起来的函数
  72. //可以看看这篇文章:https://blog.csdn.net/qq_42370291/article/details/103639349
  73. void rt_components_board_init(void)
  74. {
  75. #if RT_DEBUG_INIT //开了RT_DEBUG_INIT 将会打印出被调用的初始化的函数
  76.     int result;
  77.     const struct rt_init_desc *desc;
  78.     for (desc = &__rt_init_desc_rti_board_start; desc < &__rt_init_desc_rti_board_end; desc ++)
  79.     {
  80.         rt_kprintf("initialize %s", desc->fn_name);
  81.         result = desc->fn();
  82.         rt_kprintf(":%d done\n", result);
  83.     }
  84. #else
  85.     volatile const init_fn_t *fn_ptr;

  86.     for (fn_ptr = &__rt_init_rti_board_start; fn_ptr < &__rt_init_rti_board_end; fn_ptr++)
  87.     {
  88.         (*fn_ptr)();
  89.     }
  90. #endif
  91. }
复制代码

在startup_stm32f411xe.s中指定入口地址为entry
  1. /* Call the application's entry point.*/
  2.   bl  entry //这里之前是main
  3.   bx  lr
复制代码
————————————————
版权声明:tony++

收藏 评论0 发布时间:2022-12-29 17:00

举报

0个回答

所属标签

相似分享

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版