esp_rom_uart.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdint.h>
  7. #include <stdlib.h>
  8. #include "esp_attr.h"
  9. #include "sdkconfig.h"
  10. #include "hal/uart_ll.h"
  11. #include "hal/efuse_hal.h"
  12. #include "esp_rom_caps.h"
  13. #include "rom/uart.h"
  14. #if CONFIG_IDF_TARGET_ESP32
  15. /**
  16. * The function defined in ROM code has a bug, so we re-implement it here.
  17. */
  18. IRAM_ATTR void esp_rom_uart_tx_wait_idle(uint8_t uart_no)
  19. {
  20. while (!uart_ll_is_tx_idle(UART_LL_GET_HW(uart_no))) {};
  21. }
  22. #endif
  23. #if CONFIG_IDF_TARGET_ESP32C3
  24. /**
  25. * The ESP32-C3 ROM has released two versions, one is the ECO3 version,
  26. * and the other is the version before ECO3 (include ECO0 ECO1 ECO2).
  27. * These two versions of the ROM code do not list uart_tx_switch wrap
  28. * function in the ROM interface, so here use the uart_tx_switch direct
  29. * address instead.
  30. */
  31. IRAM_ATTR void esp_rom_uart_set_as_console(uint8_t uart_no)
  32. {
  33. typedef void (*rom_func_t)(uint8_t);
  34. rom_func_t uart_tx_switch = NULL;
  35. if (efuse_hal_chip_revision() < 3) {
  36. uart_tx_switch = (rom_func_t)0x4004b8ca;
  37. } else {
  38. uart_tx_switch = (rom_func_t)0x4004c166;
  39. }
  40. uart_tx_switch(uart_no);
  41. }
  42. #endif
  43. #if !ESP_ROM_HAS_UART_BUF_SWITCH
  44. IRAM_ATTR void esp_rom_uart_switch_buffer(uint8_t uart_no)
  45. {
  46. UartDevice *uart = GetUartDevice();
  47. uart->buff_uart_no = uart_no;
  48. }
  49. #endif // !ESP_ROM_HAS_UART_BUF_SWITCH