Commit 224788b6 authored by Johny Mattsson's avatar Johny Mattsson
Browse files

Make NodeMCU compile and link for ESP32.

A fair bit of reshuffling with include paths and overrides was necessary, as
the two RTOS SDKs (ESP8266 and ESP32) don't have the same header structure
(or even libraries for that matter). Uses the xtensa-esp108-elf toolchain
to build.

Completely untested beyond linking, as I still can't flash the ESP32 module
I have :(  I'd be most surprised if it does anything useful at this point
considering I've spent almost no time on the linker script or UART setup.

Anything using espconn has been ifdef'd out since espconn is not (and
probably will not be) available. Notably this includes the entire net module
as well as coap, mqtt and enduser_setup.

Many (most?) hardware bus drivers and related modules are also ifdef'd
out for now due to hardware differences. Functions surrounding sleep,
rtc and RF modes have also been hit by the ifdef hammer. Grep'ing for
__ESP8266__ and/or FIXME is a quick way of finding these places. With
time I hope all of these will be reinstated.
parent 0df2eda6
[submodule "rtos-sdk"]
path = rtos-sdk
[submodule "esp8266-rtos-sdk"]
path = esp8266-rtos-sdk
url = https://github.com/espressif/ESP8266_RTOS_SDK.git
[submodule "esp32-rtos-sdk"]
path = esp32-rtos-sdk
url = https://github.com/espressif/ESP32_RTOS_SDK.git
......@@ -12,22 +12,61 @@
%: s.%
%: SCCS/s.%
# Set up flags and paths based on hardware target
HW?=ESP8266
ifeq ($(HW),ESP8266)
TARGET=esp8266
TARGET_SDK_LIBS=espconn cirom mirom nopoll
TARGET_LDFLAGS=-u _UserExceptionVectorOverride -Wl,--wrap=printf
LD_FILE=$(LDDIR)/nodemcu.ld
AR = xtensa-lx106-elf-ar
CC = xtensa-lx106-elf-gcc
NM = xtensa-lx106-elf-nm
CPP = xtensa-lx106-elf-cpp
OBJCOPY = xtensa-lx106-elf-objcopy
else ifeq ($(HW),ESP32)
TARGET=esp32
TARGET_SDK_LIBS=rtc c m driver
TARGET_LDFLAGS=
LD_FILE=$(LDDIR)/nodemcu32.ld
AR = xtensa-esp108-elf-ar
CC = xtensa-esp108-elf-gcc
NM = xtensa-esp108-elf-nm
CPP = xtensa-esp108-elf-cpp
OBJCOPY = xtensa-esp108-elf-objcopy
else
$(error Unsupported hardware platform: $(HW))
endif
# Ensure we search "our" SDK before the tool-chain's SDK (if any)
TOP_DIR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
SDKDIR:=$(TOP_DIR)/rtos-sdk
SDKDIR:=$(TOP_DIR)/$(TARGET)-rtos-sdk
# This is, sadly, the cleanest way to resolve the different non-standard
# conventions for sized integers across the various components.
BASIC_TYPES=-Du32_t=uint32_t -Du16_t=uint16_t -Du8_t=uint8_t -Ds32_t=int32_t -Ds16_t=int16_t -Duint32=uint32_t -Duint16=uint16_t -Duint8=uint8_t -Dsint32=int32_t -Dsint16=int16_t -Dsint8=int8_t
# Include dirs, ensure the overrides come first
INCLUDE_DIRS=$(TOP_DIR)/sdk-overrides/include $(SDKDIR)/include $(SDKDIR)/include/espressif $(SDKDIR)/include/lwip $(SDKDIR)/include/lwip/ipv4 $(SDKDIR)/include/lwip/ipv6 $(SDKDIR)/extra_include
INCLUDE_DIRS=\
$(TOP_DIR)/sdk-overrides/include \
$(TOP_DIR)/sdk-overrides/$(TARGET)-include \
$(SDKDIR)/include \
$(SDKDIR)/include/espressif \
$(SDKDIR)/include/espressif/$(TARGET) \
$(SDKDIR)/include/$(TARGET) \
$(SDKDIR)/include/lwip \
$(SDKDIR)/include/lwip/ipv4 \
$(SDKDIR)/include/lwip/ipv6 \
$(SDKDIR)/extra_include \
$(SDKDIR)/third_party/include \
$(SDKDIR)/third_party/include/lwip \
$(SDKDIR)/third_party/include/lwip/ipv4 \
$(SDKDIR)/third_party/include/lwip/ipv6 \
$(SDKDIR)/driver_lib/include \
# ... and we have to mark them all as system include dirs rather than the usual
# -I for user include dir, or the esp-open-sdk toolchain headers wreak havoc
CCFLAGS:=$(addprefix -isystem,$(INCLUDE_DIRS)) $(BASIC_TYPES)
CCFLAGS:=$(addprefix -isystem,$(INCLUDE_DIRS)) $(BASIC_TYPES) -D__$(HW)__
LDFLAGS:= -L$(SDKDIR)/lib -L$(SDKDIR)/ld $(LDFLAGS)
......@@ -39,12 +78,8 @@ else
ESPPORT = $(COMPORT)
endif
CCFLAGS += -Os -ffunction-sections -fno-jump-tables -fdata-sections
AR = xtensa-lx106-elf-ar
CC = xtensa-lx106-elf-gcc
NM = xtensa-lx106-elf-nm
CPP = xtensa-lx106-elf-cpp
OBJCOPY = xtensa-lx106-elf-objcopy
FIRMWAREDIR = ../bin/
FIRMWAREDIR = ../bin/$(TARGET)/
#############################################################
ESPTOOL ?= ../tools/esptool.py
......@@ -53,7 +88,7 @@ ESPTOOL ?= ../tools/esptool.py
CSRCS ?= $(wildcard *.c)
ASRCs ?= $(wildcard *.s)
ASRCS ?= $(wildcard *.S)
SUBDIRS ?= $(filter-out rtos-sdk, $(patsubst %/,%,$(dir $(wildcard */Makefile))))
SUBDIRS ?= $(filter-out esp8266-rtos-sdk esp32-rtos-sdk, $(patsubst %/,%,$(dir $(wildcard */Makefile))))
ODIR := .output
OBJODIR := $(ODIR)/$(TARGET)/$(FLAVOR)/obj
......@@ -126,8 +161,18 @@ $$(IMAGEODIR)/$(1).out: $$(OBJS) $$(DEP_OBJS_$(1)) $$(DEP_LIBS_$(1)) $$(DEPENDS_
endef
$(BINODIR)/%.bin: $(IMAGEODIR)/%.out
@mkdir -p $(BINODIR)
@mkdir -p $(BINODIR) $(FIRMWAREDIR)
ifeq ($(HW),ESP8266)
$(ESPTOOL) elf2image $< -o $(FIRMWAREDIR)
else ifeq ($(HW),ESP32)
@$(OBJCOPY) --only-section .text -O binary $< eagle.app.v7.text.bin
@$(OBJCOPY) --only-section .data -O binary $< eagle.app.v7.data.bin
@$(OBJCOPY) --only-section .rodata -O binary $< eagle.app.v7.rodata.bin
@$(OBJCOPY) --only-section .irom0.text -O binary $< eagle.app.v7.irom0text.bin
@$(OBJCOPY) --only-section .drom0.text -O binary $< eagle.app.v7.drom0text.bin
@python $(SDKDIR)/tools/gen_appbin.py $< $(LD_FILE) 0 0 unused_app_cpu.bin $(FIRMWAREDIR)
@rm -f eagle.app.v7.*.bin
endif
#############################################################
# Rules base
......@@ -144,13 +189,6 @@ clobber: $(SPECIAL_CLOBBER)
$(foreach d, $(SUBDIRS), $(MAKE) -C $(d) clobber;)
$(RM) -r $(ODIR)
flash:
ifndef PDIR
$(MAKE) -C ./app flash
else
$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 $(FIRMWAREDIR)0x00000.bin 0x10000 $(FIRMWAREDIR)0x10000.bin
endif
.subdirs:
@set -e; $(foreach d, $(SUBDIRS), $(MAKE) -C $(d);)
......
......@@ -11,7 +11,6 @@
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
TARGET = eagle
#FLAVOR = release
FLAVOR = debug
......@@ -63,8 +62,6 @@ ifeq ($(FLAVOR),release)
TARGET_LDFLAGS += -Os
endif
LD_FILE = $(LDDIR)/nodemcu.ld
COMPONENTS_eagle.app.v6 = \
user/libuser.a \
driver/libdriver.a \
......@@ -93,23 +90,19 @@ COMPONENTS_eagle.app.v6 = \
SELECTED_MODULE_SYMS=$(filter %_module_selected %module_selected1,$(shell $(NM) modules/.output/$(TARGET)/$(FLAVOR)/lib/libmodules.a))
USED_SDK_LIBS= \
cirom \
crypto \
espconn \
freertos \
gcc \
json \
lwip \
main \
mirom \
net80211 \
nopoll \
phy \
pp \
smartconfig \
ssl \
wpa \
wps \
$(TARGET_SDK_LIBS) \
LINKFLAGS_eagle.app.v6 = \
-Wl,--gc-sections \
......@@ -119,10 +112,9 @@ LINKFLAGS_eagle.app.v6 = \
-Wl,@$(LDDIR)/defsym.rom \
-T$(LDDIR)/extrasyms.rom \
-Wl,--no-check-sections \
-Wl,--wrap=printf \
-Wl,-static \
$(TARGET_LDFLAGS) \
$(addprefix -u , $(SELECTED_MODULE_SYMS)) \
-u _UserExceptionVectorOverride \
-Wl,--start-group \
-lhal \
$(addprefix -l,$(USED_SDK_LIBS)) \
......
......@@ -6,6 +6,7 @@
* -1.7976931348623e+308 */
# define FPCONV_G_FMT_BUFSIZE 32
#if 0
#ifdef USE_INTERNAL_FPCONV
static inline void fpconv_init()
{
......@@ -14,6 +15,7 @@ static inline void fpconv_init()
#else
extern inline void fpconv_init();
#endif
#endif
extern int fpconv_g_fmt(char*, double, int);
extern double fpconv_strtod(const char*, char**);
......
#include "user_config.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "coap.h"
#include "uri.h"
......
......@@ -2,6 +2,7 @@
#include "c_types.h"
#include "coap.h"
#include "coap_timer.h"
#include "hash.h"
#include "node.h"
......
// No espconn on ESP32
#ifdef __ESP8266__
#include <string.h>
#include "coap_io.h"
#include "node.h"
......@@ -69,3 +72,5 @@ coap_tid_t coap_send_confirmed(struct espconn *pesp_conn, coap_pdu_t *pdu) {
coap_timer_start(&gQueue);
return node->id;
}
#endif
// No espconn on ESP32
#ifdef __ESP8266__
#include "node.h"
#include "coap_timer.h"
#include "coap_io.h"
#include "esp_timer.h"
#include "esp_system.h"
static os_timer_t coap_timer;
static coap_tick_t basetime = 0;
......@@ -76,3 +80,4 @@ void coap_timer_start(coap_queue_t ** queue){
coap_timer_setup(queue, (*queue)->t);
}
}
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "esp_libc.h"
#include "coap.h"
#include "lua.h"
......@@ -196,7 +197,13 @@ static uint32_t id = 0;
static const coap_endpoint_path_t path_id = {2, {"v1", "id"}};
static int handle_get_id(const coap_endpoint_t *ep, coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo)
{
#if defined(__ESP8266__)
id = system_get_chip_id();
#elif defined(__ESP32__)
uint8_t tmp;
system_get_chip_id (&tmp); // TODO: deal with failure
id = tmp;
#endif
return coap_make_response(scratch, outpkt, (const uint8_t *)(&id), sizeof(uint32_t), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN);
}
......
#include <string.h>
#include <stdlib.h>
#include "esp_libc.h"
#include "node.h"
static inline coap_queue_t *
......
#include <stdlib.h>
#include "pdu.h"
#include "esp_libc.h"
coap_pdu_t * coap_new_pdu(void) {
coap_pdu_t *pdu = NULL;
......
......@@ -34,6 +34,7 @@
#include "mem.h"
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#ifdef MD2_ENABLE
#include "ssl/ssl_crypto.h"
......
#ifdef __ESP8266__
#include "ets_sys.h"
#include "osapi.h"
#include "eagle_soc.h"
......@@ -41,3 +43,5 @@ gpio16_input_get(void)
{
return (uint8)(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1);
}
#endif
......@@ -8,6 +8,8 @@
* Modification history:
* 2014/5/1, v1.0 create this file.
*******************************************************************************/
#ifdef __ESP8266__
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
......@@ -162,3 +164,4 @@ key_intr_handler(void *arg)
}
}
#endif
......@@ -8,6 +8,9 @@
* Modification history:
* 2014/5/1, v1.0 create this file.
*******************************************************************************/
// ESP32 has own pwm driver in libdriver.a
#ifdef __ESP8266__
#include "platform.h"
#include "ets_sys.h"
......@@ -62,8 +65,8 @@ LOCAL uint16 pwm_gpio = 0;
LOCAL uint8 pwm_channel_num = 0;
LOCAL void ICACHE_RAM_ATTR pwm_tim1_intr_handler(os_param_t p);
#define TIMER_OWNER ((os_param_t) 'P')
LOCAL void ICACHE_RAM_ATTR pwm_tim1_intr_handler(uint32_t p);
#define TIMER_OWNER ((uint32_t) 'P')
LOCAL void ICACHE_FLASH_ATTR
pwm_insert_sort(struct pwm_single_param pwm[], uint8 n)
......@@ -318,7 +321,7 @@ pwm_get_freq(uint8 channel)
* Returns : NONE
*******************************************************************************/
LOCAL void ICACHE_RAM_ATTR
pwm_tim1_intr_handler(os_param_t p)
pwm_tim1_intr_handler(uint32_t p)
{
(void)p;
......@@ -465,3 +468,4 @@ pwm_exist(uint8 channel){
}
return false;
}
#endif
......@@ -9,6 +9,7 @@
*
* Philip Gladstone, N1DQ
*/
#ifdef __ESP8266__
#include "platform.h"
#include "c_types.h"
......@@ -319,3 +320,4 @@ int rotary_getpos(uint32_t channel)
return GET_LAST_STATUS(d).pos;
}
#endif
/* Sigma-delta only on the ESP8266 */
#ifdef __ESP8266__
#include "driver/sigma_delta.h"
#include "esp8266/gpio_register.h"
......@@ -32,3 +34,5 @@ void sigma_delta_set_prescale_target( sint16 prescale, sint16 target )
(GPIO_SIGMA_DELTA_PRESCALE_SET(prescale) & prescale_mask) |
(GPIO_SIGMA_DELTA_TARGET_SET(target) & target_mask));
}
#endif
#ifdef __ESP8266__
#include "driver/spi.h"
#include "platform.h"
......@@ -499,7 +500,6 @@ static uint8 idx = 0;
static uint8 spi_flg = 0;
#define SPI_MISO
#define SPI_QUEUE_LEN 8
os_event_t * spiQueue;
#define MOSI 0
#define MISO 1
#define STATUS_R_IN_WR 2
......@@ -585,6 +585,7 @@ void spi_slave_isr_handler(void *para)
#ifdef SPI_SLAVE_DEBUG
os_event_t * spiQueue;
void ICACHE_FLASH_ATTR
set_miso_data()
......@@ -677,4 +678,4 @@ void ICACHE_FLASH_ATTR
#endif
#endif
......@@ -29,7 +29,7 @@
// For event signalling
static task_handle_t sig = 0;
static task_handle_t tsk = 0;
// UartDev is defined and initialized in rom code.
extern UartDevice UartDev;
......@@ -270,8 +270,8 @@ uart0_rx_intr_handler(void *para)
got_input = true;
}
if (got_input && sig)
task_post_low (sig, false);
if (got_input && tsk)
task_post_low (tsk, false);
}
static void
......@@ -310,13 +310,13 @@ uart_stop_autobaud()
* Parameters : UartBautRate uart0_br - uart0 bautrate
* UartBautRate uart1_br - uart1 bautrate
* uint8 task_prio - task priority to signal on input
* os_signal_t sig_input - signal to post
* task_handle_t tsk_input - task to notify
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
uart_init(UartBautRate uart0_br, UartBautRate uart1_br, os_signal_t sig_input)
uart_init(UartBautRate uart0_br, UartBautRate uart1_br, task_handle_t tsk_input)
{
sig = sig_input;
tsk = tsk_input;
// rom use 74880 baut_rate, here reinitialize
UartDev.baut_rate = uart0_br;
......
......@@ -12,6 +12,9 @@
* FIXME: support null characters in responses.
*/
// No espconn on ESP32
#ifdef __ESP8266__
#include "osapi.h"
#include "user_interface.h"
#include "espconn.h"
......@@ -553,3 +556,4 @@ void ICACHE_FLASH_ATTR http_callback_example( char * response, int http_status,
os_printf( "response=%s<EOF>\n", response );
}
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment