AnsweredAssumed Answered

STM32L476 USART 3

Question asked by shingadaddy on Mar 15, 2016
Latest reply on Mar 16, 2016 by shingadaddy

New to ST micros but I speak uC for many years. I have 2 nuleo-476RG boards. I have been successful at using the UART to UART (IT) EXAMPLE PROGRAM from ST to connect the boards via UART 1. I then transitioned this to IrDA. Enabled Endec block and set presecaler. THAT WORKS FINE. Wanted to add USART 3. That entailed changing "Uart_Handle" stuff to "Uart_1_Handle" stuff and adding "Uart_3_Handler" stuff. I am testing this with a simple toggling of the TX pin by enabling and disabling the USART with the TE bit.

A simple :
BSP_LED_On(LED2);
Uart_3_Handle.Instance->CR1 |=  USART_CR1_TE;
HAL_Delay(1000);

BSP_LED_Off(LED2);
Uart_3_Handle.Instance->CR1 &=  ~USART_CR1_TE;
HAL_Delay(1000);

Yes the LED blinks but pin 24 only goesa HIGH and sits there. I have confirmed this works with the same
toggle trick on USART 1

I'd appreciate any pointers - even pointing and giggling would be okay as long as you help me out here!

CODE
Top of main:
/* UART handler declaration */
UART_HandleTypeDef Uart_1_Handle;
UART_HandleTypeDef Uart_3_Handle;

Body of main:
Uart_1_Handle.Instance        = USARTx;

  Uart_1_Handle.Init.BaudRate   = 9600;
  Uart_1_Handle.Init.WordLength = UART_WORDLENGTH_8B;
  Uart_1_Handle.Init.StopBits   = UART_STOPBITS_1;
  Uart_1_Handle.Init.Parity     = UART_PARITY_NONE;
  Uart_1_Handle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;
//  UartHandle.Init.Mode       = UART_MODE_TX_RX;
  if(HAL_UART_DeInit(&Uart_1_Handle) != HAL_OK)
  {
    Error_Handler(1);
  } 
  if(HAL_UART_Init(&Uart_1_Handle) != HAL_OK)
  {
    Error_Handler(2);
  }
  /***** IrDA RELATED SETTINGS ******/
  Uart_1_Handle.Instance->CR1 &=  ~USART_CR1_UE;
  Uart_1_Handle.Instance->CR3 |=  USART_CR3_IREN;
  Uart_1_Handle.Instance->GTPR |=  0x00000001;
  Uart_1_Handle.Instance->CR1 |=  USART_CR1_UE;
  /**********************************/

  /********************** SECOND UART  -- UART 3 *************************/

  Uart_3_Handle.Instance        = USART3;

  Uart_3_Handle.Init.BaudRate   = 9600;
  Uart_3_Handle.Init.WordLength = UART_WORDLENGTH_8B;
  Uart_3_Handle.Init.StopBits   = UART_STOPBITS_1;
  Uart_3_Handle.Init.Parity     = UART_PARITY_NONE;
  Uart_3_Handle.Init.HwFlowCtl  = UART_HWCONTROL_NONE;
