Skip to content

Commit bc945af

Browse files
authored
Merge branch 'master' into examples
2 parents 8a28979 + cd05bae commit bc945af

20 files changed

+169
-59
lines changed

bootloaders/eboot/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ AR := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-ar
1717
LD := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-gcc
1818
OBJDUMP := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-objdump
1919

20-
20+
INC += -I../../tools/sdk/include
2121
CFLAGS += -std=gnu99
2222

2323
CFLAGS += -O0 -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mno-text-section-literals
2424

25+
CFLAGS += $(INC)
26+
2527
LDFLAGS += -nostdlib -Wl,--no-check-sections -umain
2628

2729
LD_SCRIPT := -Teboot.ld

bootloaders/eboot/eboot.elf

24 Bytes
Binary file not shown.

bootloaders/eboot/flash.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
#ifndef FLASH_H
99
#define FLASH_H
1010

11+
12+
/* The geometry defines are placed in the sdk. The .h was factored out for reuse by eboot here.
13+
* Beware: this means that eboot has an external dependency.
14+
* The following .h is placed in tools/sdk/includes
15+
*/
16+
#include <spi_flash_geometry.h>
17+
1118
int SPIEraseBlock(uint32_t block);
1219
int SPIEraseSector(uint32_t sector);
1320
int SPIRead(uint32_t addr, void *dest, size_t size);
1421
int SPIWrite(uint32_t addr, void *src, size_t size);
1522
int SPIEraseAreaEx(const uint32_t start, const uint32_t size);
1623

17-
#define FLASH_SECTOR_SIZE 0x1000
18-
#define FLASH_BLOCK_SIZE 0x10000
19-
#define APP_START_OFFSET 0x1000
2024

