esp_rom_uart.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include <stdint.h>
  15. #include <stdlib.h>
  16. #include "esp_attr.h"
  17. #include "sdkconfig.h"
  18. #include "hal/uart_ll.h"
  19. #include "soc/uart_struct.h"
  20. #if CONFIG_IDF_TARGET_ESP32
  21. /**
  22. * The function defined in ROM code has a bug, so we re-implement it here.
  23. */
  24. IRAM_ATTR void esp_rom_uart_tx_wait_idle(uint8_t uart_no)
  25. {
  26. uart_dev_t *device = NULL;
  27. switch (uart_no) {
  28. case 0:
  29. device = &UART0;
  30. break;
  31. case 1:
  32. device = &UART1;
  33. break;
  34. default:
  35. device = &UART2;
  36. break;
  37. }
  38. while (!uart_ll_is_tx_idle(device));
  39. }
  40. #endif
  41. IRAM_ATTR void esp_rom_uart_set_clock_baudrate(uint8_t uart_no, uint32_t clock_hz, uint32_t baud_rate)
  42. {
  43. extern void uart_div_modify(uint8_t uart_no, uint32_t DivLatchValue);
  44. uart_div_modify(uart_no, (clock_hz << 4) / baud_rate);
  45. }