Skip to content

Commit

Permalink
Include @cnlohr's sdk and expand readme (#51)
Browse files Browse the repository at this point in the history
* Start a new project via `make project`

* Fix minor error cleaning rules

* Add missing 'user_rf_cal_sector_set()'

* Update user_main.c

Use recommended setup for cal flash map.

* Add sdk, 'make gitproject', inprove 'make project'

Squashed commit of the following:

commit 39574c3
Author: con-f-use <con-f-use@gmx.net>
Date:   Fri Mar 3 14:37:31 2017 +0100

    Add recursive pulling to README

commit fe86201
Author: con-f-use <con-f-use@gmx.net>
Date:   Fri Mar 3 14:33:21 2017 +0100

    Small cleanups

commit a77ffd9
Author: con-f-use <con-f-use@gmx.net>
Date:   Fri Mar 3 13:40:41 2017 +0100

    Fix them separators

    Makefiles...

commit 50c1085
Author: con-f-use <con-f-use@gmx.net>
Date:   Fri Mar 3 13:25:31 2017 +0100

    Do not require Bash shell

commit 96f5c52
Author: con-f-use <con-f-use@gmx.net>
Date:   Thu Mar 2 12:44:01 2017 +0100

    Add 'make gitproject' and reflect changes in readme

    Needs to be tested!
    Also added the sdk as a submodule. Still need to change paths in the makefiles and test it.

    DO NOT USE THIS COMMIT

* readme: typos

* Minor updates to the readme

Documentation of the commands in `./fwsrc/commonservies.c` still to come

* Document commands in `./commonsercies.c`

* Fix typo in README.md
  • Loading branch information
con-f-use committed May 12, 2017
1 parent 0946dfc commit aa8ba2f
Show file tree
Hide file tree
Showing 11 changed files with 454 additions and 74 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "toolchain/esp_nonos_sdk"]
path = toolchain/esp_nonos_sdk
url = https://github.com/cnlohr/esp_nonos_sdk.git
2 changes: 1 addition & 1 deletion Makefile.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include user.cfg

ifndef TARGET
$(info Modules were not checked out... use git clone --recursive in the future. Pulling now.)
$(shell git submodule update --init --recursive)
$(shell git submodule update --init --recursive 2>/dev/null)
endif

# Example for a custom rule.
Expand Down
221 changes: 178 additions & 43 deletions README.md

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions common.mf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

GCC_FOLDER = $(ESP_ROOT)/xtensa-lx106-elf
ESPTOOL_PY = $(ESP_ROOT)/esptool/esptool.py
SDK ?= $(ESP_ROOT)/sdk
SDK ?= $(PWD)/esp82xx/toolchain/esp_nonos_sdk

XTLIB = $(SDK)/lib
XTGCCLIB = $(GCC_FOLDER)/lib/gcc/xtensa-lx106-elf/$(ESP_GCC_VERS)/libgcc.a
Expand All @@ -20,6 +20,8 @@ CC = $(PREFIX)gcc
LD = $(PREFIX)ld
AR = $(PREFIX)ar
CP = cp
LINKERSCRIPT ?= esp82xx/toolchain/ld/linkerscript.ld
#LINKERSCRIPT ?= $(SDK)/ld/eagle.app.v6.ld

SLOWTICK_MS ?= 50