2125
typedef struct {
2226
unsigned char magic;
@@ -25,7 +29,7 @@ typedef struct {
2529
/* SPI Flash Interface (0 = QIO, 1 = QOUT, 2 = DIO, 0x3 = DOUT) */
2630
unsigned char flash_mode;
2731

28-
/* High four bits: 0 = 512K, 1 = 256K, 2 = 1M, 3 = 2M, 4 = 4M,
32+
/* High four bits: 0 = 512K, 1 = 256K, 2 = 1M, 3 = 2M, 4 = 4M, 8 = 8M, 9 = 16M
2933
Low four bits: 0 = 40MHz, 1= 26MHz, 2 = 20MHz, 0xf = 80MHz */
3034
unsigned char flash_size_freq;
3135

cores/esp8266/Esp.cpp

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "flash_utils.h"
2323
#include "eboot_command.h"
2424
#include <memory>
25-
#include <interrupts.h>
25+
#include "interrupts.h"
2626
#include "MD5Builder.h"
2727
#include "umm_malloc/umm_malloc.h"
2828
#include "cont.h"
@@ -132,9 +132,43 @@ uint64_t EspClass::deepSleepMax()
132132

133133
}
134134

135+
/*
136+
Layout of RTC Memory is as follows:
137+
Ref: Espressif doc 2C-ESP8266_Non_OS_SDK_API_Reference, section 3.3.23 (system_rtc_mem_write)
138+
139+
|<------system data (256 bytes)------->|<-----------------user data (512 bytes)--------------->|
140+
141+
SDK function signature:
142+
bool system_rtc_mem_read (
143+
uint32 des_addr,
144+
void * src_addr,
145+
uint32 save_size
146+
)
147+
148+
The system data section can't be used by the user, so:
149+
des_addr must be >=64 (i.e.: 256/4) and <192 (i.e.: 768/4)
150+
src_addr is a pointer to data
151+
save_size is the number of bytes to write
152+
153+
For the method interface:
154+
offset is the user block number (block size is 4 bytes) must be >= 0 and <128
155+
data is a pointer to data, 4-byte aligned
156+
size is number of bytes in the block pointed to by data
157+
158+
Same for write
159+
160+
Note: If the Updater class is in play, e.g.: the application uses OTA, the eboot
161+
command will be stored into the first 128 bytes of user data, then it will be
162+
retrieved by eboot on boot. That means that user data present there will be lost.
163+
Ref:
164+
- discussion in PR #5330.
165+
- https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map#memmory-mapped-io-registers
166+
- Arduino/bootloaders/eboot/eboot_command.h RTC_MEM definition
167+
*/
168+
135169
bool EspClass::rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size)
136170
{
137-
if (size + offset > 512) {
171+
if (offset * 4 + size > 512 || size == 0) {
138172
return false;
139173
} else {
140174
return system_rtc_mem_read(64 + offset, data, size);
@@ -143,13 +177,15 @@ bool EspClass::rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size)
143177

144178
bool EspClass::rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size)
145179
{
146-
if (size + offset > 512) {
180+
if (offset * 4 + size > 512 || size == 0) {
147181
return false;
148182
} else {
149183
return system_rtc_mem_write(64 + offset, data, size);
150184
}
151185
}
152186

187+
188+
153189
extern "C" void __real_system_restart_local();
154190
void EspClass::reset(void)
155191
{

cores/esp8266/MD5Builder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ class MD5Builder {
3434
void add(const uint8_t * data, const uint16_t len);
3535
void add(const char * data){ add((const uint8_t*)data, strlen(data)); }
3636
void add(char * data){ add((const char*)data); }
37-
void add(const String data){ add(data.c_str()); }
37+
void add(const String& data){ add(data.c_str()); }
3838
void addHexString(const char * data);
3939
void addHexString(char * data){ addHexString((const char*)data); }
40-
void addHexString(const String data){ addHexString(data.c_str()); }
40+
void addHexString(const String& data){ addHexString(data.c_str()); }
4141
bool addStream(Stream & stream, const size_t maxLen);
4242
void calculate(void);
4343
void getBytes(uint8_t * output);

cores/esp8266/core_esp8266_i2s.c

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,18 @@ bool i2s_rx_is_empty() {
113113
return _i2s_is_empty( rx );
114114
}
115115

116-
static int16_t _i2s_available(const i2s_state_t *ch) {
116+
static uint16_t _i2s_available(const i2s_state_t *ch) {
117117
if (!ch) {
118118
return 0;
119119
}
120120
return (SLC_BUF_CNT - ch->slc_queue_len) * SLC_BUF_LEN;
121121
}
122122

123-
int16_t i2s_available(){
123+
uint16_t i2s_available(){
124124
return _i2s_available( tx );
125125
}
126126

127-
int16_t i2s_rx_available(){
127+
uint16_t i2s_rx_available(){
128128
return _i2s_available( rx );
129129
}
130130

@@ -331,6 +331,74 @@ bool i2s_write_lr(int16_t left, int16_t right){
331331
return i2s_write_sample(sample);
332332
}
333333

334+
// writes a buffer of frames into the DMA memory, returns the amount of frames written
335+
// A frame is just a int16_t for mono, for stereo a frame is two int16_t, one for each channel.
336+
static uint16_t _i2s_write_buffer(int16_t *frames, uint16_t frame_count, bool mono, bool nb) {
337+
uint16_t frames_written=0;
338+
339+
while(frame_count>0) {
340+
341+
// make sure we have room in the current buffer
342+
if (tx->curr_slc_buf_pos==SLC_BUF_LEN || tx->curr_slc_buf==NULL) {
343+
// no room in the current buffer? if there are no buffers available then exit
344+
if (tx->slc_queue_len == 0)
345+
{
346+
if (nb) {
347+
// if nonblocking just return the number of frames written so far
348+
break;
349+
}
350+
else {
351+
while (1) {
352+
if (tx->slc_queue_len > 0) {
353+
break;
354+
} else {
355+
optimistic_yield(10000);
356+
}
357+
}
358+
}
359+
}
360+
361+
// get a new buffer
362+
ETS_SLC_INTR_DISABLE();
363+
tx->curr_slc_buf = (uint32_t *)i2s_slc_queue_next_item(tx);
364+
ETS_SLC_INTR_ENABLE();
365+
tx->curr_slc_buf_pos=0;
366+
}
367+
368+
//space available in the current buffer
369+
uint16_t available = SLC_BUF_LEN - tx->curr_slc_buf_pos;
370+
371+
uint16_t fc = (available < frame_count) ? available : frame_count;
372+
373+
if (mono) {
374+
for(uint16_t i=0;i<fc;i++){
375+
uint16_t v = (uint16_t)(*frames++);
376+
tx->curr_slc_buf[tx->curr_slc_buf_pos++] = (v << 16) | v;
377+
}
378+
}
379+
else
380+
{
381+
for(uint16_t i=0;i<fc;i++){
382+
uint16_t v1 = (uint16_t)(*frames++);
383+
uint16_t v2 = (uint16_t)(*frames++);
384+
tx->curr_slc_buf[tx->curr_slc_buf_pos++] = (v1 << 16) | v2;
385+
}
386+
}
387+
388+
frame_count -= fc;
389+
frames_written += fc;
390+
}
391+
return frames_written;
392+
}
393+
394+
uint16_t i2s_write_buffer_mono_nb(int16_t *frames, uint16_t frame_count) { return _i2s_write_buffer(frames, frame_count, true, true); }
395+
396+
uint16_t i2s_write_buffer_mono(int16_t *frames, uint16_t frame_count) { return _i2s_write_buffer(frames, frame_count, true, false); }
397+
398+
uint16_t i2s_write_buffer_nb(int16_t *frames, uint16_t frame_count) { return _i2s_write_buffer(frames, frame_count, false, true); }
399+
400+
uint16_t i2s_write_buffer(int16_t *frames, uint16_t frame_count) { return _i2s_write_buffer(frames, frame_count, false, false); }
401+
334402
bool i2s_read_sample(int16_t *left, int16_t *right, bool blocking) {
335403
if (!rx) {
336404
return false;

cores/esp8266/flash_utils.h

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,17 @@
2121
#ifndef FLASH_UTILS_H
2222
#define FLASH_UTILS_H
2323

24+
2425
#ifdef __cplusplus
2526
extern "C" {
2627
#endif
2728

28-
int SPIEraseBlock(uint32_t block);
29-
int SPIEraseSector(uint32_t sector);
30-
int SPIRead(uint32_t addr, void *dest, size_t size);
31-
int SPIWrite(uint32_t addr, void *src, size_t size);
32-
int SPIEraseAreaEx(const uint32_t start, const uint32_t size);
33-
34-
#define FLASH_SECTOR_SIZE 0x1000
35-
#define FLASH_BLOCK_SIZE 0x10000
36-
#define APP_START_OFFSET 0x1000
37-
38-
typedef struct {
39-
unsigned char magic;
40-
unsigned char num_segments;
41-
42-
/* SPI Flash Interface (0 = QIO, 1 = QOUT, 2 = DIO, 0x3 = DOUT) */
43-
unsigned char flash_mode;
44-
45-
/* High four bits: 0 = 512K, 1 = 256K, 2 = 1M, 3 = 2M, 4 = 4M, 8 = 8M, 9 = 16M
46-
Low four bits: 0 = 40MHz, 1= 26MHz, 2 = 20MHz, 0xf = 80MHz */
47-
unsigned char flash_size_freq;
48-
49-
uint32_t entry;
50-
} image_header_t;
51-
29+
/* Definitions are placed in eboot. Include them here rather than duplicate them.
30+
* Also, prefer to have eboot standalone as much as possible and have the core depend on it
31+
* rather than have eboot depend on the core.
32+
*/
33+
#include <../../bootloaders/eboot/flash.h>
5234

53-
typedef struct {
54-
uint32_t address;
55-
uint32_t size;
56-
} section_header_t;
5735

5836
#ifdef __cplusplus
5937
}

cores/esp8266/i2s.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,18 @@ bool i2s_is_full();//returns true if DMA is full and can not take more bytes (ov
5454
bool i2s_is_empty();//returns true if DMA is empty (underflow)
5555
bool i2s_rx_is_full();
5656
bool i2s_rx_is_empty();
57-
int16_t i2s_available();// returns the number of samples than can be written before blocking
58-
int16_t i2s_rx_available();// returns the number of samples than can be written before blocking
57+
uint16_t i2s_available();// returns the number of samples than can be written before blocking
58+
uint16_t i2s_rx_available();// returns the number of samples than can be written before blocking
5959
void i2s_set_callback(void (*callback) (void));
6060
void i2s_rx_set_callback(void (*callback) (void));
6161

62+
// writes a buffer of frames into the DMA memory, returns the amount of frames written
63+
// A frame is just a int16_t for mono, for stereo a frame is two int16_t, one for each channel.
64+
uint16_t i2s_write_buffer_mono(int16_t *frames, uint16_t frame_count);
65+
uint16_t i2s_write_buffer_mono_nb(int16_t *frames, uint16_t frame_count);
66+
uint16_t i2s_write_buffer(int16_t *frames, uint16_t frame_count);
67+
uint16_t i2s_write_buffer_nb(int16_t *frames, uint16_t frame_count);
68+
6269
#ifdef __cplusplus
6370
}
6471
#endif

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ bool ESP8266WiFiSTAClass::hostname(const char* aHostname) {
487487
* @param aHostname max length:32
488488
* @return ok
489489
*/
490-
bool ESP8266WiFiSTAClass::hostname(String aHostname) {
490+
bool ESP8266WiFiSTAClass::hostname(const String& aHostname) {
491491
return hostname((char*) aHostname.c_str());
492492
}
493493

libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ESP8266WiFiSTAClass {
7171
String hostname();
7272
bool hostname(char* aHostname);
7373
bool hostname(const char* aHostname);
74-
bool hostname(String aHostname);
74+
bool hostname(const String& aHostname);
7575

7676
// STA WiFi info
7777
wl_status_t status();

0 commit comments

Comments
 (0)