UART clock source

SlavaDev503
Posts: 5
Joined: Thu Apr 30, 2020 1:00 pm

UART clock source

Postby SlavaDev503 » Thu Apr 30, 2020 1:28 pm

Hello.

ESP32 communicate with host over UART0 using custom binary protocol with CRC validation.
If I use 200K baudrate, the link is ok. When I increase baud to 1M baud communication is still works, but it is very unstable, very often i get message "CRC invalid". When I sniff data exchange, I saw that sometimes ESP32 receive 0x28 instead 0x14.

Here is code for UART initialization:

Code: Select all

  
  uart_config_t uart_config = {.baud_rate = COMM_UART_BAUDRATE,
      .data_bits = UART_DATA_8_BITS,
      .parity = UART_PARITY_DISABLE,
      .stop_bits = UART_STOP_BITS_1,
      .flow_ctrl = UART_HW_FLOWCTRL_RTS,
      .rx_flow_ctrl_thresh = 100,
      .use_ref_tick = true};

  // Configure UART
  uart_param_config(COMM_UART, &uart_config);
  uart_set_pin(COMM_UART, COMM_UART_TX_PIN, COMM_UART_RX_PIN, COMM_UART_RTS_PIN, COMM_UART_CTS_PIN);
  uart_driver_install(COMM_UART, COMM_UART_DRV_RX_BUFF, 0, COMM_UART_RX_EVENT_QUEUE, &eventQueue, 0);
 
That interesting that if I change use_ref_tick to false communication work without any error.

ESP-IDF: v4.0-rc-10-g08219f3cf
power manager configuration:
pm_esp32: Frequency switching config: CPU_MAX: 80, APB_MAX: 80, APB_MIN: 80, Light sleep: DISABLED

What the difference beetween UART clocking from REF_TICK and APB?
I need to use dynamic frequence changing so I should use REF_TICK as clock source, but UART doesn`t properly work with 1M baud and REF_TICK source. What I need to do for make it works?

Hope for help. Thanks in advance!

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: UART clock source

Postby WiFive » Fri May 01, 2020 9:00 am

You may need a minimum peripheral clock of 2x baudrate for reliable operation so you would have to change reftick to 2mhz which would have a global system effect.

SlavaDev503
Posts: 5
Joined: Thu Apr 30, 2020 1:00 pm

Re: UART clock source

Postby SlavaDev503 » Thu May 07, 2020 1:06 pm

Is it possible to change REF_TICK clock? I can`t find any API to do this.
In the next picture I can see that REF_TICK value is hardcoded in IDF
esp32_1.png
esp32_1.png (26.88 KiB) Viewed 6388 times

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: UART clock source

Postby WiFive » Sat May 09, 2020 10:56 am

No I think you would have to modify it and also set APB_CTRL_CK8M_TICK_NUM

KillSwitch
Posts: 1
Joined: Wed Oct 13, 2021 6:57 am

Re: UART clock source

Postby KillSwitch » Wed Oct 13, 2021 7:06 am

Hi,
is there a save way to increase the REF_TICK clock? I need 2MHz to hit the correct UART baudrate in my usecase...
changing only the define 'REF_CLK_FREQ' doesn't work.
any idea?

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 164 guests