Skip to content

Commit

Permalink
Use APB Clock for HART UART
Browse files Browse the repository at this point in the history
Use of APB clock instead of ERFO prevents case of interrupts not working
when system/peripheral clock is slower than UART clock.
  • Loading branch information
jdk-maxim committed Oct 2, 2024
1 parent b9c44e4 commit c574d47
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Libraries/PeriphDrivers/Source/AFE/hart_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ static int hart_uart_init(mxc_uart_regs_t *uart, unsigned int baud, mxc_uart_clo
}

// Set RX threshold to 1 byte
// Note, to meet HART TPDLL needs, each received byte must be handled singularly, to verify
// it for (vertical: parity bit) parity, framing errors, and gap error.
// This HART UART driver currently checks parity, and framing errors, but gap must be
// handled by TPDLL or application code.
//
// To increase threshold would require restructuring of the receiver to monitor gaps
// and to parse when and if comm errors occur, as there could be multiple bytes in
// the FIFO, and the errors would only apply to the most recent.
retval = MXC_UART_SetRXThreshold(uart, 1);
if (retval != E_NO_ERROR) {
return retval;
Expand Down Expand Up @@ -934,7 +942,12 @@ int hart_uart_setup(uint32_t test_mode)
} else {
hart_rts_receive_mode();

retval = hart_uart_init(HART_UART_INSTANCE, 1200, MXC_UART_ERFO_CLK);
//
// NOTE: Need to use APB clock here instead of ERFO.
// Otherwise in a case for ERFO clock is faster than the System/Peripheral
// clock UART interrupts will not or only partially work.
//
retval = hart_uart_init(HART_UART_INSTANCE, 1200, MXC_UART_APB_CLK);
if (retval != E_NO_ERROR) {
return E_COMM_ERR;
}
Expand Down

0 comments on commit c574d47

Please sign in to comment.