Skip to main content
yjae
Associate II
August 24, 2018
Solved

Can you tell me how to set up serial port in keil?

  • August 24, 2018
  • 27 replies
  • 5044 views

I'm a beginner. I'd appreciate your help.

This topic has been closed for replies.
Best answer by Tesla DeLorean

The L073RZ is capable of using DMA for USART4, the VCOM.C is not illustrative of this, but there might be examples under the HAL trees.

STM32Cube_FW_L0_V1.10.0\Projects\STM32L073RZ-Nucleo\Examples\UART\UART_TwoBoards_ComDMA

27 replies

LMI2
Senior III
August 24, 2018

Keil is an IDE, it does not really matter. It is like any other project. I recommend using STM32CubeMX tool which you can download for free.

https://www.st.com/en/development-tools/stm32cubemx.html

With it comes several examples and the tool can create a basic project for you.

yjae
yjaeAuthor
Associate II
August 24, 2018

I have Cubemx. Can you tell me how to specify serial port with Cubemx?

LMI2
Senior III
August 24, 2018

Just play with the Cube, you will see. It is not hard.

Tesla DeLorean
Guru
August 24, 2018

Which serial port on what pins?

You might be better looking at the existing vcom.c code, or the USART/UART examples under the HAL trees for the NUCLEO board.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
yjae
yjaeAuthor
Associate II
August 25, 2018

In the example of p-nucleo-lrwan1 pingpong, I want to add code and set it to UART4 rx, tx . Please help me.

yjae
yjaeAuthor
Associate II
August 25, 2018

I want to set USART4 on pc10, pc11.

Tesla DeLorean
Guru
August 25, 2018
void USART4_Init(void)
{
 static UART_HandleTypeDef UartHandle;
 GPIO_InitTypeDef GPIO_InitStruct;
 
 __USART4_CLK_ENABLE();
 __GPIOC_CLK_ENABLE()
 
 /* UART TX/RX GPIO pin configuration */
 GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_PULLUP;
 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF6_USART4;
 
 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
 /*## Configure the UART peripheral ######################################*/
 /* Put the USART peripheral in the Asynchronous mode (UART Mode) */
 /* USART4 configured as follow:
 - Word Length = 8 Bits
 - Stop Bit = One Stop bit
 - Parity = No parity
 - BaudRate = 9600 baud
 - Hardware flow control disabled (RTS and CTS signals) */
 
 UartHandle.Instance = USART4;
 
 UartHandle.Init.BaudRate = 9600;
 UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
 UartHandle.Init.StopBits = UART_STOPBITS_1;
 UartHandle.Init.Parity = UART_PARITY_NONE;
 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 UartHandle.Init.Mode = UART_MODE_TX_RX;
 
 if (HAL_UART_Init(&UartHandle) != HAL_OK)
 {
 /* Initialization Error */
 Error_Handler();
 }
 
// If you use interrupts
// HAL_NVIC_SetPriority(USART4_IRQn, 0x1, 0);
// HAL_NVIC_EnableIRQ(USART4_IRQn);
}

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
yjae
yjaeAuthor
Associate II
August 26, 2018

Thank you, but I'd like to use Interrupt but it says 'USART4_IRQn' is not defined. you help me?

Tesla DeLorean
Guru
August 26, 2018

L073RZ shares USART4 and 5 interrupts

HAL_NVIC_SetPriority(USART4_5_IRQn, 0x1, 0);

HAL_NVIC_EnableIRQ(USART4_5_IRQn);

..

void USART4_5_IRQHandler(void)

{

..

}

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
yjae
yjaeAuthor
Associate II
August 27, 2018

'.\sx1272mb2das\NUCLEO_CUBE_LORA.axf: Error: L6218E: Undefined symbol __HAL_RCC_UART4_CLK_ENABLE '

I didn't define 'HAL_RCC_UART4_CLK_ENABLE' but the same error appears above.What's the problem?