Expand All @@ -30,19 +32,19 @@ SLOWTICK_MS ?= 50
OPTS += -DWEB_PORT=$(WEB_PORT) -DCOM_PORT=$(COM_PORT) -DBACKEND_PORT=$(BACKEND_PORT) $(EXTRAOPTS) -DSLOWTICK_MS=$(SLOWTICK_MS)
PAGE_SCRIPTS?=$(wildcard web/page/*.js)

# Mechanism for getting SDK/xtensa compiler paths from shell variables
SDK_DEFAULT = $(HOME)/esp8266/esp-open-sdk
# Getting xtensa compiler paths from shell variables
ESP_DEFAULT = $(HOME)/esp8266/esp-open-sdk
ESP_ROOT := $(shell echo "$$ESP_ROOT")
ifeq ($(strip $(ESP_ROOT)),)
$(warning Warning: No shell variable 'ESP_ROOT', using '$(SDK_DEFAULT)')
ESP_ROOT := $(SDK_DEFAULT)
$(warning Warning: No shell variable 'ESP_ROOT', using '$(ESP_DEFAULT)')
ESP_ROOT := $(ESP_DEFAULT)
endif

# Version related stuff
VERSION := $(shell git describe --abbrev=5 --dirty=-dev --always --tags)
VERSION := $(shell git describe --abbrev=5 --dirty=-dev --always --tags 2>/dev/null || echo "unknown")
VERSSTR := "Version: $(VERSION) - Build $(shell date -R) with $(OPTS)"
PROJECT_NAME := $(notdir $(shell git rev-parse --show-toplevel))
PROJECT_URL := $(subst .com:,.com/,$(subst .git,,$(subst git@,https://,$(shell git config --get remote.origin.url))))
PROJECT_NAME := $(notdir $(shell git rev-parse --show-toplevel 2>/dev/null || echo "exp82xx-project"))
PROJECT_URL := $(subst .com:,.com/,$(subst .git,,$(subst git@,https://,$(shell git config --get remote.origin.url 2>/dev/null || echo "https://github.com/con-f-use/esp82xx-basic.git"))))

# Newline and space hacks
define \n
Expand Down
28 changes: 28 additions & 0 deletions fwsrc/user/custom_commands.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//Copyright 2015 <>< Charles Lohr, see LICENSE file.

#include <commonservices.h>
#include "esp82xxutil.h"

int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata, unsigned short len) {
char * buffend = buffer;

switch( pusrdata[1] ) {
// Custom command test
case 'C': case 'c':
buffend += ets_sprintf( buffend, "CC" );
printf("CC");
return buffend-buffer;
break;

// Echo to UART
case 'E': case 'e':
if( retsize <= len ) return -1;
ets_memcpy( buffend, &(pusrdata[2]), len-2 );
buffend[len-2] = '\0';
printf( "%s\n", buffend );
return len-2;
break;
}

return -1;
}
165 changes: 165 additions & 0 deletions fwsrc/user/user_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
//Copyright 2015 <>< Charles Lohr, see LICENSE file.

#include "mem.h"
#include "c_types.h"
#include "user_interface.h"
#include "ets_sys.h"
#include "uart.h"
#include "osapi.h"
#include "espconn.h"
#include "esp82xxutil.h"
#include "commonservices.h"
#include "vars.h"
#include <mdns.h>

#define procTaskPrio 0
#define procTaskQueueLen 1

static volatile os_timer_t some_timer;
static struct espconn *pUdpServer;
usr_conf_t * UsrCfg = (usr_conf_t*)(SETTINGS.UserData);

//int ICACHE_FLASH_ATTR StartMDNS();


void user_rf_pre_init(void) { /*nothing*/ }



char * strcat( char * dest, char * src )
{
return strcat(dest, src );
}



//Tasks that happen all the time.

os_event_t procTaskQueue[procTaskQueueLen];

static void ICACHE_FLASH_ATTR procTask(os_event_t *events)
{
CSTick( 0 );
system_os_post(procTaskPrio, 0, 0 );
}

//Timer event.
static void ICACHE_FLASH_ATTR myTimer(void *arg)
{
CSTick( 1 ); // Send a one to uart
}


//Called when new packet comes in.
static void ICACHE_FLASH_ATTR
udpserver_recv(void *arg, char *pusrdata, unsigned short len)
{
struct espconn *pespconn = (struct espconn *)arg;

uart0_sendStr("X");
}

void ICACHE_FLASH_ATTR charrx( uint8_t c )
{
//Called from UART.
}

void user_init(void)
{
uart_init(BIT_RATE_115200, BIT_RATE_115200);

uart0_sendStr("\r\nesp82XX Web-GUI\r\n" VERSSTR "\b");

//Uncomment this to force a system restore.
// system_restore();

CSSettingsLoad( 0 );
CSPreInit();

pUdpServer = (struct espconn *)os_zalloc(sizeof(struct espconn));
ets_memset( pUdpServer, 0, sizeof( struct espconn ) );
espconn_create( pUdpServer );
pUdpServer->type = ESPCONN_UDP;
pUdpServer->proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp));
pUdpServer->proto.udp->local_port = COM_PORT;
espconn_regist_recvcb(pUdpServer, udpserver_recv);

