cancel
Showing results for 
Search instead for 
Did you mean: 

Newbie Question (Nucleo-144+STM32L496zg) : LPUART shows no signs of life

RMand
Senior

I have tried with and without the Cube generated code but no luck getting LPUART to send any printable characters/bytes to an external TeraTerm terminal over VCOM.

I think I am missing some clocking or initialization step -- any help is appreciated.

Cheers

Ramanand

// ########################

int main(void)

{

HAL_Init();

SystemClock_Config();

MX_GPIO_Init();

MX_LPUART1_UART_Init();

}

   return;

 }

3 REPLIES 3
RMand
Senior

The webpage would not let me add all my code -- is there a mechanism to attach code snippets to this thread?

Ok, so you can edit posts, and you can add code with the </> icon, and also as attachments.

If the pins are on Port G, you need to enable the VDDIO

0690X00000ARTPGQA5.jpg

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
NUCLEO-L496ZG  sourcer32@gmail.com
 
/* ## Definition of UARTx related resources ################################### */
/* Definition of UARTx */
#define UARTx                            LPUART1
 
/* Definition of UARTx clock resources */
#define UARTx_CLK_ENABLE()               __HAL_RCC_LPUART1_CLK_ENABLE()
#define UARTx_TX_PIN_CLK_ENABLE()        __HAL_RCC_GPIOG_CLK_ENABLE()
#define UARTx_RX_PIN_CLK_ENABLE()        __HAL_RCC_GPIOG_CLK_ENABLE()
 
/* Definition of UARTx channels pins */
#define UARTx_TX_PIN                     GPIO_PIN_7
#define UARTx_TX_GPIO_PORT               GPIOG
#define UARTx_TX_AF                      GPIO_AF8_LPUART1
 
#define UARTx_RX_PIN                     GPIO_PIN_8
#define UARTx_RX_GPIO_PORT               GPIOG
#define UARTx_RX_AF                      GPIO_AF8_LPUART1
 
 
/**
* @brief UART MSP Init
* @param huart: uart handle
* @retval None
*/
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
  GPIO_InitTypeDef  GPIO_InitStruct;
 
    /* Enable UARTx GPIO TX/RX clock */
    UARTx_TX_PIN_CLK_ENABLE();
    UARTx_RX_PIN_CLK_ENABLE();
 
    /* Enable UARTx clock */
    UARTx_CLK_ENABLE();
 
    /* IOSV bit MUST be set to access GPIO port G[2:15] */
    __HAL_RCC_PWR_CLK_ENABLE();
    HAL_PWREx_EnableVddIO2();
 
    /* Configure UARTx Rx and Tx as alternate function  */
    GPIO_InitStruct.Pin = UARTx_TX_PIN;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
    GPIO_InitStruct.Alternate = UARTx_TX_AF;
    HAL_GPIO_Init(UARTx_TX_GPIO_PORT, &GPIO_InitStruct);
 
    GPIO_InitStruct.Pin = UARTx_RX_PIN;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
    GPIO_InitStruct.Alternate = UARTx_RX_AF;
    HAL_GPIO_Init(UARTx_RX_GPIO_PORT, &GPIO_InitStruct);
}
 
 
/* UART handler declaration */
UART_HandleTypeDef     UartHandle;
 
#ifdef __GNUC__
  /* With GCC, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
 
 
/**
  * @brief  UART Configuration
  * @param  None
  * @retval None
  */
  /*
        - BaudRate = 115200 baud
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Tx and Rx enabled
 */
static void UART_Config(void)
{
  UartHandle.Instance = UARTx;
  UartHandle.Init.BaudRate = 115200;
  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;
  UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
  UartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
 
  if(HAL_UART_Init(&UartHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
}
 
/**
  * @brief  Retargets the C library printf function to the UART.
  * @param  None
  * @retval None
  */
PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
  HAL_UART_Transmit(&UartHandle, (uint8_t *)&ch, 1, 0xFFFF);
 
  return ch;
}

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