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****/
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****/
举报