1 // Copyright 2010-2020 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <stdint.h>
16 #include <stdlib.h>
17 #include "esp_attr.h"
18 #include "sdkconfig.h"
19 #include "hal/uart_ll.h"
20 #include "soc/uart_struct.h"
21
22 #if CONFIG_IDF_TARGET_ESP32
23 /**
24 * The function defined in ROM code has a bug, so we re-implement it here.
25 */
esp_rom_uart_tx_wait_idle(uint8_t uart_no)26 IRAM_ATTR void esp_rom_uart_tx_wait_idle(uint8_t uart_no)
27 {
28 uart_dev_t *device = NULL;
29 switch (uart_no) {
30 case 0:
31 device = &UART0;
32 break;
33 case 1:
34 device = &UART1;
35 break;
36 default:
37 device = &UART2;
38 break;
39 }
40 while (!uart_ll_is_tx_idle(device));
41 }
42 #endif
43
esp_rom_uart_set_clock_baudrate(uint8_t uart_no,uint32_t clock_hz,uint32_t baud_rate)44 IRAM_ATTR void esp_rom_uart_set_clock_baudrate(uint8_t uart_no, uint32_t clock_hz, uint32_t baud_rate)
45 {
46 extern void uart_div_modify(uint8_t uart_no, uint32_t DivLatchValue);
47 uart_div_modify(uart_no, (clock_hz << 4) / baud_rate);
48 }
49