Verdin IMX8M mini on Yavia carrier board
We modified the Linux device tree to give the M4 access to UART2 and 3. I am able to access and configure UART2 and able to transmit bytes on the expected pins. However, I am configuring the UART for a baud rate of 57600 but watching the signal with a logic analyzer, the interface is running at a lower baud rate of about 17265.
The code that does the UART initialization is:
#define UART_CLK_FREQ
CLOCK_GetPllFreq(kCLOCK_SystemPll1Ctrl) /
(CLOCK_GetRootPreDivider(kCLOCK_RootUart2)) /
(CLOCK_GetRootPostDivider(kCLOCK_RootUart2)) / 10
void uart_init(void)
{
uart_config_t config;
UART_GetDefaultConfig(&config);
/* adjust the configuration values */
config.baudRate_Bps = 57600;
config.parityMode = kUART_ParityDisabled;
config.dataBitsCount = kUART_EightDataBits;
config.stopBitCount = kUART_OneStopBit;
config.txFifoWatermark = 1;
config.rxFifoWatermark = 1;
config.enableAutoBaudRate = false;
config.enableTx = true;
config.enableRx = true;
config.enableRxRTS = false;
config.enableTxCTS = false;
assert(kStatus_Success == UART_Init(UART2, &config, UART_CLK_FREQ));
}
To transmit a byte, I call
void
uart_tx_byte(uint8_t byte)
{
/* wait for the UART to become ready */
while (0U == (UART2->USR1 & UART_USR1_TRDY_MASK))
{
;
}
UART_WriteByte(UART2, byte);
}
I see the right byte values on the logic analyzer, just at the wrong baud rate. I suspect that the clock frequency being passed to the UART_Init function is not correct, but I’m not sure what the right value to use would be. I used the same macro that the examples use to configure M4 debug UART, except changing UART4 to UART2