19#define UART_BASE 0x400E0800
20#define UART_PERIPH_TPR_ADDR (UART_BASE + 0x108)
21#define UART_PERIPH_TCR_ADDR (UART_BASE + 0x10C)
22#define UART_PERIPH_TNPR_ADDR (UART_BASE + 0x118)
23#define UART_PERIPH_TNCR_ADDR (UART_BASE + 0x11C)
24#define UART_PERIPH_PTCR_ADDR (UART_BASE + 0x120)
25#define UART_PERIPH_PTSR_ADDR (UART_BASE + 0x124)
26#define UART_SR (UART_BASE + 0x0014)
44 uint8_t backup_buffer[294];
69 *p_UART_PTCR |=
TXTEN;
96 void send(T* buffer,
int size){
100 *(
volatile uint32_t*)p_UART_TPR = (uint32_t)buffer;
104 memcpy(backup_buffer, buffer, size);
105 enableUARTInterrupt();
121 template <
typename T>
126 }
else if (*p_UART_TNCR==0){
127 *(
volatile uint32_t*)p_UART_TNPR = (uint32_t)buffer;
131 else if (!(*p_UART_SR &
TXBUFE)&&(*p_UART_TNCR!=1)){
132 while(*p_UART_TNCR!=0){
135 *(
volatile uint32_t*)p_UART_TNPR = (uint32_t)buffer;
146 return (*p_UART_PTSR & (1<<8));
151 NVIC_EnableIRQ(UART_IRQn);
153 UART->UART_IER = UART_IER_TXBUFE;
154 UART->UART_IDR = ~UART_IER_TXBUFE;
158 send(backup_buffer,
sizeof(backup_buffer));
159 NVIC_DisableIRQ(UART_IRQn);
#define UART_PERIPH_TPR_ADDR
#define UART_PERIPH_TNPR_ADDR
#define UART_PERIPH_TNCR_ADDR
#define UART_PERIPH_PTCR_ADDR
#define UART_PERIPH_TCR_ADDR
#define UART_PERIPH_PTSR_ADDR
volatile uint32_t *const p_UART_TNCR
volatile uint32_t *const p_UART_TNPR
void init()
Turns on PDC, waits until ready. Must be called AFTER Serial.begin() in setup().
void send(T *buffer, int size)
Adds data to the PDC buffer to be sent out through UART.
bool is_on()
Checks if the PDC and UART are on.
PDC()
Default constructor for the PDC class. Initializes all relevant register pointers.
volatile uint32_t *const p_UART_TCR
volatile uint32_t *const p_UART_PTCR
volatile uint32_t *const p_UART_PTSR
volatile uint32_t *const p_UART_SR
void enableUARTInterrupt()
void send_next(T *buffer, int size)
Adds data to the backup PDC buffer. Identical to send().
volatile uint32_t *const p_UART_TPR