if( espconn_create( pUdpServer ) )
{
while(1) { uart0_sendStr( "\r\nFAULT\r\n" ); }
}

CSInit();

//Set GPIO16 for INput
WRITE_PERI_REG(PAD_XPD_DCDC_CONF,
(READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); // mux configuration for XPD_DCDC and rtc_gpio0 connection

WRITE_PERI_REG(RTC_GPIO_CONF,
(READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); //mux configuration for out enable

WRITE_PERI_REG(RTC_GPIO_ENABLE,
READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe); //out disable

SetServiceName( "espcom" );
AddMDNSName( "esp82xx" );
AddMDNSName( "espcom" );
AddMDNSService( "_http._tcp", "An ESP82XX Webserver", WEB_PORT );
AddMDNSService( "_espcom._udp", "ESP82XX Comunication", COM_PORT );
AddMDNSService( "_esp82xx._udp", "ESP82XX Backend", BACKEND_PORT );

//Add a process
system_os_task(procTask, procTaskPrio, procTaskQueue, procTaskQueueLen);

//Timer example
os_timer_disarm(&some_timer);
os_timer_setfn(&some_timer, (os_timer_func_t *)myTimer, NULL);
os_timer_arm(&some_timer, 100, 1);

printf( "Boot Ok.\n" );

wifi_set_sleep_type(LIGHT_SLEEP_T);
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);

system_os_post(procTaskPrio, 0, 0 );
}


//There is no code in this project that will cause reboots if interrupts are disabled.
void EnterCritical() { }

void ExitCritical() { }


//For SDK 2.0.0 only.
uint32 ICACHE_FLASH_ATTR user_rf_cal_sector_set(void)
{
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;

switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 8;
break;

case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
break;

case FLASH_SIZE_16M_MAP_512_512:
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
break;

case FLASH_SIZE_32M_MAP_512_512:
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
break;

default:
rf_cal_sec = 0;
break;
}

return rf_cal_sec;
}
19 changes: 19 additions & 0 deletions fwsrc/user/vars.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#ifndef _VARS_H
#define _VARS_H

#include "commonservices.h"

#define BUILD_BUG_ON(condition) extern int build_bug_on[!(condition)-1]

typedef struct {
uint8_t ptrn; ///< Pattern to display on connected leds
uint16_t nled; ///< Number of connected LEDs
uint8_t clr[3]; ///< Color data (used for PATTERN_CONST)
// ... add more here ...
} __attribute__((__packed__)) usr_conf_t;
BUILD_BUG_ON(sizeof(usr_conf_t)>USERDATA_SIZE); // Produce invalid code if struct is too large ("best" way of size checking at compile time)

extern usr_conf_t * UsrCfg; ///< User data preserved between esp boots

#endif
69 changes: 48 additions & 21 deletions main.mf
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
define USAGE
Usage: make [command] [VARIABLES]

all....... Build the binaries
debug..... Build a .map and .lst file. Useful for seeing what's going on
behind the scenes.
burn ..... Write firmware to chip using a regular serial port
burnweb .. Write data for the Web-GUI to chip using a regular serial
port
netburn .. Same as 'burn' but transfer firmware over the network rather
than the serial port (if supported by the existing firmware
on the chip)
netweb ... Same as 'burnweb' but transfer data over network if supported
by firmware currently on the chip
getips ... Get a list with IPs of esp82xxs connected to your network
usbburn .. Burn via PRE-RELEASE USB loader (will probably change)
usbweb ... Burn webpage by PRE-RELEASE USB loader (will probably change)


More commands: all, clean, purge, dumprom
all......... Build the binaries
debug....... Build a .map and .lst file. Useful for seeing what's going on
behind the scenes.
burn ....... Write firmware to chip using a regular serial port
burnweb .... Write data for the Web-GUI to chip using a regular serial
port
netburn .... Same as 'burn' but transfer firmware over the network rather
than the serial port (if supported by the existing firmware
on the chip)
netweb ..... Same as 'burnweb' but transfer data over network if supported
by firmware currently on the chip
getips ..... Get a list with IPs of esp82xxs connected to your network
project .... Make the current working direcotry an esp82xx project
gitproject . Same as 'make project' but also initialiezes the current folder
as git repository and pushes it to GIT_ORIGIN.
Example:
make gitproject GIT_ORIGIN=https://github.com/USER/YREPO.git
usbburn .... Burn via PRE-RELEASE USB loader (will probably change)
usbweb ..... Burn webpage by PRE-RELEASE USB loader (will probably change)

