This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM625: UART with custom baudrate 1.333 MHz

Part Number: AM625
Other Parts Discussed in Thread: CLOCKTREETOOL

Tool/software:

Hi,

I was trying to set the UART baudrate to 1.333 MHz and I saw this link https://e2e.ti.com/support/processors-group/processors/f/processors-forum/895402/am3351-non-standard-uart-baud-rate/3313574?tisearch=e2e-sitesearch&keymatch=custom_divisor#3313574

and I need help on how to get the .custom_divisor for baudrate to 1.333 MHz.

Regards,

John Tobias

  • Greetings John,

    Thank you for your question.

    I am assuming you meant baud rate = 1.333 Mbps?

    So I am going to let you know a formula which is going to help you going further as well.

    So the operating frequency will be 48 MHz, and then you need to decide if you want to go ahead with the oversampling value: 16x or 13x.

    Based on the oversampling value your new divisor value can be computed. Look at the 4 possible combinations.

    So, if it is 16x then the baud rate with divisor value 2 = 1500000 and divisor value 3 = 1000000

    If it is 13x then the the baud rate with divisor value 2 = 1846153.84 and divisor value 3 = 1230769.23

    I think the one which is having oversampling value 13x and divisor value 3 should be ideal as it has less error percentage compared to all the 4 combinations.

    Regards,

    Vaibhav

  • Hi Vaibhav,

    Thanks for the response. I tried your suggestions but non of them work.
    1.333Mbps is very critical to the project and we need an expert assistance to get it right.


    I was using am625-evk and I was using UART5 for testing. So, I enabled the UART5 and below is my patch

    diff --git a/arch/arm64/boot/dts/ti/k3-am62x-sk-common.dtsi b/arch/arm64/boot/dts/ti/k3-am62x-sk-common.dtsi
    index b1980b85c..32b50b081 100644
    --- a/arch/arm64/boot/dts/ti/k3-am62x-sk-common.dtsi
    +++ b/arch/arm64/boot/dts/ti/k3-am62x-sk-common.dtsi
    @@ -15,6 +15,7 @@ aliases {
    serial0 = &mcu_uart0;
    serial1 = &wkup_uart0;
    serial2 = &main_uart0;
    + serial5 = &main_uart5;
    mmc0 = &sdhci0;
    mmc1 = &sdhci1;
    mmc2 = &sdhci2;
    @@ -186,6 +187,13 @@ AM62X_IOPAD(0x1cc, PIN_OUTPUT, 0) /* (E14/E11) UART0_TXD */
    >;
    };

    + main_uart5_pins_default: main-uart5-pins-default {
    + pinctrl-single,pins = <
    + AM62X_IOPAD(0x01d8, PIN_INPUT, 1) /* (H21) MCAN0_TX.UART5_RXD */
    + AM62X_IOPAD(0x01dc, PIN_OUTPUT, 1) /* (E15) MCAN0_RX.UART5_TXD */
    + >;
    + };
    +
    main_i2c0_pins_default: main-i2c0-pins-default {
    pinctrl-single,pins = <
    AM62X_IOPAD(0x1e0, PIN_INPUT_PULLUP, 0) /* (B16/E12) I2C0_SCL */
    @@ -348,6 +356,12 @@ &main_uart1 {
    status = "reserved";
    };

    +&main_uart5 {
    + pinctrl-names = "default";
    + pinctrl-0 = <&main_uart5_pins_default>;
    + status = "okay";
    +};
    +
    &main_i2c0 {
    status = "okay";
    pinctrl-names = "default";


    1. I saw the clocktreetool for am62x www.ti.com/.../CLOCKTREETOOL
    and found out there's a way to change the clock source of the uart. Instead of using the default 48 Mhz, I can use 127.6 Mhz.


    If I do 16x then the baud rate with divisor value 6 = 1329166.67 which is very ideal to what I need. But, I do not know how to change it. I need your expertise on this. Please help me how to configure the clock.


    2. I found out as well the UART has a clock (clock ID 2) DEV_UART5_FCLK_CLK_PARENT_HSDIV4_16FFT_MAIN_1_HSDIVOUT1_CLK that gives a clock frequency of 160000000

    So, If I do 13x then the baud rate with divisor value 9 = 1367521.37

    I changed the clock id to 2 so that the uart5 will run with 160Mhz clock.

    diff --git a/arch/arm64/boot/dts/ti/k3-am62-main.dtsi b/arch/arm64/boot/dts/ti/k3-am62-main.dtsi
    index 93d445cd8..4470fa78d 100644
    --- a/arch/arm64/boot/dts/ti/k3-am62-main.dtsi
    +++ b/arch/arm64/boot/dts/ti/k3-am62-main.dtsi
    @@ -396,7 +396,8 @@ main_uart5: serial@2850000 {
    reg = <0x00 0x02850000 0x00 0x100>;
    interrupts = <GIC_SPI 183 IRQ_TYPE_LEVEL_HIGH>;
    power-domains = <&k3_pds 156 TI_SCI_PD_EXCLUSIVE>;
    - clocks = <&k3_clks 156 0>;
    + //clocks = <&k3_clks 156 0>;
    + clocks = <&k3_clks 156 2>;
    clock-names = "fclk";
    status = "disabled";
    };

    After I power cycled the board, I verified the uart5 clock is 160Mhz.  I ran:
    cat /sys/class/tty/ttyS5/uartclk and it show: 160000000


    I used this tool: github.com/.../linux-serial-test.git for verification

    Note: We only care the UART RX but for the sake of testing, I used the TX to verify if the baud rate is correct
    and verified by logic analyzer.

    I ran the command below - just to verify if I can send data with the
    linux-serial-test -p /dev/ttyS5 -d 9 -y 0xAA -f

    Below is the screenshot of the logic analyzer and it showing error in framing.


    Could you tell me what am I missing?.

    Regards,

    John

  • I figured out how to change the clock.

  • Hi John,

    Thank you for your response.

    This thread has been assigned to the correct expert.

    Please expect responses in few business days.

    Regards,
    Vaibhav

  • Hi John,

    linux-serial-test -p /dev/ttyS5 -d 9 -y 0xAA -f

    Below is the screenshot of the logic analyzer and it showing error in framing.

    Can you please measure the bit width in the logic analyzer capture to see what is the uart baud rate?

  • Hi Bin,

    I was expecting to see the data in 1.333Mbps and I didn't see it correctly if I used your recommendattions.


    Instead of using the 48Mhz clock, I used 192Mhz clock and I was able to get the 1.333Mbps

  • Hi John,

    I think I am confused.

    Instead of using the 48Mhz clock, I used 192Mhz clock and I was able to get the 1.333Mbps

    Do you mean the issue is resolved now by using 192MHz clock?

  • Greetings John, Bin,

    I think as per the new post from John: https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1383021/am625-m4-custom-baud-rate

    This issue is resolved, so I am marking this thread resolved.

    Regards,

    Vaibhav