From dcf84169ae75b11c1656d45dbc6c626d93da6a10 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 8 Dec 2017 15:07:52 +0100 Subject: Add output support (broken on esp8266) --- src/arch/esp8266/Makefile.inc | 5 ++++- src/arch/esp8266/arch.cc | 5 +++++ src/arch/esp8266/driver/stdout.cc | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/arch/esp8266/driver/stdout.cc (limited to 'src/arch/esp8266') diff --git a/src/arch/esp8266/Makefile.inc b/src/arch/esp8266/Makefile.inc index b0fc4ce..9a08678 100644 --- a/src/arch/esp8266/Makefile.inc +++ b/src/arch/esp8266/Makefile.inc @@ -9,6 +9,7 @@ CC = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-gcc CXX = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-g++ AR = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-ar LD = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-gcc +OBJCOPY = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-objcopy INCLUDES += -Iinclude/esp8266 -I${SDK_BASE}/include COMMON_FLAGS += -nostdlib -mlongcalls -D__ets__ -DICACHE_FLASH @@ -16,17 +17,19 @@ CXXFLAGS = -std=c++11 LDFLAGS += -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static TARGETS += src/arch/esp8266/arch.cc src/arch/esp8266/driver/gpio.cc +TARGETS += src/arch/esp8266/driver/stdout.cc OBJECTS = ${TARGETS:.cc=.o} .cc.o: ${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc} + ${OBJCOPY} --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal $@ build/system.ar: ${OBJECTS} ${AR} cru $@ ${OBJECTS} build/system.elf: build/system.ar - ${CC} -L${SDK_BASE}/lib -T${SDK_BASE}/lib/eagle.app.v6.ld ${LDFLAGS} \ + ${CC} -L${SDK_BASE}/lib -T${SDK_BASE}/lib/eagle.app.v6-derf.ld ${LDFLAGS} \ -Wl,--start-group -lc -lgcc -lhal -lpp -lphy -lnet80211 -llwip -lwpa \ -lmain $< -Wl,--end-group -o $@ diff --git a/src/arch/esp8266/arch.cc b/src/arch/esp8266/arch.cc index 0e11f2d..f5d1c91 100644 --- a/src/arch/esp8266/arch.cc +++ b/src/arch/esp8266/arch.cc @@ -10,6 +10,8 @@ extern "C" { void ets_timer_arm_new(os_timer_t *ptimer, uint32_t milliseconds, bool repeat_flag, bool us_flag); void ets_timer_disarm(os_timer_t *ptimer); void ets_timer_setfn(os_timer_t *ptimer, os_timer_func_t *pfunction, void *parg); +extern void (*__init_array_start)(); +extern void (*__init_array_end)(); } #define user_procTaskPrio 0 @@ -30,6 +32,9 @@ extern int main(void); void ICACHE_FLASH_ATTR jump_to_main(void) { + for (void (**p)() = &__init_array_start; p != &__init_array_start; p++) { + (*p)(); + } #ifdef WITH_LOOP os_timer_disarm(&loop_timer); os_timer_setfn(&loop_timer, (os_timer_func_t *)jump_to_loop, (void *)0); diff --git a/src/arch/esp8266/driver/stdout.cc b/src/arch/esp8266/driver/stdout.cc new file mode 100644 index 0000000..b35275b --- /dev/null +++ b/src/arch/esp8266/driver/stdout.cc @@ -0,0 +1,25 @@ +#include "driver/stdout.h" +extern "C" { +#include "osapi.h" +#include "user_interface.h" +#include "gpio.h" +void uart_div_modify(uint8_t uart_no, uint32 DivLatchValue); +void os_printf_plus(const char *s, ...); +} + +void StandardOutput::setup() +{ + uart_div_modify(0, UART_CLK_FREQ / 115200); +} + +void StandardOutput::put(char c) +{ + os_printf("%c", c); +} + +void StandardOutput::write(const char *s) +{ + os_printf("%s", s); +} + +StandardOutput kout; -- cgit v1.2.3