TX works and prints info in console (I use Putty) but when I send on STM and echo I don't receive anything (and when I write symbols in console they don't appear). Baud rate and other config settings are correct.
init_pa9()- Configures PA9 as UART1 TX (output) pin.init_pa10()- Configures PA10 as UART1 RX (input) pin with pull-up.init_usart1()- Initializes USART1 with 115200 baud, 8N1, enables TX and RX, and sets up RX interrupt.UART_SendChar()/UART_SendString()- Functions to transmit a single character or a string over UART.USART1_IRQHandler()- Interrupt handler for USART1; reads received data from RX and immediately sends it back (echo).main()- Initializes pins and UART, sends a welcome message, then waits in an infinite loop; all echoing happens via interrupts.
#include "stm32h7xx.h"
#include "stm32h7xx_ll_gpio.h"
#include "stm32h7xx_ll_tim.h"
#include "stm32h7xx_ll_rcc.h"
#include "stm32h7xx_ll_bus.h"
#include "stm32h7xx_ll_usart.h"
#include "stm32h7xx_hal.h"
#include "stdbool.h"
void init_pa9(void) {
//USART1_TX
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOA);
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_9, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_9, LL_GPIO_AF_7);
LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_9, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_9, LL_GPIO_PULL_NO);
LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_9, LL_GPIO_OUTPUT_PUSHPULL);
}
void init_a10(void) {
// USART1_RX
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOA);
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_10, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_10, LL_GPIO_AF_7);
LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_10, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_10, LL_GPIO_PULL_NO);
LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_10, LL_GPIO_OUTPUT_PUSHPULL);
}
void init_USART1 (){
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
LL_RCC_SetUSARTClockSource(LL_RCC_USART16_CLKSOURCE_PCLK2);
LL_USART_Disable(USART1);
LL_USART_SetDataWidth(USART1, LL_USART_DATAWIDTH_8B);
LL_USART_SetStopBitsLength(USART1, LL_USART_STOPBITS_1);
LL_USART_SetParity(USART1, LL_USART_PARITY_NONE);
LL_USART_SetTransferDirection(USART1, LL_USART_DIRECTION_TX_RX);
LL_USART_SetBaudRate(USART1, SystemCoreClock, LL_USART_PRESCALER_DIV1, LL_USART_OVERSAMPLING_16, 115200);
LL_USART_EnableIT_RXNE_RXFNE(USART1);
NVIC_EnableIRQ(USART1_IRQn);
LL_USART_Enable(USART1);
while(!LL_USART_IsActiveFlag_TEACK(USART1));
}
void UART_SendChar(char ch) {
while (!LL_USART_IsActiveFlag_TXE_TXFNF(USART1)); // <--- исправлено
LL_USART_TransmitData8(USART1, ch);
}
void UART_SendString(const char *str) {
while (*str) {
UART_SendChar(*str++);
}
}
void USART1_IRQHandler() {
if (LL_USART_IsActiveFlag_RXNE_RXFNE(USART1))
{
uint8_t rx_byte = LL_USART_ReceiveData8(USART1);
LL_USART_TransmitData8(USART1, rx_byte);
}
}
int main(void) {
init_pa9();
init_a10();
init_USART1();
UART_SendString("Hello from STM32H7!\r\n");
UART_SendString("UART TX working!\r\n");
while (1) {
}
}