Skip to content

Commit 2ae269c

Browse files
committed
Build system changes for the ESP8266 board.
1 parent 4eeb12d commit 2ae269c

File tree

2 files changed

+146
-1
lines changed

2 files changed

+146
-1
lines changed

Makefile

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
# MINISTM32_STRIVE=1
4747
# MINISTM32_ANGLED_VE=1
4848
# MINISTM32_ANGLED_VG=1
49+
# ESP8266_BOARD=1 # ESP8266 from Espressif
4950
# Or nothing for standard linux compile
5051
#
5152
# Also:
@@ -60,7 +61,6 @@
6061
#
6162
#
6263
# WIZNET=1 # If compiling for a non-linux target that has internet support, use WIZnet support, not TI CC3000
63-
6464
ifndef SINGLETHREAD
6565
MAKEFLAGS=-j5 # multicore
6666
endif
@@ -417,6 +417,20 @@ BOARD=LCTECH_STM32F103RBT6
417417
STLIB=STM32F10X_MD
418418
PRECOMPILED_OBJS+=$(ROOT)/targetlibs/stm32f1/lib/startup_stm32f10x_md.o
419419
OPTIMIZEFLAGS+=-Os
420+
else ifdef ESP8266_BOARD
421+
USE_NET=1
422+
EMBEDDED=1
423+
BOARD=ESP8266_BOARD
424+
OPTIMIZEFLAGS+=-Os
425+
LIBS += -lc -lgcc -lhal -lphy -lpp -lnet80211 -llwip -lwpa -lmain
426+
CFLAGS+=-std=gnu99 \
427+
-Wno-maybe-uninitialized -Wno-old-style-declaration -Wno-conversion -Wno-unused-variable \
428+
-Wno-unused-parameter -Wno-ignored-qualifiers -Wno-discarded-qualifiers -Wno-float-conversion \
429+
-Wno-parentheses -Wno-type-limits -Wno-unused-function -Wno-unused-value \
430+
-fno-builtin -fno-strict-aliasing -fno-inline-functions \
431+
-Wl,EL -nostdlib \
432+
-mlongcalls -mtext-section-literals \
433+
-D__ETS__ -DICACHE_FLASH
420434
else
421435
ifeq ($(shell uname -m),armv6l)
422436
RASPBERRYPI=1 # just a guess
@@ -519,10 +533,14 @@ ifndef LINUX
519533
ifdef WIZNET
520534
USE_WIZNET=1
521535
else
536+
ifdef ESP8266_BOARD
537+
USE_ESP8266_BOARD=1
538+
else
522539
USE_CC3000=1
523540
endif
524541
endif
525542
endif
543+
endif
526544

527545
ifdef DEBUG
528546
#OPTIMIZEFLAGS=-Os -g
@@ -777,6 +795,14 @@ libs/network/js/network_js.c
777795
libs/network/wiznet/Ethernet/socket.c \
778796
libs/network/wiznet/W5500/w5500.c
779797
endif
798+
799+
ifdef USE_ESP8266
800+
DEFINES += -DUSE_ESP8266
801+
WRAPPERSOURCES += libs/network/esp8266/jswrap_esp8266.c
802+
INCLUDE += -I$(ROOT)/libs/network/esp8266
803+
SOURCES += \
804+
libs/network/esp8266/network_esp8266.c
805+
endif
780806
endif
781807

782808
ifdef USE_TV
@@ -1217,6 +1243,51 @@ ifdef NRF5X
12171243
LDFLAGS += --specs=nano.specs -lc -lnosys
12181244
endif # NRF5X
12191245

1246+
#
1247+
# Definitions for the build of the ESP8266
1248+
#
1249+
ifdef ESP8266_BOARD
1250+
# The Root of the ESP8266_SDK distributed by Espressif
1251+
# This must be supplied as a Make environment variable.
1252+
ifndef ESP8266_SDK_ROOT
1253+
$(error, "The ESP8266_SDK_ROOT variable must be set")
1254+
endif
1255+
1256+
# The pefix for the xtensa toolchain
1257+
CCPREFIX=xtensa-lx106-elf-
1258+
1259+
# Extra flags passed to the linker
1260+
LDFLAGS += -L$(ESP8266_SDK_ROOT)/lib \
1261+
-Ttargets/esp8266/eagle.app.v6.0x10000.ld \
1262+
-nostdlib \
1263+
-Wl,--no-check-sections \
1264+
-u call_user_start \
1265+
-Wl,-static
1266+
1267+
# Extra source files specific to the ESP8266 board
1268+
SOURCES += targets/esp8266/uart.c \
1269+
targets/esp8266/user_main.c \
1270+
targets/esp8266/jshardware.c \
1271+
targets/esp8266/esp8266_board_utils.c \
1272+
libs/network/esp8266/network_esp8266.c
1273+
1274+
# The tool used for building the firmware and flashing
1275+
ESPTOOL_CK ?= esptool-ck
1276+
ESPTOOL ?= esptool
1277+
1278+
# Extra include directories specific to the ESP8266
1279+
INCLUDE += -I$(ESP8266_SDK_ROOT)/include \
1280+
-I$(ROOT)/targets/esp8266 \
1281+
-I$(ROOT)/libs/network/esp8266
1282+
1283+
WRAPPERSOURCES += libs/network/esp8266/jswrap_esp8266.c
1284+
1285+
# Specify the defines
1286+
DEFINES += -DXTENSA -DUSE_ESP8266_BOARD
1287+
1288+
# End of ESP8266 definitions
1289+
endif # ESP8266_BOARD
1290+
12201291
export CC=$(CCPREFIX)gcc
12211292
export LD=$(CCPREFIX)gcc
12221293
export AR=$(CCPREFIX)ar
@@ -1263,7 +1334,11 @@ $(PLATFORM_CONFIG_FILE): boards/$(BOARD).py scripts/build_platform_config.py
12631334
$(Q)python scripts/build_platform_config.py $(BOARD)
12641335

