cancel
Showing results for 
Search instead for 
Did you mean: 

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

yjae
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

27 REPLIES 27
LMI2
Lead

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
Associate II

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

LMI2
Lead

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

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
Up vote any posts that you find helpful, it shows what's working..
yjae
Associate II

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

yjae
Associate II

I want to set USART4 on pc10, pc11.

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
Up vote any posts that you find helpful, it shows what's working..
yjae
Associate II

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

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
Up vote any posts that you find helpful, it shows what's working..