Question
STM32L476RG-EVAL, no output to realterm using lpuart
Hello,
I have been following a tutorial which is supposed to transmit a string of characters from the board to the realterm terminal on my computer across the USB st-link, however when I run it I do not see anything in the realterm terminal
This is the code:
#include "stm32l4xx.h"
#include <stdint.h>
#define SYS_FREQ 4000000
#define APB1_CLK SYS_FREQ
#define GPIOBEN (1U<<1)// 0b 0000 0000 0000 0000 0000 0000 0000 0010
#define LPUART1EN (1U<<0)
#define CR1_TE (1U<<3)
#define CR1_UE (1U<<0)
#define ISR_TXE (1U<<7)
static uint16_t compute_lpuart_div(uint32_t PeriphClk, uint32_t Baudrate);
static void lpuart_set_baudrate(uint32_t PeriphClk, uint32_t Baudrate);
static void lpuart1_write(uint8_t ch);
void lpuart1_tx_init(void);
int main(void){
lpuart1_tx_init();
while(1){
lpuart1_write('y');
}
}
void lpuart1_tx_init(void){
//Configure the lpuart pin
//Enable clock access to GPIOB as TX line
RCC->AHB2ENR |= GPIOBEN;
//Set PB11 as alternate function mode
GPIOB->MODER &= ~(1U<<22);
GPIOB->MODER |= (1U<<23);
//Set alternate function type to lpuart
GPIOB->AFR[1] &= ~(1U<<12);
GPIOB->AFR[1] &= ~(1U<<13);
GPIOB->AFR[1] &= ~(1U<<14);
GPIOB->AFR[1] |= (1U<<15);
//Configure the lpuart module
//Enable clock access to lpuart
RCC->APB1ENR2 |= LPUART1EN;
//Configure baudrate
lpuart_set_baudrate(APB1_CLK, 115200);
//Configure transfer direction
LPUART1->CR1 = CR1_TE;
//Enable lpuart module
LPUART1->CR1 |= CR1_UE;
}
static void lpuart1_write(uint8_t ch){
while(!(LPUART1-> ISR & ISR_TXE)){}
LPUART1->TDR = (ch & 0xFF);
}
static void lpuart_set_baudrate(uint32_t PeriphClk, uint32_t Baudrate){
LPUART1->BRR = compute_lpuart_div(PeriphClk, Baudrate);
}
static uint16_t compute_lpuart_div(uint32_t PeriphClk, uint32_t Baudrate){
return ((PeriphClk + (Baudrate/2))/Baudrate);
}Are there any mistakes I am making here? I have checked the pins etc over many times and believe it to be correct.
Any help would be greatly appreciated. Thank you.