//  UartHandle.Init.Mode       = UART_MODE_TX_RX;

  if(HAL_UART_DeInit(&Uart_3_Handle) != HAL_OK)
  {
    Error_Handler(1);
  }

  if(HAL_UART_Init(&Uart_3_Handle) != HAL_OK)
  {
    Error_Handler(2);
  }
 
  stm32L4xx_hal_msp.c changes
   if(huart->Instance == USART1)
    {
     /*##-1- Enable peripherals and GPIO Clocks #################################*/
     /* Enable GPIO TX/RX clock */
     USARTx_TX_GPIO_CLK_ENABLE(); // Yes - enables GPIOA clock BUT
     USARTx_RX_GPIO_CLK_ENABLE(); // REDUNDANT - enables same GPIOA clock
 
     /* Enable USARTx clock */
     USARTx_CLK_ENABLE();
 
     /*##-2- Configure peripheral GPIO ##########################################*/
 
     /* UART TX GPIO pin configuration  */
     GPIO_InitStruct.Pin       = USARTx_TX_PIN;
     GPIO_InitStruct.Mode      = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Pull      = GPIO_PULLUP;
     GPIO_InitStruct.Speed     = GPIO_SPEED_FREQ_VERY_HIGH;
     GPIO_InitStruct.Alternate = USARTx_TX_AF;
 
     HAL_GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStruct);
 
     /* UART RX GPIO pin configuration  */
     GPIO_InitStruct.Pin = USARTx_RX_PIN;
     GPIO_InitStruct.Alternate = USARTx_RX_AF;
 
     HAL_GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStruct);
 
     /*##-3- Configure the NVIC for UART ########################################*/
     /* NVIC for USART */
     HAL_NVIC_SetPriority(USARTx_IRQn, 0, 1);
     HAL_NVIC_EnableIRQ(USARTx_IRQn);
    }
 
   
  /******************************* SECOND UART -- UART 3 -- ***************************/
 
    if(huart->Instance == USART3)
    {
     USART3_RX_GPIO_CLK_ENABLE();
     USART3_TX_GPIO_CLK_ENABLE();
 
     USART3_CLK_ENABLE();
 
     /* UART TX GPIO pin configuration  */
     GPIO_InitStruct.Pin       = USART3_TX_PIN;
     GPIO_InitStruct.Mode      = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Pull      = GPIO_PULLUP;
     GPIO_InitStruct.Speed     = GPIO_SPEED_FREQ_VERY_HIGH;
     GPIO_InitStruct.Alternate = USART3_TX_AF;
 
     HAL_GPIO_Init(USART3_TX_GPIO_PORT, &GPIO_InitStruct);
 
     /* UART RX GPIO pin configuration  */
     GPIO_InitStruct.Pin = USART3_RX_PIN;
     GPIO_InitStruct.Alternate = USART3_RX_AF;
 
     HAL_GPIO_Init(USART3_RX_GPIO_PORT, &GPIO_InitStruct);
 
     /*##-3- Configure the NVIC for UART ########################################*/
     /* NVIC for USART */
     HAL_NVIC_SetPriority(USART3_IRQn, 0, 1);
   HAL_NVIC_EnableIRQ(USART3_IRQn);
  

MAIN.H
#define USARTx                           USART1

#define USARTx_CLK_ENABLE()              __HAL_RCC_USART1_CLK_ENABLE()
#define USARTx_RX_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOA_CLK_ENABLE()
#define USARTx_TX_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOA_CLK_ENABLE()

#define USARTx_FORCE_RESET()             __HAL_RCC_USART1_FORCE_RESET()
#define USARTx_RELEASE_RESET()           __HAL_RCC_USART1_RELEASE_RESET()

/* Definition for USARTx Pins */
#define USARTx_TX_PIN                    GPIO_PIN_9
#define USARTx_TX_GPIO_PORT              GPIOA
#define USARTx_TX_AF                     GPIO_AF7_USART1
#define USARTx_RX_PIN                    GPIO_PIN_10
#define USARTx_RX_GPIO_PORT              GPIOA
#define USARTx_RX_AF                     GPIO_AF7_USART1

/* Definition for USARTx's NVIC */
#define USARTx_IRQn                      USART1_IRQn
#define USARTx_IRQHandler                USART1_IRQHandler

/*************************** -- SECOND UART -- UART 3 -- **********************/

#define USART3_CLK_ENABLE()              __HAL_RCC_USART3_CLK_ENABLE()

#define USART3_RX_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOC_CLK_ENABLE()
#define USART3_TX_GPIO_CLK_ENABLE()      __HAL_RCC_GPIOC_CLK_ENABLE()

#define USART3_FORCE_RESET()             __HAL_RCC_USART3_FORCE_RESET()
#define USART3_RELEASE_RESET()           __HAL_RCC_USART3_RELEASE_RESET()

/* Definition for USART3 Pins */
#define USART3_TX_PIN                    GPIO_PIN_4
#define USART3_TX_GPIO_PORT              GPIOC
#define USART3_TX_AF                     GPIO_AF7_USART3
#define USART3_RX_PIN                    GPIO_PIN_5
#define USART3_RX_GPIO_PORT              GPIOC
#define USART3_RX_AF                     GPIO_AF7_USART3

/* Definition for USART3's NVIC */
//#define USART3_IRQn                      USART3_IRQn
//#define USART3_IRQHandler                USART3_IRQHandler

Outcomes