реклама на сайте
подробности

 
 
> STM32, USART на прерываниях и очередях, проблемы с передачей, Портится очередь
asdus
сообщение Jan 20 2012, 14:14
Сообщение #1


Участник
*

Группа: Участник
Сообщений: 21
Регистрация: 28-04-08
Из: Раменсбург
Пользователь №: 37 126



Есть проектик, STM32F10*, FreeRTOS 7.1.0
USART реализован на прерываниях и очередях, по примеру из FreeRTOS
С приемом все хорошо, а вот при передаче через некоторое время работы "портятся" данные. Свиду - сдвигаются указатели на голову и хвост в очереди.
В данный момент пройтись отладчиком возможности нет.
Выписал код в минипрогу, ошибка повторяется. Через некоторое, рандомное время, вместо "Hello World!\n" становится, например "rlWorld!\no Wo", потом еще что-нибудь и т.д.
CODE
#include "stm32f10x.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"

static xQueueHandle USART1_TxQueue;

uint8_t USART1_PutChar( uint8_t cOutChar )
{
uint8_t xReturn;

if( xQueueSend( USART1_TxQueue, &cOutChar, 10 ) == pdPASS )
{
xReturn = pdPASS;
USART_ITConfig( USART1, USART_IT_TXE, ENABLE );
}
else
{
xReturn = pdFAIL;
}

return xReturn;
}

void USART1_PutString( const uint8_t * pcString )
{
uint8_t *pxNext;

pxNext = ( uint8_t * ) pcString;
while( *pxNext )
{
USART1_PutChar( *pxNext );
pxNext++;
}
}

void HelloWorldTask(void *pvParameters)
{
for(;;)
{
USART1_PutString("Hello World!\n");
vTaskDelay( 1000 );
}
}

void USART1_IRQHandler( void )
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
uint8_t cChar;

if( USART_GetITStatus( USART1, USART_IT_TXE ) == SET )
{
if( xQueueReceiveFromISR( USART1_TxQueue, &cChar, &xHigherPriorityTaskWoken ) == pdTRUE )
{
USART_SendData( USART1, cChar );
}
else
{
USART_ITConfig( USART1, USART_IT_TXE, DISABLE );
}
}

portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
}

int main(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;

/* Enable USART1 GPIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);

/* Enable UART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

/* Enable the USART1 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_LOWEST_INTERRUPT_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

/* Configure USART1 Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Configure USART1 Rx as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Configure USART1 parameters 115200 8n1 noHW Tx+Rx*/
USART_InitStructure.USART_BaudRate = 115200;
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_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);

/* Create TxQueue for USART1 */
USART1_TxQueue = xQueueCreate( 256, ( unsigned portBASE_TYPE ) sizeof( uint8_t ) );

USART1_PutString("Program started!\n");
USART1_PutString("================\n");

xTaskCreate(HelloWorldTask, "HelWor", configMINIMAL_STACK_SIZE, NULL, 2, NULL);

vTaskStartScheduler();

for(;;)
{
}
}


Сообщение отредактировал asdus - Jan 20 2012, 14:16


--------------------
Секс - классная штука. Как ни крути...
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 20th July 2025 - 06:18
Рейтинг@Mail.ru


Страница сгенерированна за 0.01361 секунд с 7
ELECTRONIX ©2004-2016