Advertisement
doragasu

esp-open-rtos patch to be able to select stdout UART

Jan 19th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.58 KB | None | 0 0
  1. diff --git a/common.mk b/common.mk
  2. index 25260fb..6521497 100644
  3. --- a/common.mk
  4. +++ b/common.mk
  5. @@ -48,6 +48,9 @@ ESPTOOL ?= esptool.py
  6.  ESPPORT ?= /dev/ttyUSB0
  7.  ESPBAUD ?= 115200
  8.  
  9. +# Set STDOUT_UART to the UART number that will be used to output using printf/os_printf
  10. +STDOUT_UART ?= 0
  11. +
  12.  # Set OTA to 1 to build an image that supports rBoot OTA bootloader
  13.  #
  14.  # Currently only works with 16mbit or more flash sizes, with 8mbit
  15. @@ -100,7 +103,7 @@ ENTRY_SYMBOL ?= call_user_start
  16.  SPLIT_SECTIONS ?= 1
  17.   1 diff --git a/common.mk b/common.mk
  18.   2 index 25260fb..6521497 100644
  19.   3 --- a/common.mk
  20.   4 +++ b/common.mk
  21.   5 @@ -48,6 +48,9 @@ ESPTOOL ?= esptool.py
  22.   6  ESPPORT ?= /dev/ttyUSB0
  23.   7  ESPBAUD ?= 115200
  24.   8
  25.   9 +# Set STDOUT_UART to the UART number that will be used to output using printf/os_printf
  26.  10 +STDOUT_UART ?= 0
  27.  11 +
  28.  12  # Set OTA to 1 to build an image that supports rBoot OTA bootloader
  29.  13  #
  30.  14  # Currently only works with 16mbit or more flash sizes, with 8mbit
  31.  
  32.  # Common flags for both C & C++_
  33. -C_CXX_FLAGS     ?= -Wall -Werror -Wl,-EL -nostdlib $(EXTRA_C_CXX_FLAGS)
  34. +C_CXX_FLAGS     ?= -Wall -Werror -Wl,-EL -nostdlib -DPRINT_UART=$(STDOUT_UART) $(EXTRA_C_CXX_FLAGS)
  35.  # Flags for C only
  36.  CFLAGS         ?= $(C_CXX_FLAGS) -std=gnu99 $(EXTRA_CFLAGS)
  37.  # Flags for C++ only
  38. diff --git a/core/app_main.c b/core/app_main.c
  39. index a710c77..ce08a88 100644
  40. --- a/core/app_main.c
  41. +++ b/core/app_main.c
  42. @@ -165,7 +165,7 @@ void IRAM sdk_user_fatal_exception_handler(void) {
  43.  
  44.  
  45.  static void IRAM default_putc(char c) {
  46. -    uart_putc(0, c);
  47. +    uart_putc(PRINT_UART, c);
  48.  }
  49.  
  50.  // .text+0x258
  51. @@ -232,6 +232,10 @@ void IRAM sdk_user_start(void) {
  52.      sdk_SPIRead(ic_flash_addr, buf32, sizeof(struct sdk_g_ic_saved_st));
  53.      Cache_Read_Enable(0, 0, 1);
  54.      zero_bss();
  55. +       // If user wants output through UART1, switch GPIO2 to U1TX function
  56. +#if PRINT_UART == 1
  57. +       PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
  58. +#endif
  59.      sdk_os_install_putc1(default_putc);
  60.      if (cksum_magic == 0xffffffff) {
  61.          // No checksum required
  62. diff --git a/core/newlib_syscalls.c b/core/newlib_syscalls.c
  63. index b414481..ec1495c 100644
  64. --- a/core/newlib_syscalls.c
  65. +++ b/core/newlib_syscalls.c
  66. @@ -45,8 +45,8 @@ long _write_r(struct _reent *r, int fd, const char *ptr, int len )
  67.          if(ptr[i] == '\r')
  68.              continue;
  69.          if(ptr[i] == '\n')
  70. -            uart_putc(0, '\r');
  71. -        uart_putc(0, ptr[i]);
  72. +            uart_putc(PRINT_UART, '\r');
  73. +        uart_putc(PRINT_UART, ptr[i]);
  74.      }
  75.      return len;
  76.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement