本帖最后由 MCUJunior 于 2011-7-29 11:46 编辑
环境: IAR v5.4
仿真器: USB HJTAG普及版
芯片: STM32F103R8T6
库函数:STM32 v1.0版
底层OS:ucos v2.52
问题描述:如果crc查表数组使用const定义,就进入不了串口2的接收中断,如果是不加const修饰,就没有问题,之前也出过类似问题,如果某个芯片的定义数据数组定义成const型,进不了串口中断。
串口初始化代码:
/*原生串口2,用于接收上位机的命令*/
/* Configure USART2 Tx (PA.02) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART2 Rx (PA.03) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//9600波特率,8位数据位,1位停止位,没有奇偶校验
USART_InitStructure.USART_BaudRate = 9600;
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(USART2, &USART_InitStructure);
/* Enable the USART2 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//只配置接收中断
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_Cmd(USART2, ENABLE);
NVIC相关配置:
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
/* Configure zero bit for preemption priority */
/*全部4位都用来指定响应优先级*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
ISR程序:
void USART2_IRQHandler(void)
{
OS_CPU_SR cpu_sr = 0;
u8 Rdata = 0;
OS_ENTER_CRITICAL(); /* Tell uC/OS-II that we are starting an ISR */
OSIntNesting++;
OS_EXIT_CRITICAL();
/*清除中断*/
if(USART_GetFlagStatus(USART2,USART_IT_RXNE)==SET)
{
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
Rdata = USART_ReceiveData(USART2);
RingBufWriteOne(&SerialFIFO, Rdata);
OSSemPost(Sem_SerialData);
}
OSIntExit(); /* Tell uC/OS-II that we are leaving the ISR */
}
CRC查找表数组
//const
unsigned short crc16_table[256] = 。。。。
很不理解数组定义到flash中,对STM32串口会有什么影响? |