12651336
compile=$(CC) $(CFLAGS) $(DEFINES) $< -o $@
1337+
ifndef ESP8266_BOARD
12661338
link=$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
1339+
else
1340+
link=$(LD) $(LDFLAGS) -o $@ -Wl,--start-group $(OBJS) $(LIBS) -Wl,--end-group
1341+
endif
12671342
obj_dump=$(OBJDUMP) -x -S $(PROJ_NAME).elf > $(PROJ_NAME).lst
12681343
obj_to_bin=$(OBJCOPY) -O $1 $(PROJ_NAME).elf $(PROJ_NAME).$2
12691344

@@ -1275,6 +1350,9 @@ quiet_obj_to_bin= GEN $(PROJ_NAME).$2
12751350
%.o: %.c $(PLATFORM_CONFIG_FILE) $(PININFOFILE).h
12761351
@echo $($(quiet_)compile)
12771352
@$(call compile)
1353+
ifdef ESP8266_BOARD
1354+
$(OBJCOPY) --rename-section .text=.irom0.text --rename-section .literal=.irom0.literal $@
1355+
endif
12781356

12791357
.cpp.o: $(PLATFORM_CONFIG_FILE) $(PININFOFILE).h
12801358
@echo $($(quiet_)compile)
@@ -1316,7 +1394,16 @@ ifndef TRAVIS
13161394
bash scripts/check_size.sh $(PROJ_NAME).bin
13171395
endif
13181396

1397+
ifndef ESP8266_BOARD
13191398
proj: $(PROJ_NAME).lst $(PROJ_NAME).bin $(PROJ_NAME).hex
1399+
else
1400+
proj: $(PROJ_NAME).elf
1401+
endif
1402+
1403+
ifdef ARDUINO_AVR
1404+
proj: $(PROJ_NAME).hex
1405+
endif
1406+
13201407
#proj: $(PROJ_NAME).lst $(PROJ_NAME).hex $(PROJ_NAME).srec $(PROJ_NAME).bin
13211408

13221409
flash: all
@@ -1330,6 +1417,16 @@ else ifdef OLIMEXINO_STM32_BOOTLOADER
13301417
else ifdef NUCLEO
13311418
if [ -d "/media/$(USER)/NUCLEO" ]; then cp $(PROJ_NAME).bin /media/$(USER)/NUCLEO;sync; fi
13321419
if [ -d "/media/NUCLEO" ]; then cp $(PROJ_NAME).bin /media/NUCLEO;sync; fi
1420+
else ifdef ESP8266_BOARD
1421+
ifndef COMPORT
1422+
$(error, "In order to flash, we need to have the COMPORT variable defined")
1423+
endif
1424+
# Handle ESP8266 flashing
1425+
@echo Disass: $(OBJDUMP) -d -l -x $(PROJ_NAME).elf
1426+
-$(Q)$(ESPTOOL_CK) -eo $(PROJ_NAME).elf -bo ESP8266_0x00000.bin -bs .text -bs .data -bs .rodata -bs .iram0.text -bc -ec
1427+
-$(Q)$(ESPTOOL_CK) -eo $(PROJ_NAME).elf -es .irom0.text ESP8266_0x10000.bin -ec
1428+
-$(Q)$(ESPTOOL) --port $(COMPORT) --baud 115200 write_flash --flash_freq 40m --flash_mode qio --flash_size 4m 0x00000 ESP8266_0x00000.bin 0x10000 ESP8266_0x10000.bin
1429+
# End of handle ESP8266 flashing
13331430
else
13341431
echo ST-LINK flash
13351432
st-flash --reset write $(PROJ_NAME).bin $(BASEADDRESS)

boards/ESP8266_BOARD.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/false
2+
# This file is part of Espruino, a JavaScript interpreter for Microcontrollers
3+
#
4+
# Copyright (C) 2013 Gordon Williams <[email protected]>
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
#
10+
# ----------------------------------------------------------------------------------------
11+
# This file contains information for a specific board - the available pins, and where LEDs,
12+
# Buttons, and other in-built peripherals are. It is used to build documentation as well
13+
# as various source and header files for Espruino.
14+
# ----------------------------------------------------------------------------------------
15+
16+
import pinutils;
17+
info = {
18+
'name' : "ESP8266",
19+
'default_console' : "EV_SERIAL1",
20+
'variables' : 1023,
21+
'binary_name' : 'espruino_esp8266_board',
22+
};
23+
chip = {
24+
'part' : "ESP8266",
25+
'family' : "ESP8266",
26+
'package' : "",
27+
'ram' : 80,
28+
'flash' : 512,
29+
'speed' : 80,
30+
'usart' : 1,
31+
'spi' : 0,
32+
'i2c' : 0,
33+
'adc' : 1,
34+
'dac' : 0,
35+
};
36+
# left-right, or top-bottom order
37+
board = {
38+
};
39+
devices = {
40+
};
41+
42+
board_css = """
43+
""";
44+
45+
def get_pins():
46+
pins = pinutils.generate_pins(0,7)
47+
# just fake pins D0 .. D7
48+
return pins

0 commit comments

Comments
 (0)