完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
STM32F103 FreeRTOS记录
一、移植(测试RTOSled) 1.添加freertos9.相关文件。 2.在头文件添加下面代码并注释掉stm32f10x_it.c文件里的相关函数 #define vPortSVCHandler SVC_Handler #define xPortPendSVHandler PendSV_Handler #define xPortSysTickHandler SysTick_Handler 3.设置: NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); 4.代码如下: /** ****************************************************************************** * @file Project/STM32F10x_StdPeriph_Template/main.c * @author MCD Application Team * @version V3.5.0 * @date 08-April-2011 * @brief Main program body ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h" #include #include #include "FreeRTOS.h" #include "task.h" #include "delay.h" #include "sysclk.h" #include "usart.h" #include "adc.h" unsigned int spa=0,mill=0,uart_num=0,dma_recv_num=0; char RX_Buffer[50]={" "}; char RT_Buffer[50]={0}; char DM_RX_BUF[5]={0}; TaskHandle_t xLedTask1 = NULL,xLedTask2 = NULL,xCNTask=NULL,xGetStackTask=NULL; unsigned char RX_Buffer_Temp=' ',rec_flag=0,dma_receive_flag=0; unsigned char uart1_tc5_flag=0; unsigned int ssp=0,ds_count=0,adc_ds_count=0,OneMill2=0,OneMill1=0; float ADC_ConvertedValue=0; void MyGPIO_Init() { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); } void Process_Led1(void *pvParameters) { while(1) { GPIOC->ODR ^= GPIO_Pin_0; vTaskDelay(100); OneMill1++; } } void Process_Led2(void *pvParameters) { while(1) { GPIOC->ODR ^= GPIO_Pin_1; vTaskDelay(100); OneMill2++; } } void Process_Count(void *pvParameters) { while(1) { vTaskDelay(100); printf("The rtos1 is %d,rtos2 is %d",OneMill1,OneMill2); } } RCC_ClocksTypeDef RCC_Clocks; int main(void) { MyGPIO_Init(); SystemClk_Init(); Uart1_Init(); Usart1_DMA_init(); ADC1_CH4_Init(); RCC_GetClocksFreq(&RCC_Clocks); Init_NVIC(); xTaskCreate(Process_Led1, "LED_TEST1", 60, NULL, 2, &xLedTask1); xTaskCreate(Process_Led2, "LED_TEST2", 60, NULL, 2, &xLedTask2); xTaskCreate(Process_Count, "PRO_CN", 60, NULL, 2, &xCNTask); //xTaskCreate(Process_GetStack, "GET_STACK", 70, NULL, 2, &xGetStackTask); vTaskStartScheduler(); } void ADC1_2_IRQHandler(void) { if(ADC_GetITStatus(ADC1,ADC_IT_EOC)==SET) { //ADC_ClearITPendingBit(ADC1,ADC_IT_EOC); if(adc_ds_count<65500)adc_ds_count++; } } void USART1_IRQHandler(void) { unsigned char uart_info=0; uart_info=uart_info; if(USART_GetITStatus(USART1,USART_IT_IDLE) == SET) { uart_info = USART1->SR; uart_info = USART1->DR; DMA_Cmd(DMA1_Channel5,DISABLE); dma_recv_num = 200 - DMA_GetCurrDataCounter(DMA1_Channel5); DMA1_Channel5->CNDTR=200; DMA_Cmd(DMA1_Channel5,ENABLE); dma_receive_flag = 1; } } void DMA1_Channel5_IRQHandler(void) { if(DMA_GetITStatus(DMA1_IT_TC5) == SET) { DMA_ClearFlag(DMA1_IT_TC5); } } void DMA1_Channel4_IRQHandler(void) { if(DMA_GetITStatus(DMA1_IT_TC4) == SET) { DMA_ClearFlag(DMA1_IT_TC4); } } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %drn", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1683 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1582 浏览 1 评论
1013 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
703 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1627 浏览 2 评论
1892浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
675浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
538浏览 3评论
557浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
526浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-4 01:07 , Processed in 0.715490 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号