1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-08-09 22:24:14 +03:00

Merge branch 'ficeto-esp8266' into esp8266

* ficeto-esp8266:
  add flash splits depending on the flash size
  use WDT_RESET macro in spiffs_flashmem methods
  fix reading bytes from incoming POST upload
  double
  add flash frequency and mode options
  mount spiffs on boot
  blah
  cast it
  make sure write return a positive or zero value
  fix FSFile template
  add toolchain to ignore
This commit is contained in:
Ivan Grokhotkov
2015-05-15 17:57:20 +03:00
17 changed files with 159 additions and 36 deletions

2
.gitignore vendored
View File

@@ -58,3 +58,5 @@ avr-toolchain-*.zip
/hardware/tools/listComPorts.exe
build/macosx/esptool-*-osx.zip
build/macosx/dist/osx-xtensa-lx106-elf.tgz

View File

@@ -1,6 +1,8 @@
menu.UploadSpeed=Upload Speed
menu.CpuFrequency=CPU Frequency
menu.FlashSize=Flash size
menu.FlashSize=Flash Size
menu.FlashFreq=Flash Frequency
menu.FlashMode=Flash Mode
##############################################################
generic.name=Generic ESP8266 Module
@@ -21,6 +23,7 @@ generic.build.variant=generic
generic.build.flash_mode=qio
generic.build.flash_size=512K
generic.build.flash_freq=40
generic.build.flash_ld=eagle.flash.512k.ld
generic.menu.CpuFrequency.80=80 MHz
generic.menu.CpuFrequency.80.build.f_cpu=80000000L
@@ -48,14 +51,37 @@ generic.menu.UploadSpeed.921600.upload.speed=921600
generic.menu.FlashSize.512K=512K
generic.menu.FlashSize.512K.build.flash_size=512K
generic.menu.FlashSize.512K.build.flash_ld=eagle.flash.512k.ld
generic.menu.FlashSize.256K=256K
generic.menu.FlashSize.256K.build.flash_size=256K
generic.menu.FlashSize.256K.build.flash_ld=eagle.flash.256k.ld
generic.menu.FlashSize.1M=1M
generic.menu.FlashSize.1M.build.flash_size=1M
generic.menu.FlashSize.1M.build.flash_ld=eagle.flash.1m.ld
generic.menu.FlashSize.2M=2M
generic.menu.FlashSize.2M.build.flash_size=2M
generic.menu.FlashSize.2M.build.flash_ld=eagle.flash.2m.ld
generic.menu.FlashSize.4M=4M
generic.menu.FlashSize.4M.build.flash_size=4M
generic.menu.FlashSize.4M.build.flash_ld=eagle.flash.4m.ld
generic.menu.FlashFreq.40=40MHz
generic.menu.FlashFreq.40.build.flash_freq=40
generic.menu.FlashFreq.20=20MHz
generic.menu.FlashFreq.20.build.flash_freq=20
generic.menu.FlashFreq.26=26.7MHz
generic.menu.FlashFreq.26.build.flash_freq=26.7
generic.menu.FlashFreq.80=80MHz
generic.menu.FlashFreq.80.build.flash_freq=80
generic.menu.FlashMode.qio=QIO
generic.menu.FlashMode.qio.build.flash_mode=qio
generic.menu.FlashMode.qout=QOUT
generic.menu.FlashMode.qout.build.flash_mode=qout
generic.menu.FlashMode.dio=DIO
generic.menu.FlashMode.dio.build.flash_mode=dio
generic.menu.FlashMode.dout=DOUT
generic.menu.FlashMode.dout.build.flash_mode=dout
##############################################################
modwifi.name=Olimex MOD-WIFI-ESP8266(-DEV)
@@ -77,6 +103,7 @@ modwifi.build.variant=generic
modwifi.build.flash_mode=qio
modwifi.build.flash_size=2M
modwifi.build.flash_freq=40
modwifi.build.flash_ld=eagle.flash.2m.ld
modwifi.menu.CpuFrequency.80=80 MHz
modwifi.menu.CpuFrequency.80.build.f_cpu=80000000L
@@ -122,6 +149,7 @@ nodemcu.build.variant=nodemcu
nodemcu.build.flash_mode=qio
nodemcu.build.flash_size=4M
nodemcu.build.flash_freq=40
nodemcu.build.flash_ld=eagle.flash.4m.ld
nodemcu.menu.CpuFrequency.80=80 MHz
nodemcu.menu.CpuFrequency.80.build.f_cpu=80000000L
@@ -168,6 +196,7 @@ nodemcu.menu.FlashSize.4M.build.flash_size=4M
# wifio.build.flash_mode=qio
# wifio.build.flash_size=512K
# wifio.build.flash_freq=40
# wifio.build.flash_ld=eagle.flash.512k.ld
#
# wifio.menu.CpuFrequency.80=80MHz
# wifio.menu.CpuFrequency.80.build.f_cpu=80000000L

View File

@@ -38,7 +38,7 @@ extern "C" {
#include "pgmspace.h"
#include "esp8266_peri.h"
#include "twi.h"
#include "spiffs/spiffs.h"
//#include "spiffs/spiffs.h"
void yield(void);

View File

@@ -162,7 +162,8 @@ int FSFile::available() {
size_t FSFile::write(const uint8_t *buf, size_t size){
if (! _file) return 0;
return SPIFFS_write(&_filesystemStorageHandle, _file, (uint8_t *)buf, size);
int res = SPIFFS_write(&_filesystemStorageHandle, _file, (uint8_t *)buf, size);
return (res > 0)?(size_t)res:0;
}
size_t FSFile::write(uint8_t val) {

View File

@@ -61,13 +61,15 @@ public:
size_t bytesWritten = 0;
while (true){
size_t available = src.available();
if(!available)
return bytesWritten;
size_t willWrite = (available < bufferSize) ? available : bufferSize;
src.read(obuf, willWrite);
size_t cb = write(obuf, willWrite);
bytesWritten += cb;
if (cb != willWrite) {
return bytesWritten;
}
bytesWritten += cb;
}
return bytesWritten;
}
@@ -78,7 +80,7 @@ public:
class FSClass {
private:
bool _mounted;
bool _mounted = false;
public:
bool mount();

View File

@@ -78,4 +78,5 @@ void init() {
timer1_isr_init();
os_timer_setfn(&micros_overflow_timer, (os_timer_func_t*) &micros_overflow_tick, 0);
os_timer_arm(&micros_overflow_timer, 60000, REPEAT);
spiffs_mount();
}

View File

@@ -20,7 +20,6 @@
#include "stddef.h"
#include "osapi.h"
#include "ets_sys.h"
#include <user_config.h>
// ----------- >8 ------------
#define IRAM_ATTR __attribute__((section(".iram.text")))
#define STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed))

View File

@@ -1,4 +1,5 @@
#include "flashmem.h"
#include "esp8266_peri.h"
// Based on NodeMCU platform_flash
// https://github.com/nodemcu/nodemcu-firmware
@@ -184,7 +185,7 @@ uint32_t flashmem_write_internal( const void *from, uint32_t toaddr, uint32_t si
return 0;
os_memcpy(apbuf, from, size);
}
WRITE_PERI_REG(0x60000914, 0x73);
WDT_RESET();
r = spi_flash_write(toaddr, apbuf?(uint32 *)apbuf:(uint32 *)from, size);
if(apbuf)
os_free(apbuf);
@@ -200,7 +201,7 @@ uint32_t flashmem_read_internal( void *to, uint32_t fromaddr, uint32_t size )
{
fromaddr -= INTERNAL_FLASH_START_ADDRESS;
SpiFlashOpResult r;
WRITE_PERI_REG(0x60000914, 0x73);
WDT_RESET();
r = spi_flash_read(fromaddr, (uint32 *)to, size);
if(SPI_FLASH_RESULT_OK == r)
return size;

View File

@@ -83,6 +83,7 @@ protected:
static const char* _responseCodeToString(int code);
void _parseForm(WiFiClient& client, String boundary, uint32_t len);
void _uploadWriteByte(uint8_t b);
uint8_t _uploadReadByte(WiFiClient& client);
struct RequestHandler;
struct RequestArgument {

View File

@@ -214,12 +214,22 @@ void ESP8266WebServer::_uploadWriteByte(uint8_t b){
_currentUpload.buf[_currentUpload.currentSize++] = b;
}
uint8_t ESP8266WebServer::_uploadReadByte(WiFiClient& client){
int res = client.read();
if(res == -1){
while(!client.available())
yield();
res = client.read();
}
return (uint8_t)res;
}
void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
#ifdef DEBUG
DEBUG_OUTPUT.print("Parse Form: Boundary: ");
DEBUG_OUTPUT.print(boundary);
DEBUG_OUTPUT.print("Length: ");
DEBUG_OUTPUT.print(" Length: ");
DEBUG_OUTPUT.println(len);
#endif
String line;
@@ -249,17 +259,17 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
argFilename = argName.substring(nameStart+2, argName.length() - 1);
argName = argName.substring(0, argName.indexOf('"'));
argIsFile = true;
#ifdef DEBUG
#ifdef DEBUG
DEBUG_OUTPUT.print("PostArg FileName: ");
DEBUG_OUTPUT.println(argFilename);
#endif
#endif
//use GET to set the filename if uploading using blob
if (argFilename == "blob" && hasArg("filename")) argFilename = arg("filename");
}
#ifdef DEBUG
#ifdef DEBUG
DEBUG_OUTPUT.print("PostArg Name: ");
DEBUG_OUTPUT.println(argName);
#endif
#endif
argType = "text/plain";
line = client.readStringUntil('\r');
client.readStringUntil('\n');
@@ -269,10 +279,10 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
client.readStringUntil('\r');
client.readStringUntil('\n');
}
#ifdef DEBUG
#ifdef DEBUG
DEBUG_OUTPUT.print("PostArg Type: ");
DEBUG_OUTPUT.println(argType);
#endif
#endif
if (!argIsFile){
while(1){
line = client.readStringUntil('\r');
@@ -281,20 +291,20 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
if (argValue.length() > 0) argValue += "\n";
argValue += line;
}
#ifdef DEBUG
#ifdef DEBUG
DEBUG_OUTPUT.print("PostArg Value: ");
DEBUG_OUTPUT.println(argValue);
DEBUG_OUTPUT.println();
#endif
#endif
RequestArgument& arg = postArgs[postArgsLen++];
arg.key = argName;
arg.value = argValue;
if (line == ("--"+boundary+"--")){
#ifdef DEBUG
#ifdef DEBUG
DEBUG_OUTPUT.println("Done Parsing POST");
#endif
#endif
break;
}
} else {
@@ -312,23 +322,23 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
#endif
if (_fileUploadHandler) _fileUploadHandler();
_currentUpload.status = UPLOAD_FILE_WRITE;
uint8_t argByte = client.read();
uint8_t argByte = _uploadReadByte(client);
readfile:
while(argByte != 0x0D){
_uploadWriteByte(argByte);
argByte = client.read();
argByte = _uploadReadByte(client);
}
argByte = client.read();
argByte = _uploadReadByte(client);
if (argByte == 0x0A){
argByte = client.read();
argByte = _uploadReadByte(client);
if ((char)argByte != '-'){
//continue reading the file
_uploadWriteByte(0x0D);
_uploadWriteByte(0x0A);
goto readfile;
} else {
argByte = client.read();
argByte = _uploadReadByte(client);
if ((char)argByte != '-'){
//continue reading the file
_uploadWriteByte(0x0D);
@@ -366,11 +376,13 @@ readfile:
} else {
_uploadWriteByte(0x0D);
_uploadWriteByte(0x0A);
_uploadWriteByte((uint8_t)('-'));
_uploadWriteByte((uint8_t)('-'));
uint32_t i = 0;
while(i < boundary.length()){
_uploadWriteByte(endBuf[i++]);
}
argByte = client.read();
argByte = _uploadReadByte(client);
goto readfile;
}
} else {

View File

@@ -20,8 +20,7 @@ compiler.c.flags=-c -Os -Wpointer-arith -Wno-implicit-function-declaration -Wl,-
compiler.S.cmd=xtensa-lx106-elf-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD
compiler.c.elf.ldscript=eagle.app.v6.ld
compiler.c.elf.flags=-nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-T{compiler.c.elf.ldscript}"
compiler.c.elf.flags=-nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-T{build.flash_ld}"
compiler.c.elf.cmd=xtensa-lx106-elf-gcc
compiler.c.elf.libs=-lm -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig

View File

@@ -1,12 +1,5 @@
/* This linker script generated from xt-genldscripts.tpp for LSP . */
/* Linker Script for ld -N */
MEMORY
{
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40210000, len = 0x5B000
}
PHDRS
{
@@ -20,8 +13,6 @@ PHDRS
/* Default entry point: */
ENTRY(call_user_start)
PROVIDE ( _SPIFFS_start = 0x4026B000 );
PROVIDE ( _SPIFFS_end = 0x4027B000 );
PROVIDE(_memmap_vecbase_reset = 0x40000000);
/* Various memory-map dependent cache attribute settings: */
_memmap_cacheattr_wb_base = 0x00000110;

View File

@@ -0,0 +1,17 @@
/* Flash Split for 1M chips */
/* irom0 428KB */
/* spiffs 512KB */
/* eeprom 20KB */
MEMORY
{
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40210000, len = 0x6B000
}
PROVIDE ( _SPIFFS_start = 0x4027B000 );
PROVIDE ( _SPIFFS_end = 0x402FB000 );
INCLUDE "../ld/eagle.app.v6.common.ld"

View File

@@ -0,0 +1,17 @@
/* Flash Split for 256K chips */
/* irom0 108KB */
/* spiffs 64KB */
/* eeprom 20KB */
MEMORY
{
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40210000, len = 0x1B000
}
PROVIDE ( _SPIFFS_start = 0x4022B000 );
PROVIDE ( _SPIFFS_end = 0x4023B000 );
INCLUDE "../ld/eagle.app.v6.common.ld"

View File

@@ -0,0 +1,17 @@
/* Flash Split for 2M chips */
/* irom0 960KB */
/* spiffs 1004KB */
/* eeprom 20KB */
MEMORY
{
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40210000, len = 0xF0000
}
PROVIDE ( _SPIFFS_start = 0x40300000 );
PROVIDE ( _SPIFFS_end = 0x403FB000 );
INCLUDE "../ld/eagle.app.v6.common.ld"

View File

@@ -0,0 +1,17 @@
/* Flash Split for 4M chips */
/* irom0 960KB */
/* spiffs 3052KB */
/* eeprom 20KB */
MEMORY
{
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40210000, len = 0xF0000
}
PROVIDE ( _SPIFFS_start = 0x40300000 );
PROVIDE ( _SPIFFS_end = 0x405FB000 );
INCLUDE "../ld/eagle.app.v6.common.ld"

View File

@@ -0,0 +1,17 @@
/* Flash Split for 512K chips */
/* irom0 364KB */
/* spiffs 64KB */
/* eeprom 20KB */
MEMORY
{
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40210000, len = 0x5B000
}
PROVIDE ( _SPIFFS_start = 0x4026B000 );
PROVIDE ( _SPIFFS_end = 0x4027B000 );
INCLUDE "../ld/eagle.app.v6.common.ld"