More commands: all, clean, purge, dumprom, cleanproject
endef

.PHONY : all clean cleanall netburn burnweb burn $(BIN_TARGET) netweb getips help
.PHONY : all clean purge netburn burnweb burn $(BIN_TARGET) netweb getips help project gitproject cleanproject


FW_FILE1 = image.elf-0x00000.bin
FW_FILE2 = image.elf-0x40000.bin
Expand All @@ -44,8 +49,6 @@ ifneq ($(CUSTOMPP), 1)
endif

INCL = $(SDK)/include esp82xx/include .
LINKERSCRIPT ?= esp82xx/ld/linkerscript.ld
#LINKERSCRIPT ?= $(SDK)/ld/eagle.app.v6.ld

CFLAGS = -mlongcalls -Os $(addprefix -I,$(INCL) $(call uniq, $(patsubst %/,%,$(dir $(SRCS))))) $(OPTS) -DVERSSTR='$(VERSSTR)'

Expand Down Expand Up @@ -128,7 +131,7 @@ wipechip :
dd if=/dev/zero of=/tmp/zeroes bs=1M count=1
($(ESPTOOL_PY) $(FWBURNFLAGS) --port $(PORT) write_flash 0x0 /tmp/zeroes)||(true)

getips:
getips :
$(info Detecting possible IPs for ESP82XX modules...)
$(info Needs 'nmap' and takes some time especiallay if none are connected)
sudo nmap -sP 192.168.0.0/24 | grep -iP "espressif|esp" -B2 | grep -oP "(\d{1,3}\.){3,3}\d\d{1,3}"
Expand All @@ -146,3 +149,27 @@ purge : clean
bump_submodule :
cd esp82xx; git pull origin master; cd ..

Makefile : esp82xx/Makefile.example
user.cfg : esp82xx/user.cfg.example
web/page/index.html : esp82xx/web/page/index.html
web/page/example.js : esp82xx/web/page/example.js

Makefile user.cfg web/page/index.html web/page/example.js :
mkdir -p web/page user; \
cp -n $< $@; \
touch $@

project : Makefile user.cfg web/page/index.html web/page/example.js
ln -s $(patsubst %,../../%,$(wildcard esp82xx/web/page/jquery-*)) ../../esp82xx/web/page/menuinterface.js web/page/ 2>/dev/null; \
ln -s $(patsubst %,../%,$(wildcard esp82xx/web/*)) web/ 2>/dev/null; \
cp -rn esp82xx/fwsrc/user/ .;

gitproject: project
git init .
git add .
git remote add origin $(GIT_ORIGIN)
git commit -m 'Initial commit'
git push

cleanproject :
$(RM) -r use* web/
1 change: 1 addition & 0 deletions toolchain/esp_nonos_sdk
Submodule esp_nonos_sdk added at 7d66ff
File renamed without changes.
2 changes: 1 addition & 1 deletion user.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ COM_PORT = 7777
BACKEND_PORT = 7878
PAGE_OFFSET = 65536 # 1048576

SDK_DEFAULT = $(HOME)/esp8266/esp-open-sdk
ESP_DEFAULT = $(HOME)/esp8266/esp-open-sdk
ESP_GCC_VERS = 4.8.5

OPTS += -DICACHE_FLASH
Expand Down

3 comments on commit aa8ba2f

@cnlohr
Copy link
Owner

@cnlohr cnlohr commented on aa8ba2f May 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@con-f-use Considering you're pulling in my copy of the sdk, do we really want the default to be ~/esp8266/esp-open-sdk?

@con-f-use
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... I don't know where that line came from all of a sudden.
None the less, it says SDK ?= $(PWD)/esp82xx/toolchain/esp_nonos_sdk in common.mf so it will default to using your version of the sdk.

@cnlohr
Copy link
Owner

@cnlohr cnlohr commented on aa8ba2f May 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know what the best approach would be here :-/ I think removing the reference to ~/ from esp82xx is probably the right move.

Please sign in to comment.