STM32 跑RTX 程序运行初始化 os_sem_init() 程序就死机
//-------------------------------------------------------------
// 函数名称 :UARTx_Init
// 功能描述 :初始化uart,设置波特率,校验位,停止位,数据位
// 配置中断,初始化FIFO
// 入口参数1:串口号:uart_base
// 入口参数2:波特率:BaudRate
// 出口参数 :None
//-------------------------------------------------------------
void UARTx_Init(uint32 uart_base, uint32 baudrate)
{
unsigned int i;
_UARTx *UARTx = NULL;
USART_InitTypeDef USART_InitStructure;
/* USART1 configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = baudrate; //波特率: 115200
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //数据数: 8
USART_InitStructure.USART_StopBits = USART_StopBits_1; //停止位: 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; //Open RX接收和TX发送功能
#ifdef __UART0
if(uart_base == USART1_BASE)//com0
{
UARTx = &UART_0;
UARTx -> RxBuf = Rx0Buf;
for(i = 0 ; i < UART0_RxFifo ; i++)
{
UARTx -> RxBuf = UART0_END_FLAG;
}
UART1_GPIO_Configuration();
}
#endif
#ifdef __UART1
else if(uart_base==USART2_BASE)//com1
{
UARTx = &UART_1;
UARTx -> RxBuf = Rx1Buf;
for(i = 0; i < UART1_RxFifo; i++)
{
UARTx -> RxBuf = UART1_END_FLAG;
}
UART2_GPIO_Configuration();
}
#endif
#ifdef __UART2
else if(uart_base==USART3_BASE)//com2
{
UARTx = &UART_2;
UARTx -> RxBuf = Rx2Buf;
for(i = 0 ; i < UART2_RxFifo ; i++)
{
UARTx -> RxBuf = UART2_END_FLAG;
}
UART3_GPIO_Configuration();
}
#endif
if(UARTx == NULL)
return;
/*
UARTConfigSetExpClk(uart_base, SysCtlClockGet(), baudrate, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
//===============串口接收、发送中断设置==================================================================
UARTIntEnable(uart_base, UART_INT_RX | UART_INT_RT | UART_INT_TX);
UARTFIFOLevelSet(uart_base, UART_FIFO_TX1_8, UART_FIFO_RX7_8);//sets fifo level at which transmit and receive interrupts will be generated.
*/
#ifdef __UART0
if(uart_base == USART1_BASE)//com0
{
/* Configure the USART1*/
USART_Init(USART1, &USART_InitStructure);
/* Enable USART1 Receive and Transmit interrupts */
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //接收中断模式允许
/* Enable the USART1 */
USART_Cmd(USART1, ENABLE); //启动串口1
}
#endif
#ifdef __UART1
else if(uart_base==USART2_BASE)//com1
{
/* Configure the USART2*/
USART_Init(USART2, &USART_InitStructure);
/* Enable USART2 Receive and Transmit interrupts */
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //接收中断模式允许
/* Enable the USART2 */
USART_Cmd(USART2, ENABLE); //启动串口2
}
#endif
#ifdef __UART2
else if(uart_base==USART3_BASE)//com2
{
/* Configure the USART3*/
USART_Init(USART3, &USART_InitStructure);
/* Enable USART3 Receive and Transmit interrupts */
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); //接收中断模式允许
/* Enable the USART3 */
USART_Cmd(USART3, ENABLE); //启动串口2
}
#endif
UARTx -> TxPointer = NULL; //初始化串口缓冲区
UARTx -> TxNum = 0;
UARTx -> TxEmpty = TRUE;
os_sem_init(UARTx -> TxSem , 1);
os_sem_init(UARTx -> RxSem , 1);
UARTx -> RxNum = 0;
UARTx -> RxMax = 0;
UARTx -> RxOverRun = FALSE;
UARTx -> RxReadShift = 0;
UARTx -> RxWriteShift = 0;
// IntEnable(UartInt);
// UARTEnable(uart_base);//enables transmitting and receiving and enables transmit and receive FIFOs
}
程序跑到
os_sem_init(UARTx -> TxSem , 1);
os_sem_init(UARTx -> RxSem , 1); 就不动 死机
STM32 跑RTX系统 高手帮忙解决下这个问题。
|