2024-11-17 06:50 AM - last edited on 2024-11-25 01:29 AM by STTwo-32
Hey guys,
I have NUCLEO-WL55JC2 board, and I am following a tutorial to learn baremetal embedded programming. The first task is a "hello world" app for UART.
So, I just read the doc, and I understood that I need to use LPUART1 which is the default for this board.
But, I could not get any character over COM port. Can you please help me?
#include "stm32wl55xx.h"
#define RCC_GPIOA_EN (1U<<0)
#define RCC_GPIOB_EN (1U<<1)
#define RCC_GPIOC_EN (1U<<2)
#define LPUART1_EN (1U<<0)
#define CR1_TE (1U<<3)
#define ISR_TXE (1U<<7)
//#define SYS_FREQ 48000000
//#define APB1_CLK SYS_FREQ
#define UART_BAUDRATE 9600
static void uart_set_baudrate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t Baudrate);
static uint16_t compute_uart_bd(uint32_t PeriphClk, uint32_t Baudrate);
void uart1_tx_init(void);
void uart1_write(int ch);
int main(void)
{
uart1_tx_init();
while(1)
{
uart1_write("Y");
}
for(int i=0;i<1000000;i++){}
}
void uart1_tx_init(void)
{
/***** Configure UART GPIO Pin *****/
/* Enable clock access to the proper GPIO, in this case GPIOA */
RCC->AHB2ENR |= RCC_GPIOA_EN;
/* Set PA2 mode to alternate function mode */
GPIOA->MODER |= (1U<<5);
GPIOA->MODER &=~(1U<<4);
/* Set PA2 alternate function type to LPUART_TX (AF08) */
GPIOA->AFR[0] &=~(1U<<8);
GPIOA->AFR[0] &=~(1U<<9);
GPIOA->AFR[0] &=~(1U<<10);
GPIOA->AFR[0] |= (1U<<11);
/***** Configure UART Module *****/
/* Enable clock access to LPUART1 */
RCC->APB1ENR2 |= LPUART1_EN;
/* Configure baud rate */
LPUART1->BRR = 0x369; //9600 in the doc
/* Configure the transfer direction */
LPUART1->CR1 |= CR1_TE;
/* Enable LPUART1 */
LPUART1->CR1 |= (1U<<0);
}
void uart1_write(int ch)
{
/* Make sure the transmit data reg is empty */
while(!(LPUART1->ISR & ISR_TXE)){}
/* Write to transmit data reg */
LPUART1->TDR = (ch & 0xFF);
}
2024-11-25 02:19 AM
Hello @unalf
I suggest you take a look at the configurations of this working simple project (that I've attached) and try to reproduce it to make the LPUART1 works as expected. Also, don't forget to check the position of the solder bridges (as mentioned on the UM2592).
Best Regards.
STTwo-32
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.