2018-01-11 09:09 PM
I'm using a stm32f401re-nucleo board and I build a project on ubuntu through arm-none-eabi-gcc compiler.
Here is my code for uart.
This code initializes uart.
void UartInit(void) {
hUart2.Instance = USARTx;
hUart2.Init.BaudRate = 115200;
hUart2.Init.WordLength = UART_WORDLENGTH_8B;
hUart2.Init.StopBits = UART_STOPBITS_1;
hUart2.Init.Parity = UART_PARITY_NONE;
hUart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
hUart2.Init.Mode = UART_MODE_TX_RX;
hUart2.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&hUart2);
setvbuf(stdout, NULL, _IONBF, 0);
}
�?�?�?�?�?�?�?�?�?�?
void HAL_UART_MspInit(UART_HandleTypeDef* huart) {
(void)huart;
GPIO_InitTypeDef GPIO_InitStruct;
USARTx_TX_GPIO_CLK_ENABLE();
USARTx_RX_GPIO_CLK_ENABLE();
USARTx_CLK_ENABLE();
GPIO_InitStruct.Pin = USARTx_TX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
GPIO_InitStruct.Alternate = USARTx_TX_AF;
HAL_GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStruct);
GPIO_InitStruct.Pin = USARTx_RX_PIN;
GPIO_InitStruct.Alternate = USARTx_RX_AF;
HAL_GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStruct);
HAL_NVIC_SetPriority(USARTx_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(USARTx_IRQn);
}
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) {
(void)huart;
USARTx_FORCE_RESET();
USARTx_RELEASE_RESET();
HAL_GPIO_DeInit(USARTx_TX_GPIO_PORT, USARTx_TX_PIN);
HAL_GPIO_DeInit(USARTx_RX_GPIO_PORT, USARTx_RX_PIN);
HAL_NVIC_DisableIRQ(USARTx_IRQn);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
This code is for retargetting printf.
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#define GETCHAR_PROTOTYPE int __io_getchar(void)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#define GETCHAR_PROTOTYPE int fgetc(FILE* f)
#endif
PUTCHAR_PROTOTYPE {
HAL_UART_Transmit(&hUart2, (uint8_t*)&ch, 1, 0xffff);
return ch;
}
GETCHAR_PROTOTYPE {
int ch;
HAL_UART_Receive(&hUart2, (uint8_t*)&ch, 1, 0xffff);
return ch;
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
This code is for interrupt handler.
void USARTx_IRQHandler(void)
{
HAL_UART_IRQHandler(&hUart2);
}
�?�?�?�?
Now, I can use puts, putchar, printf, getchar, HAL_UART_Transmit. However I can't use gets, HAL_UART_Transmit_IT.
But, I build a same code on IAR compiler, it works well except gets.
Only on gcc, after call a HAL_UART_Transmit_IT function, my board has stucked.
How can I use these two function gets, HAL_UART_Transmit_IT on gcc.
Help me, plz.
#uart #arm-none-eabi-gcc #stm32f401re #nucleo