GPS Device
Loading...
Searching...
No Matches
stm32f401re_usart.c File Reference

USART driver implementation for STM32F401RE. More...

#include "stm32f401re_usart.h"
#include "common.h"
#include "arm_cortex_m4_nvic.h"
#include "stm32f401re.h"
#include "stm32f401re_rcc.h"
Include dependency graph for stm32f401re_usart.c:

Go to the source code of this file.

Functions

static void usart_set_pclk (USART_REGDEF_ts const *instance, EN_STATUS_te en_status)
 Enables or disables the peripheral clock for a USART instance.
static void usart_set_baud_rate (USART_CFG_ts *usart_cfg)
 Computes and writes the BRR register for the configured baud rate.
void usart_init (USART_CFG_ts *usart_cfg)
 Initializes the USART peripheral with the given configuration.
void usart_deinit (USART_REGDEF_ts const *instance)
 Deinitializes the USART peripheral, disables its NVIC interrupt, and disables its clock.
void usart_send (USART_REGDEF_ts *instance, uint8_t *tx_buffer, uint32_t len)
 Blocking USART transmit.
void usart_receive (USART_REGDEF_ts const *instance, uint8_t *rx_buffer, uint32_t len)
 Blocking USART receive.
void usart_set_transmission (USART_REGDEF_ts *instance, EN_STATUS_te en_status)
 Enables or disables the USART transmitter.
void usart_set_reception (USART_REGDEF_ts *instance, EN_STATUS_te en_status)
 Enables or disables the USART receiver.
void usart_get_name (USART_REGDEF_ts const *instance, char *name)
 Returns the name string of a USART peripheral instance.
void USART1_IRQHandler (void)
 USART1 interrupt handler. Dispatches RXNE events to usart1_irq_data_recv_callback.
void USART2_IRQHandler (void)
 USART2 interrupt handler. Currently empty — no interrupt sources configured.
void USART6_IRQHandler (void)
 USART6 interrupt handler. Dispatches RXNE events to usart6_irq_data_recv_callback.
void usart1_irq_data_recv_callback (uint8_t data) __attribute__((weak
 Default weak implementation of usart1_irq_data_recv_callback.
void alias ("usart_irq_callback")))
void usart6_irq_data_recv_callback (uint8_t data) __attribute__((weak
 Default weak implementation of usart6_irq_data_recv_callback.
void usart_irq_callback (uint8_t data)
 Default fallback handler for unimplemented USART receive callbacks.

Detailed Description

USART driver implementation for STM32F401RE.

Author
github.com/Baksi675
Version
0.1
Date
2025-09-04

Definition in file stm32f401re_usart.c.

Function Documentation

◆ USART1_IRQHandler()

void USART1_IRQHandler ( void )

USART1 interrupt handler. Dispatches RXNE events to usart1_irq_data_recv_callback.

Checks the RXNE flag and reads USART_DR to clear it, then passes the received byte to the application callback. Only RXNE is handled; other interrupt sources are not checked.

Definition at line 259 of file stm32f401re_usart.c.

259 {
260 if((USART1->USART_SR >> USART_SR_RXNE) & 0x1) {
261 uint8_t data = USART1->USART_DR;
263 }
264}
void usart1_irq_data_recv_callback(uint8_t data) __attribute__((weak
Default weak implementation of usart1_irq_data_recv_callback.
#define USART1
@ USART_SR_RXNE
Here is the call graph for this function:

◆ USART2_IRQHandler()

void USART2_IRQHandler ( void )

USART2 interrupt handler. Currently empty — no interrupt sources configured.

Definition at line 269 of file stm32f401re_usart.c.

269 {
270}

◆ USART6_IRQHandler()

void USART6_IRQHandler ( void )

USART6 interrupt handler. Dispatches RXNE events to usart6_irq_data_recv_callback.

Checks the RXNE flag and reads USART_DR to clear it, then passes the received byte to the application callback.

Definition at line 279 of file stm32f401re_usart.c.

279 {
280 if((USART6->USART_SR >> USART_SR_RXNE) & 0x1) {
281 uint8_t data = USART6->USART_DR;
283 }
284}
void usart6_irq_data_recv_callback(uint8_t data) __attribute__((weak
Default weak implementation of usart6_irq_data_recv_callback.
#define USART6
Here is the call graph for this function:

◆ usart_irq_callback()

void usart_irq_callback ( uint8_t data)

Default fallback handler for unimplemented USART receive callbacks.

Spins forever. Serves as the weak alias target for both usart1_irq_data_recv_callback and usart6_irq_data_recv_callback when no application override is provided.

Definition at line 312 of file stm32f401re_usart.c.

312 {
313 while(1);
314}