常见泽1 发表于 2023-10-22 22:15

【STM32F769-discovery开发板】第七篇 Rtthread工程CubeMX生成入门

<p>&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">打开CubeMX,CubeMX本身是不自带RTT组件的,需要自己安装</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">选择管理组件</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">添加新的PACK</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">添加Url,把网上找的Rt-thread链接放进去</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">点check-&gt;OK</span></span></p>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;"> &nbsp;</span></span></p>

<p >&nbsp;</p>

<p > &nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">开始下载</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">下载速度还是很快的</span></span></p>

<p >&nbsp;</p>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;"> &nbsp;</span></span></p>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">安装完毕</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;"> &nbsp;</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">在Cube工程里把RTTHREAD</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">三个全都勾选上</span></span></p>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;"> &nbsp;</span></span></p>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">RTTHREAD的默认参数都不改了,都直接默认</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;"> &nbsp;</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">以前的CubeMx好像取消HardFault_Handler、PendSV_Handler、SysTick_Handler中断函数(RTT已经定义了,需要在CubeMX上取消)</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">现在好像不需要了,我看生成的里面直接写了manage by RTOS</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;"> &nbsp;</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">除了这个Hard fault好像需要去掉勾</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;"> &nbsp;</span></span></p>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;"><b>RTTHRAED部分配置好了</b></span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;"><b>下面开始配置GPIO部分</b></span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;"> &nbsp;</span></span></p>

<p >&nbsp;</p>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">不建议HAL库和RTOS使用一个时钟源</span></span></p>

<p > &nbsp;</p>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;"> &nbsp;</span></span></p>

<p >&nbsp;</p>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">设置完成后生成工程</span></span></p>

<pre>
<code>int main(void)
{

//HAL_Init();
//SystemClock_Config();
//MX_GPIO_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
        LED_Thread = rt_thread_create("LED",                                /* 线程名字 */
                                                        LED_Thread_Entry,                        /* 线程入口函数 */
                                                        RT_NULL,                                                /* 线程入口函数参数 */
                                                        512,                                                        /* 线程栈大小 */
                                                        3,                                                        /* 线程的优先级 */
                                                        20);                                                        /* 线程时间片 */
               
        if(LED_Thread != RT_NULL)
        {
                        rt_thread_startup(LED_Thread);
        }
        else
        {
                return -1;
        }
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
}

}
</code></pre>

<p >&nbsp;</p>

<pre>
<code>static void LED_Thread_Entry(void *parameter)
{
        while(1)
        {
               HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_13|GPIO_PIN_5, GPIO_PIN_RESET);
                //HW_Led1_On();
                rt_thread_delay(500);
       
                HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_13|GPIO_PIN_5, GPIO_PIN_SET);
                rt_thread_delay(500);

        }
}
</code></pre>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">在rt_hw_board_init函数里添加GPIO初始化函数</span></span></p>

<p >&nbsp;</p>

<pre>
<code>void rt_hw_board_init(void)
{
    extern void SystemClock_Config(void);
   
    HAL_Init();
    SystemClock_Config();
    SystemCoreClockUpdate();
                MX_GPIO_Init();
    /*
   * 1: OS Tick Configuration
   * Enable the hardware timer and call the rt_os_tick_callback function
   * periodically with the frequency RT_TICK_PER_SECOND.
   */
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/RT_TICK_PER_SECOND);
</code></pre>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">加入GPIO初始化函数</span></span></p>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">添加头文件</span></span></p>

<p >&nbsp;</p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">生成OK</span></span></p>

<p ><span style="font-size:16px;"><span style="font-family:宋体;">下载进去后,看到LED灯闪烁</span></span></p>

lugl4313820 发表于 2023-10-23 17:51

这是rtthread nano吧,用rtthread studio,不是方便一些?

常见泽1 发表于 2023-10-24 13:42

lugl4313820 发表于 2023-10-23 17:51
这是rtthread nano吧,用rtthread studio,不是方便一些?

<p>是的&nbsp; 应该会更方便</p>

<p>没用过 CUBE比较熟悉就用CUBE了</p>
页: [1]
查看完整版本: 【STM32F769-discovery开发板】第七篇 Rtthread工程CubeMX生成入门