Skip to content

Instantly share code, notes, and snippets.

@agrif
Created September 19, 2024 22:48
Show Gist options
  • Save agrif/29802f19ad76733817a7c0463c410d2c to your computer and use it in GitHub Desktop.
Save agrif/29802f19ad76733817a7c0463c410d2c to your computer and use it in GitHub Desktop.
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdio.h>
extern void busy_loop(void);
extern volatile uint32_t LEDS;
extern volatile struct {
struct {
bool tx_ready : 1;
} control;
uint32_t input;
uint32_t output;
} UART;
void uart_send(const char* s) {
for (size_t i = 0; s[i]; i++) {
while (!UART.control.tx_ready);
UART.output = s[i];
}
}
void main(void) {
uint8_t n = 0;
char message[64];
while (1) {
snprintf(message, sizeof(message), "Hello, uart %i!\r\n", n++ % 100);
uart_send(message);
busy_loop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment