1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-06 05:21:22 +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
commit 92455f710a
11 changed files with 74 additions and 27 deletions

2
.gitignore vendored
View File

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

View File

@ -1,6 +1,8 @@
menu.UploadSpeed=Upload Speed menu.UploadSpeed=Upload Speed
menu.CpuFrequency=CPU Frequency 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 generic.name=Generic ESP8266 Module
@ -21,6 +23,7 @@ generic.build.variant=generic
generic.build.flash_mode=qio generic.build.flash_mode=qio
generic.build.flash_size=512K generic.build.flash_size=512K
generic.build.flash_freq=40 generic.build.flash_freq=40
generic.build.flash_ld=eagle.flash.512k.ld
generic.menu.CpuFrequency.80=80 MHz generic.menu.CpuFrequency.80=80 MHz
generic.menu.CpuFrequency.80.build.f_cpu=80000000L 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=512K
generic.menu.FlashSize.512K.build.flash_size=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=256K
generic.menu.FlashSize.256K.build.flash_size=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=1M
generic.menu.FlashSize.1M.build.flash_size=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=2M
generic.menu.FlashSize.2M.build.flash_size=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=4M
generic.menu.FlashSize.4M.build.flash_size=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) modwifi.name=Olimex MOD-WIFI-ESP8266(-DEV)
@ -77,6 +103,7 @@ modwifi.build.variant=generic
modwifi.build.flash_mode=qio modwifi.build.flash_mode=qio
modwifi.build.flash_size=2M modwifi.build.flash_size=2M
modwifi.build.flash_freq=40 modwifi.build.flash_freq=40
modwifi.build.flash_ld=eagle.flash.2m.ld
modwifi.menu.CpuFrequency.80=80 MHz modwifi.menu.CpuFrequency.80=80 MHz
modwifi.menu.CpuFrequency.80.build.f_cpu=80000000L modwifi.menu.CpuFrequency.80.build.f_cpu=80000000L
@ -122,6 +149,7 @@ nodemcu.build.variant=nodemcu
nodemcu.build.flash_mode=qio nodemcu.build.flash_mode=qio
nodemcu.build.flash_size=4M nodemcu.build.flash_size=4M
nodemcu.build.flash_freq=40 nodemcu.build.flash_freq=40
nodemcu.build.flash_ld=eagle.flash.4m.ld
nodemcu.menu.CpuFrequency.80=80 MHz nodemcu.menu.CpuFrequency.80=80 MHz
nodemcu.menu.CpuFrequency.80.build.f_cpu=80000000L 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_mode=qio
# wifio.build.flash_size=512K # wifio.build.flash_size=512K
# wifio.build.flash_freq=40 # wifio.build.flash_freq=40
# wifio.build.flash_ld=eagle.flash.512k.ld
# #
# wifio.menu.CpuFrequency.80=80MHz # wifio.menu.CpuFrequency.80=80MHz
# wifio.menu.CpuFrequency.80.build.f_cpu=80000000L # wifio.menu.CpuFrequency.80.build.f_cpu=80000000L

View File

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

View File

@ -162,7 +162,8 @@ int FSFile::available() {
size_t FSFile::write(const uint8_t *buf, size_t size){ size_t FSFile::write(const uint8_t *buf, size_t size){
if (! _file) return 0; 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) { size_t FSFile::write(uint8_t val) {

View File

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

View File

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

View File

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

View File

@ -1,4 +1,5 @@
#include "flashmem.h" #include "flashmem.h"
#include "esp8266_peri.h"
// Based on NodeMCU platform_flash // Based on NodeMCU platform_flash
// https://github.com/nodemcu/nodemcu-firmware // 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; return 0;
os_memcpy(apbuf, from, size); os_memcpy(apbuf, from, size);
} }
WRITE_PERI_REG(0x60000914, 0x73); WDT_RESET();
r = spi_flash_write(toaddr, apbuf?(uint32 *)apbuf:(uint32 *)from, size); r = spi_flash_write(toaddr, apbuf?(uint32 *)apbuf:(uint32 *)from, size);
if(apbuf) if(apbuf)
os_free(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; fromaddr -= INTERNAL_FLASH_START_ADDRESS;
SpiFlashOpResult r; SpiFlashOpResult r;
WRITE_PERI_REG(0x60000914, 0x73); WDT_RESET();
r = spi_flash_read(fromaddr, (uint32 *)to, size); r = spi_flash_read(fromaddr, (uint32 *)to, size);
if(SPI_FLASH_RESULT_OK == r) if(SPI_FLASH_RESULT_OK == r)
return size; return size;

View File

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

View File

@ -214,12 +214,22 @@ void ESP8266WebServer::_uploadWriteByte(uint8_t b){
_currentUpload.buf[_currentUpload.currentSize++] = 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){ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
#ifdef DEBUG #ifdef DEBUG
DEBUG_OUTPUT.print("Parse Form: Boundary: "); DEBUG_OUTPUT.print("Parse Form: Boundary: ");
DEBUG_OUTPUT.print(boundary); DEBUG_OUTPUT.print(boundary);
DEBUG_OUTPUT.print("Length: "); DEBUG_OUTPUT.print(" Length: ");
DEBUG_OUTPUT.println(len); DEBUG_OUTPUT.println(len);
#endif #endif
String line; String line;
@ -249,17 +259,17 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
argFilename = argName.substring(nameStart+2, argName.length() - 1); argFilename = argName.substring(nameStart+2, argName.length() - 1);
argName = argName.substring(0, argName.indexOf('"')); argName = argName.substring(0, argName.indexOf('"'));
argIsFile = true; argIsFile = true;
#ifdef DEBUG #ifdef DEBUG
DEBUG_OUTPUT.print("PostArg FileName: "); DEBUG_OUTPUT.print("PostArg FileName: ");
DEBUG_OUTPUT.println(argFilename); DEBUG_OUTPUT.println(argFilename);
#endif #endif
//use GET to set the filename if uploading using blob //use GET to set the filename if uploading using blob
if (argFilename == "blob" && hasArg("filename")) argFilename = arg("filename"); if (argFilename == "blob" && hasArg("filename")) argFilename = arg("filename");
} }
#ifdef DEBUG #ifdef DEBUG
DEBUG_OUTPUT.print("PostArg Name: "); DEBUG_OUTPUT.print("PostArg Name: ");
DEBUG_OUTPUT.println(argName); DEBUG_OUTPUT.println(argName);
#endif #endif
argType = "text/plain"; argType = "text/plain";
line = client.readStringUntil('\r'); line = client.readStringUntil('\r');
client.readStringUntil('\n'); client.readStringUntil('\n');
@ -269,10 +279,10 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
client.readStringUntil('\r'); client.readStringUntil('\r');
client.readStringUntil('\n'); client.readStringUntil('\n');
} }
#ifdef DEBUG #ifdef DEBUG
DEBUG_OUTPUT.print("PostArg Type: "); DEBUG_OUTPUT.print("PostArg Type: ");
DEBUG_OUTPUT.println(argType); DEBUG_OUTPUT.println(argType);
#endif #endif
if (!argIsFile){ if (!argIsFile){
while(1){ while(1){
line = client.readStringUntil('\r'); line = client.readStringUntil('\r');
@ -281,20 +291,20 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
if (argValue.length() > 0) argValue += "\n"; if (argValue.length() > 0) argValue += "\n";
argValue += line; argValue += line;
} }
#ifdef DEBUG #ifdef DEBUG
DEBUG_OUTPUT.print("PostArg Value: "); DEBUG_OUTPUT.print("PostArg Value: ");
DEBUG_OUTPUT.println(argValue); DEBUG_OUTPUT.println(argValue);
DEBUG_OUTPUT.println(); DEBUG_OUTPUT.println();
#endif #endif
RequestArgument& arg = postArgs[postArgsLen++]; RequestArgument& arg = postArgs[postArgsLen++];
arg.key = argName; arg.key = argName;
arg.value = argValue; arg.value = argValue;
if (line == ("--"+boundary+"--")){ if (line == ("--"+boundary+"--")){
#ifdef DEBUG #ifdef DEBUG
DEBUG_OUTPUT.println("Done Parsing POST"); DEBUG_OUTPUT.println("Done Parsing POST");
#endif #endif
break; break;
} }
} else { } else {
@ -312,23 +322,23 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
#endif #endif
if (_fileUploadHandler) _fileUploadHandler(); if (_fileUploadHandler) _fileUploadHandler();
_currentUpload.status = UPLOAD_FILE_WRITE; _currentUpload.status = UPLOAD_FILE_WRITE;
uint8_t argByte = client.read(); uint8_t argByte = _uploadReadByte(client);
readfile: readfile:
while(argByte != 0x0D){ while(argByte != 0x0D){
_uploadWriteByte(argByte); _uploadWriteByte(argByte);
argByte = client.read(); argByte = _uploadReadByte(client);
} }
argByte = client.read(); argByte = _uploadReadByte(client);
if (argByte == 0x0A){ if (argByte == 0x0A){
argByte = client.read(); argByte = _uploadReadByte(client);
if ((char)argByte != '-'){ if ((char)argByte != '-'){
//continue reading the file //continue reading the file
_uploadWriteByte(0x0D); _uploadWriteByte(0x0D);
_uploadWriteByte(0x0A); _uploadWriteByte(0x0A);
goto readfile; goto readfile;
} else { } else {
argByte = client.read(); argByte = _uploadReadByte(client);
if ((char)argByte != '-'){ if ((char)argByte != '-'){
//continue reading the file //continue reading the file
_uploadWriteByte(0x0D); _uploadWriteByte(0x0D);
@ -366,11 +376,13 @@ readfile:
} else { } else {
_uploadWriteByte(0x0D); _uploadWriteByte(0x0D);
_uploadWriteByte(0x0A); _uploadWriteByte(0x0A);
_uploadWriteByte((uint8_t)('-'));
_uploadWriteByte((uint8_t)('-'));
uint32_t i = 0; uint32_t i = 0;
while(i < boundary.length()){ while(i < boundary.length()){
_uploadWriteByte(endBuf[i++]); _uploadWriteByte(endBuf[i++]);
} }
argByte = client.read(); argByte = _uploadReadByte(client);
goto readfile; goto readfile;
} }
} else { } 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.cmd=xtensa-lx106-elf-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD 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{build.flash_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.cmd=xtensa-lx106-elf-gcc compiler.c.elf.cmd=xtensa-lx106-elf-gcc
compiler.c.elf.libs=-lm -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig compiler.c.elf.libs=-lm -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig