Skip to content

Commit

Permalink
cpu/esp8266: complete reimplementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gschorcht committed Mar 5, 2019
1 parent da36aa3 commit 7d7936a
Show file tree
Hide file tree
Showing 212 changed files with 27,161 additions and 9,859 deletions.
17 changes: 10 additions & 7 deletions boards/common/esp8266/board_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "board_common.h"
#include "esp_common.h"
#include "log.h"
#include "periph/gpio.h"

Expand All @@ -42,6 +43,7 @@ void board_init(void)
#endif
}

extern void adc_print_config(void);
extern void pwm_print_config(void);
extern void i2c_print_config(void);
extern void spi_print_config(void);
Expand All @@ -50,27 +52,28 @@ extern void timer_print_config(void);

void board_print_config (void)
{
LOG_INFO("\nBoard configuration:\n");
ets_printf("\nBoard configuration:\n");

adc_print_config();
pwm_print_config();
i2c_print_config();
spi_print_config();
uart_print_config();
timer_print_config();

LOG_INFO("\tLED: pins=[ ");
ets_printf("\tLED:\t\tpins=[ ");
#ifdef LED0_PIN
LOG_INFO("%d ", LED0_PIN);
ets_printf("%d ", LED0_PIN);
#endif
#ifdef LED1_PIN
LOG_INFO("%d ", LED1_PIN);
ets_printf("%d ", LED1_PIN);
#endif
#ifdef LED2_PIN
LOG_INFO("%d ", LED2_PIN);
ets_printf("%d ", LED2_PIN);
#endif
LOG_INFO("]\n");
ets_printf("]\n");

LOG_INFO("\n\n");
ets_printf("\n\n");
}

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion cpu/esp32/esp-wifi/esp_wifi_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ void auto_init_esp_wifi (void)
_esp_wifi_dev.event = SYSTEM_EVENT_MAX; /* no event */
_esp_wifi_dev.netif = gnrc_netif_ethernet_create(_esp_wifi_stack,
ESP_WIFI_STACKSIZE, ESP_WIFI_PRIO,
"netdev-esp-wifi",
"esp_wifi",
(netdev_t *)&_esp_wifi_dev);
}

Expand Down
3 changes: 2 additions & 1 deletion cpu/esp32/periph/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,8 @@ int rtcio_config_sleep_mode (gpio_t pin, bool mode, bool input)
return 0;
}

void adc_print_config(void) {
void adc_print_config(void)
{
ets_printf("\tADC\t\tpins=[ ");
#if defined(ADC_GPIOS)
for (unsigned i = 0; i < adc_chn_num; i++) {
Expand Down
2 changes: 1 addition & 1 deletion cpu/esp32/periph/i2c_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ void i2c_print_config(void)

void i2c_print_config(void)
{
LOG_TAG_INFO("i2c", "no I2C devices\n");
ets_printf("\tI2C:\tno devices\n");
}

#endif /* defined(I2C0_SPEED) || defined(I2C1_SPEED) */
Expand Down
2 changes: 1 addition & 1 deletion cpu/esp32/periph/i2c_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ void i2c_print_config(void)

void i2c_print_config(void)
{
LOG_TAG_INFO("i2c", "no I2C devices\n");
ets_printf("\tI2C:\t\tno devices\n");
}

#endif /* defined(I2C0_SPEED) || defined(I2C1_SPEED) */
Expand Down
2 changes: 1 addition & 1 deletion cpu/esp32/periph/pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ void pwm_print_config(void)

void pwm_print_config(void)
{
LOG_TAG_INFO("pwm", "no PWM devices\n");
ets_printf("\tPWM:\tno devices\n");
}

#endif /* defined(PWM0_GPIOS) || defined(PWM1_GPIOS) */
2 changes: 1 addition & 1 deletion cpu/esp32/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void uart_system_init (void)
void uart_print_config(void)
{
for (unsigned uart = 0; uart < UART_NUMOF; uart++) {
ets_printf("\tUART_DEV(%d)\ttxd=%d rxd=%d\n", uart,
ets_printf("\tUART_DEV(%d):\ttxd=%d rxd=%d\n", uart,
__uarts[uart].pin_txd, __uarts[uart].pin_rxd);
}
}
Expand Down
6 changes: 5 additions & 1 deletion cpu/esp32/vendor/esp-idf/esp32/event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx)
s_event_ctx = ctx;
s_event_queue = xQueueCreate(CONFIG_SYSTEM_EVENT_QUEUE_SIZE, sizeof(system_event_t));

#ifdef RIOT_VERSION
xTaskCreatePinnedToCore(esp_event_loop_task, "esp_events",
ESP_TASKD_EVENT_STACK, NULL, ESP_TASKD_EVENT_PRIO, NULL, 0);
#else
xTaskCreatePinnedToCore(esp_event_loop_task, "wifi-event-loop",
ESP_TASKD_EVENT_STACK, NULL, ESP_TASKD_EVENT_PRIO, NULL, 0);

#endif
s_event_init_flag = true;
return ESP_OK;
}
3 changes: 3 additions & 0 deletions cpu/esp8266/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ MODULE = cpu

# Add a list of subdirectories, that should also be built:
DIRS += $(RIOTCPU)/esp_common
DIRS += freertos
DIRS += periph
DIRS += sdk
DIRS += vendor
Expand All @@ -11,4 +12,6 @@ ifneq (, $(filter esp_wifi, $(USEMODULE)))
DIRS += esp-wifi
endif

INCLUDES += -I$(ESP8266_SDK_DIR)/components/esp8266/include/internal

include $(RIOTBASE)/Makefile.base
8 changes: 2 additions & 6 deletions cpu/esp8266/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# additional modules dependencies

ifneq (, $(filter esp_sdk, $(USEMODULE)))
USEMODULE += core_thread_flags
INCLUDES += -I$(ESP8266_SDK_DIR)/third_party/include
ifneq (, $(filter esp_idf_heap, $(USEMODULE)))
LINKFLAGS += -Wl,-wrap=malloc
LINKFLAGS += -Wl,-wrap=free
LINKFLAGS += -Wl,-wrap=calloc
LINKFLAGS += -Wl,-wrap=realloc
LINKFLAGS += -Wl,-wrap=_malloc_r
LINKFLAGS += -Wl,-wrap=_calloc_r
LINKFLAGS += -Wl,-wrap=_free_r
LINKFLAGS += -Wl,-wrap=_realloc_r
LINKFLAGS += -Wl,-wrap=mallinfo
endif

ifneq (, $(filter esp_spiffs, $(USEMODULE)))
Expand All @@ -20,8 +18,6 @@ ifneq (, $(filter esp_spiffs, $(USEMODULE)))
endif

ifneq (, $(filter esp_wifi, $(USEMODULE)))
CFLAGS += -DLWIP_OPEN_SRC
LINKFLAGS += -Wl,-wrap=ethernet_input
USEMODULE += netdev_eth
endif

Expand Down
161 changes: 92 additions & 69 deletions cpu/esp8266/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
# check some environment variables first

ifndef ESP8266_NEWLIB_DIR
$(info ESP8266_NEWLIB_DIR should be defined as /path/to/newlib directory)
$(info ESP8266_NEWLIB_DIR is set by default to /opt/esp/newlib-xtensa)
export ESP8266_NEWLIB_DIR=/opt/esp/newlib-xtensa
endif

ifndef ESP8266_SDK_DIR
$(info ESP8266_SDK_DIR should be defined as /path/to/sdk directory)
$(info ESP8266_SDK_DIR is set by default to /opt/esp/esp-open-sdk/sdk)
export ESP8266_SDK_DIR=/opt/esp/esp-open-sdk/sdk
export ESP8266_SDK_DIR=/opt/esp/ESP8266-RTOS-SDK
endif

# Options to control the compilation

ifeq ($(USE_SDK), 1)
USEMODULE += esp_sdk
endif

ifeq ($(ENABLE_GDB), 1)
USEMODULE += esp_gdb
endif
Expand All @@ -29,13 +19,9 @@ endif
# SPECIAL module dependencies
# cannot be done in Makefile.dep since Makefile.dep is included too late

ifneq (, $(filter esp_sw_timer, $(USEMODULE)))
USEMODULE += esp_sdk
endif

ifneq (, $(filter esp_now esp_wifi, $(USEMODULE)))
$(eval GNRC_NETIF_NUMOF=$(shell echo $$(($(GNRC_NETIF_NUMOF)+1))))
USEMODULE += esp_sdk
USEMODULE += esp_wifi_any
USEMODULE += netopt
endif

Expand All @@ -46,49 +32,65 @@ endif
# regular Makefile

export TARGET_ARCH ?= xtensa-lx106-elf
export ESPTOOL ?= $(ESP8266_SDK_DIR)/components/esptool_py/esptool/esptool.py

# ESP8266 pseudomodules
PSEUDOMODULES += esp_gdb
PSEUDOMODULES += esp_now
PSEUDOMODULES += esp_sdk
PSEUDOMODULES += esp_log_color
PSEUDOMODULES += esp_qemu
PSEUDOMODULES += esp_sw_timer
PSEUDOMODULES += esp_spiffs

USEMODULE += esp
PSEUDOMODULES += esp_wifi_any

USEMODULE += esp_idf
USEMODULE += esp_idf_esp8266
USEMODULE += esp_idf_nvs_flash
USEMODULE += esp_idf_spi_flash
USEMODULE += esp_idf_util
USEMODULE += esp_idf_wpa_supplicant_crypto
USEMODULE += esp_sdk
USEMODULE += log
USEMODULE += mtd
USEMODULE += periph
USEMODULE += periph_common
USEMODULE += ps
USEMODULE += random
USEMODULE += sdk
USEMODULE += riot_freertos
USEMODULE += xtensa
USEMODULE += xtimer

ifneq (, $(filter pthread, $(USEMODULE)))
# has to be included before $(ESP8266_NEWLIB_DIR)
INCLUDES += -I$(RIOTBASE)/sys/posix/pthread/include
endif

INCLUDES += -I$(ESP8266_NEWLIB_DIR)/$(TARGET_ARCH)/include
INCLUDES += -I$(RIOTBOARD)/common/$(CPU)/include
INCLUDES += -I$(RIOTCPU)/esp_common/vendor/
INCLUDES += -I$(RIOTCPU)/$(CPU)
INCLUDES += -I$(RIOTCPU)/$(CPU)/include
INCLUDES += -I$(RIOTCPU)/$(CPU)/include/freertos
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/espressif

CFLAGS += -DESP_OPEN_SDK -DSCHED_PRIO_LEVELS=32 -DCONTEXT_SWITCH_BY_INT
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/bootloader_support/include
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/esp8266/include
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/esp8266/include/esp8266
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/heap/include
INCLUDES += -I$(RIOTCPU)/$(CPU)/vendor/esp-idf/log/include
INCLUDES += -I$(ESP8266_SDK_DIR)/components/
INCLUDES += -I$(ESP8266_SDK_DIR)/components/bootloader_support/include/
INCLUDES += -I$(ESP8266_SDK_DIR)/components/esp8266/include
INCLUDES += -I$(ESP8266_SDK_DIR)/components/esp8266/include/esp8266
INCLUDES += -I$(ESP8266_SDK_DIR)/components/heap/include
INCLUDES += -I$(ESP8266_SDK_DIR)/components/heap/port/esp8266/include
INCLUDES += -I$(ESP8266_SDK_DIR)/components/nvs_flash/include
INCLUDES += -I$(ESP8266_SDK_DIR)/components/spi_flash/include

CFLAGS += -DESP_OPEN_SDK -DSCHED_PRIO_LEVELS=32 -DDEVELHELP
CFLAGS += -D__ESP_FILE__=__FILE__
CFLAGS += -Wno-unused-parameter -Wformat=0
CFLAGS += -mlongcalls -mtext-section-literals
CFLAGS += -fdata-sections -fzero-initialized-in-bss
CFLAGS += -fdata-sections -ffunction-sections -fzero-initialized-in-bss
CFLAGS += -fno-exceptions
ASFLAGS += --longcalls --text-section-literals

ifneq (, $(filter esp_sdk, $(USEMODULE)))
INCLUDES += -I$(ESP8266_SDK_DIR)/include
CFLAGS += -DUSE_US_TIMER
endif

ifneq (, $(filter esp_gdbstub, $(USEMODULE)))
GDBSTUB_DIR ?= $(RIOTCPU)/$(CPU)/vendor/esp-gdbstub
CFLAGS += -DGDBSTUB_FREERTOS=0
CFLAGS += -DGDBSTUB_FREERTOS=0 -DGDBSTUB_BREAK_ON_INIT=0
INCLUDES += -I$(GDBSTUB_DIR)
endif

Expand All @@ -99,7 +101,7 @@ else
endif

ifeq ($(QEMU), 1)
CFLAGS += -DQEMU
USEMODULE += esp_qemu
endif

ifeq ($(FLASH_MODE), qio)
Expand All @@ -110,44 +112,65 @@ ifeq ($(FLASH_MODE), qout)
CFLAGS += -DFLASH_MODE_QOUT
endif

LINKFLAGS += -L$(ESP8266_NEWLIB_DIR)/$(TARGET_ARCH)/lib
LINKFLAGS += -L$(ESP8266_SDK_DIR)/lib

ifneq (, $(filter esp_sdk, $(USEMODULE)))
LINKFLAGS += -Wl,--start-group $(BINDIR)/sdk.a
ifneq (, $(filter esp_now, $(USEMODULE)))
LINKFLAGS += -lespnow
endif
LINKFLAGS += -lmain -lnet80211 -lcrypto -lwpa2 -lwpa -llwip -lpp -lphy -lc -lhal
LINKFLAGS += -Wl,--end-group
LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp8266.riot-os.sdk.app.ld
else
LINKFLAGS += -Wl,--start-group -lphy -lhal -lc -Wl,--end-group
LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp8266.riot-os.no_sdk.app.ld
LINKFLAGS += -L$(ESP8266_SDK_DIR)/components/esp8266/lib

BASELIBS += -lc -lgcc -lwpa -lcore -lnet80211 -lphy -lpp -lhal -lstdc++

ifneq (, $(filter esp_now, $(USEMODULE)))
BASELIBS += -lespnow
endif

LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/eagle.rom.addr.v6.ld
LINKFLAGS += -nostdlib -lgcc -u ets_run -Wl,-gc-sections # -Wl,--print-gc-sections
LINKFLAGS += -u _malloc_r
LINKFLAGS += -nostdlib -Wl,-gc-sections -Wl,-static # -Wl,--print-gc-sections
LINKFLAGS += -Wl,--warn-unresolved-symbols
LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp8266.rom.ld
LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp8266.riot-os.ld
LINKFLAGS += -T$(RIOTCPU)/$(CPU)/ld/esp8266.peripherals.ld

# configure preflasher to convert .elf to .bin before flashing
FLASH_SIZE = -fs 8m
export PREFLASHER ?= esptool.py
export PREFFLAGS ?= elf2image $(FLASH_SIZE) $(ELFFILE)
export FLASHDEPS ?= preflash
FLASH_MODE = dout # FIX configuration, DO NOT CHANGE
FLASH_FREQ = 40m # FIX configuration, DO NOT CHANGE
FLASH_SIZE ?= 1MB

export PREFLASHER = $(ESPTOOL)

export PREFFLAGS = --chip esp8266 elf2image --flash_size $(FLASH_SIZE)
export PREFFLAGS += --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ)
export PREFFLAGS += --version=3 -o $(ELFFILE).bin $(ELFFILE);
export PREFFLAGS += echo "" > $(BINDIR)/partitions.csv;
export PREFFLAGS += echo "nvs, data, nvs, 0x9000, 0x6000" >> $(BINDIR)/partitions.csv;
export PREFFLAGS += echo "phy_init, data, phy, 0xf000, 0x1000" >> $(BINDIR)/partitions.csv;
export PREFFLAGS += echo -n "factory, app, factory, 0x10000, " >> $(BINDIR)/partitions.csv;
export PREFFLAGS += ls -l $(ELFFILE).bin | awk '{ print $$5 }' >> $(BINDIR)/partitions.csv;
export PREFFLAGS += python $(ESP8266_SDK_DIR)/components/partition_table/gen_esp32part.py
export PREFFLAGS += --verify $(BINDIR)/partitions.csv $(BINDIR)/partitions.bin
export FLASHDEPS = preflash

ifneq (, $(filter esp_log_color, $(USEMODULE)))
BOOTLOADER = bootloader_dout_115200_color.bin
else
BOOTLOADER = bootloader_dout_115200_no_color.bin
endif

# flasher configuration
ifeq ($(QEMU), 1)
export FLASHER = cat
export FFLAGS += $(ELFFILE)-0x00000.bin /dev/zero | head -c $$((0x10000)) | cat -
export FFLAGS += $(ELFFILE)-0x10000.bin /dev/zero | head -c $$((0xfc000)) | cat -
export FFLAGS += $(RIOTCPU)/$(CPU)/bin/esp_init_data_default.bin > $(ELFFILE).bin
export FLASHER = dd
export FFLAGS += if=/dev/zero bs=1M count=1 | tr "\\000" "\\377" > tmp.bin &&
export FFLAGS += cat $(RIOTCPU)/$(CPU)/bin/$(BOOTLOADER) tmp.bin |
export FFLAGS += head -c $$((0x8000)) |
export FFLAGS += cat - $(BINDIR)/partitions.bin tmp.bin |
export FFLAGS += head -c $$((0x10000)) |
export FFLAGS += cat - $(ELFFILE).bin tmp.bin |
export FFLAGS += head -c $$((0xfc000)) |
export FFLAGS += cat - $(RIOTCPU)/$(CPU)/bin/esp_init_data_default.bin tmp.bin |
export FFLAGS += head -c $$((0x100000)) > $(BINDIR)/esp8266flash.bin && rm tmp.bin
else
FLASH_MODE ?= dout
export PROGRAMMER_SPEED ?= 460800
export FLASHER = esptool.py
export FFLAGS += -p $(PORT) -b $(PROGRAMMER_SPEED) write_flash
export FFLAGS += -fm $(FLASH_MODE)
export FFLAGS += 0 $(ELFFILE)-0x00000.bin
export FFLAGS += 0x10000 $(ELFFILE)-0x10000.bin; esptool.py -p $(PORT) run
export FLASHER = $(ESPTOOL)
export FFLAGS += --chip esp8266 --port $(PORT) --baud $(PROGRAMMER_SPEED)
export FFLAGS += --before default_reset --after hard_reset write_flash -z
export FFLAGS += --flash_size detect
export FFLAGS += --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ)
export FFLAGS += 0x0000 $(RIOTCPU)/$(CPU)/bin/$(BOOTLOADER)
export FFLAGS += 0x8000 $(BINDIR)/partitions.bin
export FFLAGS += 0x10000 $(ELFFILE).bin
endif
Binary file removed cpu/esp8266/bin/wifi_cfg_default.bin
Binary file not shown.
Loading

0 comments on commit 7d7936a

Please sign in to comment.