Not getting expected baud rate on UART with M4

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

After posting this and seeing that the clock frequency being calculated at run time was 80 MHz, and seeing the baud rate was about 1/3 of the expected value, I tried hard coding the clock frequency to 24 Mhz and now I’m getting the expected baud rate. Not sure if the clock frequency will always be 24 MHz, or if there is an alternative way I should be calculating the baud rate.

Hey @pfvogel,

This type of question I believe would be better suited for the NXP community boards [ community.nxp.com] . Poking around there I see a few related questions.

You’ll also find some information via the IMX8M mini Applications Processor Reference Manual.
quick link here You’'ll have to make an NXP account and agree to some terms, but it should be ~ instant.

-Eric