Skip to content

Commit 93c4566

Browse files
author
ficeto
committed
Merge pull request #23 from Links2004/esp8266
pull markus's changes
2 parents 4c4e6b8 + 0be310f commit 93c4566

File tree

12 files changed

+365
-32
lines changed

12 files changed

+365
-32
lines changed

Diff for: cores/esp8266/HardwareSerial.cpp

+31-15
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ extern "C" {
4242
#define UART_TX_FIFO_SIZE 0x80
4343

4444
struct uart_ {
45-
int uart_nr;
45+
int uart_nr;
4646
int baud_rate;
4747
bool rxEnabled;
4848
bool txEnabled;
49-
uint8_t rxPin;
50-
uint8_t txPin;
49+
uint8_t rxPin;
50+
uint8_t txPin;
5151
};
5252

5353
static const int UART0 = 0;
@@ -120,7 +120,7 @@ void ICACHE_RAM_ATTR uart_interrupt_handler(uart_t* uart) {
120120
// -------------- UART 0 --------------
121121
if(Serial.isRxEnabled()) {
122122
while(U0IS & (1 << UIFF)) {
123-
Serial._rx_complete_irq((char)(U0F & 0xff));
123+
Serial._rx_complete_irq((char) (U0F & 0xff));
124124
U0IC = (1 << UIFF);
125125
}
126126
}
@@ -135,7 +135,7 @@ void ICACHE_RAM_ATTR uart_interrupt_handler(uart_t* uart) {
135135

136136
if(Serial1.isRxEnabled()) {
137137
while(U1IS & (1 << UIFF)) {
138-
Serial1._rx_complete_irq((char)(U1F & 0xff));
138+
Serial1._rx_complete_irq((char) (U1F & 0xff));
139139
U1IC = (1 << UIFF);
140140
}
141141
}
@@ -357,19 +357,19 @@ void uart_swap(uart_t* uart) {
357357
switch(uart->uart_nr) {
358358
case UART0:
359359
if(uart->txPin == 1 && uart->rxPin == 3) {
360-
pinMode(15, FUNCTION_4);//TX
361-
pinMode(13, FUNCTION_4);//RX
360+
pinMode(15, FUNCTION_4); //TX
361+
pinMode(13, FUNCTION_4); //RX
362362
USWAP |= (1 << USWAP0);
363-
pinMode(1, INPUT);//TX
364-
pinMode(3, INPUT);//RX
363+
pinMode(1, INPUT); //TX
364+
pinMode(3, INPUT); //RX
365365
uart->rxPin = 13;
366366
uart->txPin = 15;
367367
} else {
368-
pinMode(1, SPECIAL);//TX
369-
pinMode(3, SPECIAL);//RX
368+
pinMode(1, SPECIAL); //TX
369+
pinMode(3, SPECIAL); //RX
370370
USWAP &= ~(1 << USWAP0);
371-
pinMode(15, INPUT);//TX
372-
pinMode(13, INPUT);//RX
371+
pinMode(15, INPUT); //TX
372+
pinMode(13, INPUT); //RX
373373
uart->rxPin = 3;
374374
uart->txPin = 1;
375375
}
@@ -400,6 +400,14 @@ void uart0_write_char(char c) {
400400
return;
401401
}
402402
}
403+
404+
// wait for the Hardware FIFO
405+
while(true) {
406+
if(((USS(0) >> USTXC) & 0xff) <= (UART_TX_FIFO_SIZE - 2)) {
407+
break;
408+
}
409+
}
410+
403411
if(c == '\n') {
404412
USF(0) = '\r';
405413
}
@@ -416,6 +424,14 @@ void uart1_write_char(char c) {
416424
return;
417425
}
418426
}
427+
428+
// wait for the Hardware FIFO
429+
while(true) {
430+
if(((USS(1) >> USTXC) & 0xff) <= (UART_TX_FIFO_SIZE - 2)) {
431+
break;
432+
}
433+
}
434+
419435
if(c == '\n') {
420436
USF(1) = '\r';
421437
}
@@ -469,11 +485,11 @@ void HardwareSerial::begin(unsigned long baud, byte config) {
469485
}
470486

471487
if(_uart->rxEnabled) {
472-
if (!_rx_buffer)
488+
if(!_rx_buffer)
473489
_rx_buffer = new cbuf(SERIAL_RX_BUFFER_SIZE);
474490
}
475491
if(_uart->txEnabled) {
476-
if (!_tx_buffer)
492+
if(!_tx_buffer)
477493
_tx_buffer = new cbuf(SERIAL_TX_BUFFER_SIZE);
478494
}
479495
_written = false;

Diff for: cores/esp8266/abi.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ extern "C" {
2626
}
2727

2828
void *operator new(size_t size) {
29+
size = ((size + 3) & ~((size_t)0x3));
2930
return os_malloc(size);
3031
}
3132

3233
void *operator new[](size_t size) {
34+
size = ((size + 3) & ~((size_t)0x3));
3335
return os_malloc(size);
3436
}
3537

Diff for: cores/esp8266/libc_replacements.c

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "user_interface.h"
3939

4040
void* malloc(size_t size) {
41+
size = ((size + 3) & ~((size_t)0x3));
4142
return os_malloc(size);
4243
}
4344

@@ -46,6 +47,7 @@ void free(void* ptr) {
4647
}
4748

4849
void* realloc(void* ptr, size_t size) {
50+
size = ((size + 3) & ~((size_t)0x3));
4951
return os_realloc(ptr, size);
5052
}
5153

Diff for: doc/exception_causes.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Exception Causes (EXCCAUSE)
2+
===========================================
3+
4+
| EXC-CAUSE Code | Cause Name | Cause Description | Required Option | EXC-VADDR Loaded |
5+
|:--------------:|:---------------------------|:------------------------------------------------------------------------------------------------------------|:-------------------------|:----------------:|
6+
| 0 | IllegalInstructionCause | Illegal instruction | Exception | No |
7+
| 1 | SyscallCause | SYSCALL instruction | Exception | No |
8+
| 2 | InstructionFetchErrorCause | Processor internal physical address or data error during instruction fetch | Exception | Yes |
9+
| 3 | LoadStoreErrorCause | Processor internal physical address or data error during load or store | Exception | Yes |
10+
| 4 | Level1InterruptCause | Level-1 interrupt as indicated by set level-1 bits in the INTERRUPT register | Interrupt | No |
11+
| 5 | AllocaCause | MOVSP instruction, if caller’s registers are not in the register file | Windowed Register | No |
12+
| 6 | IntegerDivideByZeroCause | QUOS, QUOU, REMS, or REMU divisor operand is zero | 32-bit Integer Divide | No |
13+
| 7 | Reserved for Tensilica | | | |
14+
| 8 | PrivilegedCause | Attempt to execute a privileged operation when CRING ? 0 | MMU | No |
15+
| 9 | LoadStoreAlignmentCause | Load or store to an unaligned address | Unaligned Exception | Yes |
16+
| 10..11 | Reserved for Tensilica | | | |
17+
| 12 | InstrPIFDataErrorCause | PIF data error during instruction fetch | Processor Interface | Yes |
18+
| 13 | LoadStorePIFDataErrorCause | Synchronous PIF data error during LoadStore access | Processor Interface | Yes |
19+
| 14 | InstrPIFAddrErrorCause | PIF address error during instruction fetch | Processor Interface | Yes |
20+
| 15 | LoadStorePIFAddrErrorCause | Synchronous PIF address error during LoadStore access | Processor Interface | Yes |
21+
| 16 | InstTLBMissCause | Error during Instruction TLB refill | MMU | Yes |
22+
| 17 | InstTLBMultiHitCause | Multiple instruction TLB entries matched | MMU | Yes |
23+
| 18 | InstFetchPrivilegeCause | An instruction fetch referenced a virtual address at a ring level less than CRING | MMU | Yes |
24+
| 19 | Reserved for Tensilica | | | |
25+
| 20 | InstFetchProhibitedCause | An instruction fetch referenced a page mapped with an attribute that does not permit instruction fetch | Region Protection or MMU | Yes |
26+
| 21..23 | Reserved for Tensilica | | | |
27+
| 24 | LoadStoreTLBMissCause | Error during TLB refill for a load or store | MMU | Yes |
28+
| 25 | LoadStoreTLBMultiHitCause | Multiple TLB entries matched for a load or store | MMU | Yes |
29+
| 26 | LoadStorePrivilegeCause | A load or store referenced a virtual address at a ring level less than CRING | MMU | Yes |
30+
| 27 | Reserved for Tensilica | | | |
31+
| 28 | LoadProhibitedCause | A load referenced a page mapped with an attribute that does not permit loads | Region Protection or MMU | Yes |
32+
| 29 | StoreProhibitedCause | A store referenced a page mapped with an attribute that does not permit stores | Region Protection or MMU | Yes |
33+
| 30..31 | Reserved for Tensilica | | | |
34+
| 32..39 | CoprocessornDisabled | Coprocessor n instruction when cpn disabled. n varies 0..7 as the cause varies 32..39 | Coprocessor | No |
35+
| 40..63 | Reserved | | | |
36+
37+
38+
Infos from Xtensa Instruction Set Architecture (ISA) Reference Manual

Diff for: libraries/EEPROM/EEPROM.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ EEPROMClass::EEPROMClass()
4242

4343
void EEPROMClass::begin(size_t size)
4444
{
45-
if (size < 0)
45+
if (size <= 0)
4646
return;
4747
if (size > SPI_FLASH_SEC_SIZE)
4848
size = SPI_FLASH_SEC_SIZE;
4949

5050
_data = new uint8_t[size];
5151
_size = size;
5252

53+
noInterrupts();
5354
spi_flash_read(CONFIG_ADDR, reinterpret_cast<uint32_t*>(_data), _size);
55+
interrupts();
5456
}
5557

5658
void EEPROMClass::end()
@@ -59,8 +61,9 @@ void EEPROMClass::end()
5961
return;
6062

6163
commit();
62-
63-
delete[] _data;
64+
if(_data) {
65+
delete[] _data;
66+
}
6467
_data = 0;
6568
_size = 0;
6669
}
@@ -70,6 +73,8 @@ uint8_t EEPROMClass::read(int address)
7073
{
7174
if (address < 0 || (size_t)address >= _size)
7275
return 0;
76+
if(!_data)
77+
return 0;
7378

7479
return _data[address];
7580
}
@@ -78,6 +83,8 @@ void EEPROMClass::write(int address, uint8_t value)
7883
{
7984
if (address < 0 || (size_t)address >= _size)
8085
return;
86+
if(!_data)
87+
return;
8188

8289
_data[address] = value;
8390
_dirty = true;
@@ -90,20 +97,24 @@ bool EEPROMClass::commit()
9097
return false;
9198
if(!_dirty)
9299
return true;
100+
if(!_data)
101+
return false;
93102

94-
ETS_UART_INTR_DISABLE();
103+
noInterrupts();
95104
if(spi_flash_erase_sector(CONFIG_SECTOR) == SPI_FLASH_RESULT_OK) {
96105
if(spi_flash_write(CONFIG_ADDR, reinterpret_cast<uint32_t*>(_data), _size) == SPI_FLASH_RESULT_OK) {
97106
_dirty = false;
98107
ret = true;
99108
}
100109
}
101-
ETS_UART_INTR_ENABLE();
110+
interrupts();
111+
102112
return ret;
103113
}
104114

105115
uint8_t * EEPROMClass::getDataPtr()
106116
{
117+
_dirty = true;
107118
return &_data[0];
108119
}
109120

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This sketch trys to Connect to the best AP based on a given list
3+
*
4+
*/
5+
6+
#include <ESP8266WiFi.h>
7+
#include <ESP8266WiFiMulti.h>
8+
9+
ESP8266WiFiMulti WiFiMulti = ESP8266WiFiMulti();
10+
11+
void setup() {
12+
Serial.begin(115200);
13+
delay(10);
14+
15+
WiFiMulti.addAP("ssid_from_AP_1", "your_password_for_AP_1");
16+
WiFiMulti.addAP("ssid_from_AP_2", "your_password_for_AP_2");
17+
WiFiMulti.addAP("ssid_from_AP_3", "your_password_for_AP_3");
18+
19+
Serial.println("Connecting Wifi...");
20+
if(wifiMulti.run() == WL_CONNECTED) {
21+
Serial.println("");
22+
Serial.println("WiFi connected");
23+
Serial.println("IP address: ");
24+
Serial.println(WiFi.localIP());
25+
}
26+
}
27+
28+
void loop() {
29+
if(wifiMulti.run() != WL_CONNECTED) {
30+
Serial.println("WiFi not connected!");
31+
delay(1000);
32+
}
33+
}

Diff for: libraries/ESP8266WiFi/src/ESP8266WiFi.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ uint8_t ESP8266WiFiClass::encryptionType(uint8_t i)
344344
return -1;
345345
}
346346

347-
uint8_t ESP8266WiFiClass::status()
347+
wl_status_t ESP8266WiFiClass::status()
348348
{
349349
int status = wifi_station_get_connect_status();
350350

Diff for: libraries/ESP8266WiFi/src/ESP8266WiFi.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class ESP8266WiFiClass
199199
*
200200
* return: one of the value defined in wl_status_t
201201
*/
202-
uint8_t status();
202+
wl_status_t status();
203203

204204
/*
205205
* Resolve the given hostname to an IP address.

0 commit comments

Comments
 (0)