Skip to content

Instantly share code, notes, and snippets.

@fenske
Created December 9, 2022 21:53
Show Gist options
  • Select an option

  • Save fenske/11ee381fb8eee406632450e667b6c020 to your computer and use it in GitHub Desktop.

Select an option

Save fenske/11ee381fb8eee406632450e667b6c020 to your computer and use it in GitHub Desktop.
This routine first waits until the TDR register is ready to accept new data, and then sends a chunk of data from the buffer to the TDR register. The chunk size is determined by the remaining length of the data buffer and the size of the TDR register. The routine continues sending chunks of data until all of the data in the buffer has been transm…
void uart_transmit(const uint8_t* data, size_t length) {
size_t i = 0;
while (i < length) {
// Wait until TDR is ready to accept new data
while ((*(volatile uint32_t*)(0xFC000000 + 0x8) & (1 << 23)) == 0);
// Send a chunk of data from the buffer
size_t chunk_size = MIN(length - i, 4);
*(volatile uint32_t*)(0xFC000000 + 0x14) = *(const uint32_t*)(data + i);
i += chunk_size;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment