下载了FreeRTOS-v5.02后,解压, 由于手头没有STM32的开发板,一直在用当时ST做活动时送的那个最小系统,看过我博客的朋友应该见过一个图,只引出了串口与USB口.
这里我们要关注的目录有:
这里主要讲的是要把freertos在最小系统上跑起来,主要需处理的是串口驱动相关部分,
根据我在串口控制台的方法,把最小系统上的串口驱动起来,这里有些不同,这里发送接收都采用中断方式,驱动设置如下:
/* Configure USARTx_Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_TxPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOx, &GPIO_InitStructure);
/* Configure USARTx_Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_RxPin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOx, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = ulWantedBaud;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_Clock = USART_Clock_Disable;
USART_InitStructure.USART_CPOL = USART_CPOL_Low;
USART_InitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_InitStructure.USART_LastBit = USART_LastBit_Disable;
USART_Init( USARTx, &USART_InitStructure );
USART_ITConfig( USARTx, USART_IT_RXNE, ENABLE );
USART_Cmd( USARTx, ENABLE );
NVIC_InitStructure.NVIC_IRQChannel = USARTx_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
中断处理如下: 串口发达接收都增加一个环形缓冲队列,参照serial.c更改即可.
if( USART_GetITStatus( USARTx, USART_IT_TXE ) == SET )
{
if( xQueueReceiveFromISR( xCharsForTx, &cChar, &xHigherPriorityTaskWoken )
== pdTRUE )
USART_SendData( USARTx, cChar );
else
USART_ITConfig( USARTx, USART_IT_TXE, DISABLE );
}
if( USART_GetITStatus( USARTx, USART_IT_RXNE ) == SET )
{
cChar = USART_ReceiveData( USARTx );
xQueueSendFromISR( xRxedChars, &cChar, &xHigherPriorityTaskWoken );
}
portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
然后利用FreeRTOS提供的互斥信号量封装串口发送函数,如下:
// taskENTER_CRITICAL(); // 20080808
if(uartMutexHandle!=NULL)
{
//xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime );
//xQueueGiveMutexRecursive( xQueueHandle xMutex );
if(xQueueTakeMutexRecursive(uartMutexHandle,(portTickType)10)==pdTRUE)
{
pxNext = ( signed portCHAR * ) pcString;
while( *pxNext )
{
xSerialPutChar( pxPort, *pxNext, serNO_BLOCK );
pxNext++;
}
xQueueGiveMutexRecursive(uartMutexHandle);
}
}
// taskEXIT_CRITICAL();
初始化时创建互斥信号量: uartMutexHandle = xSemaphoreCreateMutex(); // 20080815
用户499533 2010-9-26 08:56
walnutcy_696810119 2009-10-26 21:17
用户1190910 2009-10-24 11:06
用户1397074 2009-2-20 10:51
walnutcy_696810119 2009-1-5 19:08
用户1001363 2009-1-4 22:09
walnutcy_696810119 2009-1-4 19:42
用户1001363 2009-1-4 14:22
用户1001363 2009-1-4 14:22
用户1001363 2009-1-4 14:21