Use USART2

This commit is contained in:
Alexander Heldt
2025-01-01 12:33:52 +01:00
parent 95455a7161
commit 55ee09eab8
6 changed files with 737 additions and 527 deletions

View File

@@ -2252,6 +2252,56 @@ struct timer {
void tim4_init(void);
void tim4_start(void);
# 9 "src/main.c" 2
# 1 "src/usart.h" 1
#define USART_H_
struct usart {
volatile uint32_t SR;
volatile uint32_t DR;
volatile uint32_t BRR;
volatile uint32_t CR1;
volatile uint32_t CR2;
volatile uint32_t CR3;
volatile uint32_t GTPR;
};
#define USART2_BASE_ADDR (0x40004400U)
#define USART2 ((struct usart *) USART2_BASE_ADDR)
#define USART_SR_TC_BIT 6
#define USART_SR_TC_COMPLETED (1 << USART_SR_TC_BIT)
#define USART_CR1_UE_BIT 13
#define USART_CR1_UE_ENABLE (1 << USART_CR1_UE_BIT)
#define USART_CR1_TE_BIT 3
#define USART_CR1_TE_ENABLE (1 << USART_CR1_TE_BIT)
#define USART_CR1_RE_BIT 2
#define USART_CR1_RE_ENABLE (1 << USART_CR1_RE_BIT)
#define USART_BRR_MANTISSA_BIT 4
#define USART_BRR_MANTISSA_MASK (0b111111111111)
#define USART_BRR_FRACTION_BIT 0
#define USART_BRR_FRACTION_MASK (0b111)
void usart2_init(void);
void usart2_start(void);
void usart2_write_byte(uint8_t byte);
void usart2_write(char *buf);
# 10 "src/main.c" 2
#define exit 42
@@ -2321,8 +2371,10 @@ static void system_clock_init(void) {
int main(void) {
(void) system_clock_init();
(void) tim4_init();
(void) usart2_init();
(void) tim4_start();
(void) usart2_start();
uint16_t led = (((('C') - 'A') << 8) | 13);
((struct rcc *) (0x40023800U))->AHB1ENR |= (1 << (led >> 8));
@@ -2330,19 +2382,21 @@ int main(void) {
uint16_t counter = ((struct timer *) (0x40000800U))->CNT;
# 86 "src/main.c" 3 4
# 89 "src/main.c" 3 4
_Bool
# 86 "src/main.c"
# 89 "src/main.c"
led_on =
# 86 "src/main.c" 3 4
# 89 "src/main.c" 3 4
((_Bool)+0u)
# 86 "src/main.c"
# 89 "src/main.c"
;
while(1) {
if ((((struct timer *) (0x40000800U))->CNT - counter) >= 250) {
led_on = !led_on;
gpio_write(led, led_on);
usart2_write("hello, world!\n");
counter = ((struct timer *) (0x40000800U))->CNT;
}
};