Skip to content

Commit 47eecaa

Browse files
committed
Merge pull request #1 from esp8266/esp8266-sdk-1.0
lkj
2 parents 259067d + aa372a7 commit 47eecaa

23 files changed

+666
-141
lines changed

README.md

+61-16
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,51 @@ Allows the sketch to respond to multicast DNS queries for domain names like "foo
183183
Currently the library only works on STA interface, AP interface is not supported.
184184
See attached example and library README file for details.
185185

186+
#### Servo ####
187+
188+
This library exposes the ability to control RC (hobby) servo motors. It will support upto 24 servos on any available output pin. By defualt the first 12 servos will use Timer0 and currently this will not interfere with any other support. Servo counts above 12 will use Timer1 and features that use it will be effected.
189+
While many RC servo motors will accept the 3.3v IO data pin from a esp8266, most will not be able to run off 3.3v and will require another power source that matches their specifications. Make sure to connect the grounds between the esp8266 and the servo motor power supply.
190+
186191
#### Other libraries (not included with the IDE)
187192

188193
Libraries that don't rely on low-level access to AVR registers should work well. Here are a few libraries that were verified to work:
189194

195+
- [arduinoWebSockets](https://github.com/Links2004/arduinoWebSockets) - WebSocket Server and Client compatible with esp8266 (RFC6455)
190196
- [aREST](https://github.com/marcoschwartz/aREST) REST API handler library.
191-
- [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy.
192-
- [DHT11](https://github.com/adafruit/DHT-sensor-library) - initialize DHT as follows: ```DHT dht(DHTPIN, DHTTYPE, 15);```
197+
- [Blynk](https://github.com/blynkkk/blynk-library) - easy IoT framework for Makers (check out the [Kickstarter page](http://tiny.cc/blynk-kick)).
193198
- [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git)
199+
- [DHT11](https://github.com/adafruit/DHT-sensor-library) - initialize DHT as follows: ```DHT dht(DHTPIN, DHTTYPE, 15);```
194200
- [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with esp8266.
201+
- [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy.
195202
- [RTC](https://github.com/Makuna/Rtc) - Arduino Library for Ds1307 & Ds3231 compatible with esp8266.
196-
- [Blynk](https://github.com/blynkkk/blynk-library) - easy IoT framework for Makers (check out the [Kickstarter page](http://tiny.cc/blynk-kick)).
197-
- [arduinoWebSockets](https://github.com/Links2004/arduinoWebSockets) - WebSocket Server and Client compatible with esp8266 (RFC6455)
203+
- [Souliss, Smart Home](https://github.com/souliss/souliss) - Framework for Smart Home based on Arduino, Android and openHAB.
198204

199205
#### Upload via serial port ####
200206
Pick the correct serial port.
201207
You need to put ESP8266 into bootloader mode before uploading code.
202208

209+
#### Power Supply ####
210+
211+
For stable use of the ESP8266 a power supply with 3V3 and >= 250mA is required.
212+
213+
* Note
214+
- using Power from USB to Serial is may unstable, they not deliver enough current.
215+
216+
#### Serial Adapter ####
217+
218+
There are many different USB to Serial adapters / boards.
219+
220+
* Note
221+
- for full upload management you need RTS and DTR
222+
- the chip need to have 3V3 TTL (5V may damage the chip)
223+
- not all board have all pins of the ICs as breakout (check before order)
224+
- CTS and DSR are not useful for upload (they are Inputs)
225+
226+
* Working ICs
227+
- FT232RL
228+
- CP2102
229+
- may others (drop a comment)
230+
203231
#### Minimal hardware Setup for Bootloading and usage ####
204232

205233
ESPxx Hardware
@@ -220,26 +248,43 @@ ESPxx Hardware
220248
- Reset is also named RSBT or REST (adding PullUp improves the stability of the Module)
221249
- GPIO2 is alternative TX for the boot loader mode
222250

223-
ESP01 example:
224-
225-
![ESP01 connect](https://raw.githubusercontent.com/Links2004/Arduino/esp8266/docs/ESP01_connect.jpg)
251+
###### esp to Serial
252+
![ESP to Serial](https://raw.githubusercontent.com/Links2004/Arduino/esp8266/docs/ESP_to_serial.png)
226253

227254
#### Minimal hardware Setup for Bootloading only ####
228255
ESPxx Hardware
229256

230-
| PIN | Resistor | Serial Adapter |
231-
| ------------- | -------- | -------------- |
232-
| VCC | | VCC (3.3V) |
233-
| GND | | GND |
234-
| TX or GPIO2 | | RX |
235-
| RX | | TX |
236-
| GPIO0 | | GND |
257+
| PIN | Resistor | Serial Adapter |
258+
| ------------- | -------- | --------------- |
259+
| VCC | | VCC (3.3V) |
260+
| GND | | GND |
261+
| TX or GPIO2 | | RX |
262+
| RX | | TX |
263+
| GPIO0 | | GND |
237264
| Reset | | RTS* |
238-
| GPIO15 | PullDown | |
239-
| CH_PD | PullUp | |
265+
| GPIO15 | PullDown | |
266+
| CH_PD | PullUp | |
240267

241268
* Note
242269
- if no RTS is used a manual power toggle is needed
270+
271+
#### Minimal hardware Setup for running only ####
272+
273+
ESPxx Hardware
274+
275+
| PIN | Resistor | Power supply |
276+
| ------------- | -------- | --------------- |
277+
| VCC | | VCC (3.3V) |
278+
| GND | | GND |
279+
| GPIO0 | PullUp | |
280+
| GPIO15 | PullDown | |
281+
| CH_PD | PullUp | |
282+
283+
###### minimal
284+
![ESP min](https://raw.githubusercontent.com/Links2004/Arduino/esp8266/docs/ESP_min.png)
285+
286+
###### improved stability
287+
![ESP improved stability](https://raw.githubusercontent.com/Links2004/Arduino/esp8266/docs/ESP_improved_stability.png)
243288

244289
### Issues and support ###
245290

docs/ESP_improved_stability.png

18 KB
Loading

docs/ESP_min.png

6.46 KB
Loading

docs/ESP_to_serial.png

21.3 KB
Loading

hardware/esp8266com/esp8266/bootloaders/eboot/Makefile

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
XTENSA_TOOCHAIN ?=
1+
XTENSA_TOOLCHAIN ?=
22

33
BIN_DIR := ./
44
TARGET_DIR := ./
55

66
TARGET_OBJ_FILES := \
77
eboot.o \
88
eboot_command.o \
9+
flash.o \
910

1011
TARGET_OBJ_PATHS := $(addprefix $(TARGET_DIR)/,$(TARGET_OBJ_FILES))
1112

12-
CC := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-gcc
13-
CXX := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-g++
14-
AR := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-ar
15-
LD := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-gcc
16-
OBJDUMP := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-objdump
13+
CC := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-gcc
14+
CXX := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-g++
15+
AR := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-ar
16+
LD := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-gcc
17+
OBJDUMP := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-objdump
1718

1819

1920
CFLAGS += -std=gnu99

hardware/esp8266com/esp8266/bootloaders/eboot/eboot.c

+16-41
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
#include <stddef.h>
1010
#include <stdint.h>
1111
#include <stdbool.h>
12-
#include "eboot.h"
12+
#include "flash.h"
1313
#include "eboot_command.h"
14-
extern void* flashchip;
1514

1615
#define SWRST do { (*((volatile uint32_t*) 0x60000700)) |= 0x80000000; } while(0);
1716

@@ -73,53 +72,21 @@ int load_app_from_flash_raw(const uint32_t flash_addr)
7372

7473

7574

76-
int erase(const uint32_t start, const uint32_t size)
77-
{
78-
if (start & (FLASH_SECTOR_SIZE - 1) != 0) {
79-
return 1;
80-
}
81-
82-
const uint32_t sectors_per_block = FLASH_BLOCK_SIZE / FLASH_SECTOR_SIZE;
83-
uint32_t current_sector = start / FLASH_SECTOR_SIZE;
84-
uint32_t sector_count = (size + FLASH_SECTOR_SIZE - 1) / FLASH_SECTOR_SIZE;
85-
const uint32_t end = current_sector + sector_count;
86-
87-
for (; current_sector < end && (current_sector & (sectors_per_block-1));
88-
++current_sector, --sector_count) {
89-
if (SPIEraseSector(current_sector)) {
90-
return 2;
91-
}
92-
}
93-
94-
for (;current_sector + sectors_per_block <= end;
95-
current_sector += sectors_per_block,
96-
sector_count -= sectors_per_block) {
97-
if (SPIEraseBlock(current_sector / sectors_per_block)) {
98-
return 3;
99-
}
100-
}
101-
102-
for (; current_sector < end;
103-
++current_sector, --sector_count) {
104-
if (SPIEraseSector(current_sector)) {
105-
return 4;
106-
}
107-
}
108-
109-
return 0;
110-
}
111-
11275
int copy_raw(const uint32_t src_addr,
11376
const uint32_t dst_addr,
11477
const uint32_t size)
11578
{
79+
ets_putc('\n');
80+
ets_putc('c');
81+
ets_putc('p');
82+
ets_putc('\n');
11683
// require regions to be aligned
11784
if (src_addr & 0xfff != 0 ||
11885
dst_addr & 0xfff != 0) {
11986
return 1;
12087
}
12188

122-
if (erase(dst_addr, size)) {
89+
if (SPIEraseAreaEx(dst_addr, size)) {
12390
return 2;
12491
}
12592

@@ -153,17 +120,25 @@ void main()
153120
int res = 9;
154121
struct eboot_command cmd;
155122

156-
eboot_command_read(&cmd);
123+
if (eboot_command_read(&cmd)) {
124+
cmd.action = ACTION_LOAD_APP;
125+
cmd.args[0] = 0;
126+
ets_putc('e');
127+
} else {
128+
ets_putc('@');
129+
}
130+
eboot_command_clear();
157131

158132
if (cmd.action == ACTION_COPY_RAW) {
159133
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2]);
160134
if (res == 0) {
161135
cmd.action = ACTION_LOAD_APP;
136+
cmd.args[0] = cmd.args[1];
162137
}
163138
}
164139

165140
if (cmd.action == ACTION_LOAD_APP) {
166-
res = load_app_from_flash_raw(0);
141+
res = load_app_from_flash_raw(cmd.args[0]);
167142
}
168143

169144
if (res) {
Binary file not shown.

hardware/esp8266com/esp8266/bootloaders/eboot/eboot_command.c

+22-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ uint32_t eboot_command_calculate_crc32(const struct eboot_command* cmd)
2828
offsetof(struct eboot_command, crc32));
2929
}
3030

31-
void eboot_command_read(struct eboot_command* cmd)
31+
int eboot_command_read(struct eboot_command* cmd)
3232
{
3333
const uint32_t dw_count = sizeof(struct eboot_command) / sizeof(uint32_t);
3434
uint32_t* dst = (uint32_t *) cmd;
@@ -39,9 +39,27 @@ void eboot_command_read(struct eboot_command* cmd)
3939
uint32_t crc32 = eboot_command_calculate_crc32(cmd);
4040
if (cmd->magic & EBOOT_MAGIC_MASK != EBOOT_MAGIC ||
4141
cmd->crc32 != crc32) {
42-
43-
cmd->action = ACTION_LOAD_APP;
44-
cmd->args[0] = 0;
42+
return 1;
4543
}
44+
45+
return 0;
46+
}
47+
48+
void eboot_command_write(struct eboot_command* cmd)
49+
{
50+
cmd->magic = EBOOT_MAGIC;
51+
cmd->crc32 = eboot_command_calculate_crc32(cmd);
52+
53+
const uint32_t dw_count = sizeof(struct eboot_command) / sizeof(uint32_t);
54+
const uint32_t* src = (const uint32_t *) cmd;
55+
for (uint32_t i = 0; i < dw_count; ++i) {
56+
RTC_MEM[i] = src[i];
57+
}
58+
}
59+
60+
void eboot_command_clear()
61+
{
62+
RTC_MEM[offsetof(struct eboot_command, magic) / sizeof(uint32_t)] = 0;
63+
RTC_MEM[offsetof(struct eboot_command, crc32) / sizeof(uint32_t)] = 0;
4664
}
4765

hardware/esp8266com/esp8266/bootloaders/eboot/eboot_command.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/* Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
2+
* This file is part of eboot bootloader.
3+
*
4+
* Redistribution and use is permitted according to the conditions of the
5+
* 3-clause BSD license to be found in the LICENSE file.
6+
*/
7+
18
#ifndef EBOOT_COMMAND_H
29
#define EBOOT_COMMAND_H
310

@@ -23,7 +30,8 @@ struct eboot_command {
2330
};
2431

2532

26-
void eboot_command_read(struct eboot_command* cmd);
27-
33+
int eboot_command_read(struct eboot_command* cmd);
34+
void eboot_command_write(struct eboot_command* cmd);
35+
void eboot_command_clear();
2836

2937
#endif //EBOOT_COMMAND_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
2+
* This file is part of eboot bootloader.
3+
*
4+
* Redistribution and use is permitted according to the conditions of the
5+
* 3-clause BSD license to be found in the LICENSE file.
6+
*/
7+
8+
#include <stddef.h>
9+
#include <stdint.h>
10+
#include <stdbool.h>
11+
#include "flash.h"
12+
13+
14+
int SPIEraseAreaEx(const uint32_t start, const uint32_t size)
15+
{
16+
if (start & (FLASH_SECTOR_SIZE - 1) != 0) {
17+
return 1;
18+
}
19+
20+
const uint32_t sectors_per_block = FLASH_BLOCK_SIZE / FLASH_SECTOR_SIZE;
21+
uint32_t current_sector = start / FLASH_SECTOR_SIZE;
22+
uint32_t sector_count = (size + FLASH_SECTOR_SIZE - 1) / FLASH_SECTOR_SIZE;
23+
const uint32_t end = current_sector + sector_count;
24+
25+
for (; current_sector < end && (current_sector & (sectors_per_block-1));
26+
++current_sector, --sector_count) {
27+
if (SPIEraseSector(current_sector)) {
28+
return 2;
29+
}
30+
}
31+
32+
for (;current_sector + sectors_per_block <= end;
33+
current_sector += sectors_per_block,
34+
sector_count -= sectors_per_block) {
35+
if (SPIEraseBlock(current_sector / sectors_per_block)) {
36+
return 3;
37+
}
38+
}
39+
40+
for (; current_sector < end;
41+
++current_sector, --sector_count) {
42+
if (SPIEraseSector(current_sector)) {
43+
return 4;
44+
}
45+
}
46+
47+
return 0;
48+
}
49+

hardware/esp8266com/esp8266/bootloaders/eboot/eboot.h renamed to hardware/esp8266com/esp8266/bootloaders/eboot/flash.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
* 3-clause BSD license to be found in the LICENSE file.
66
*/
77

8-
#ifndef EBOOT_H
9-
#define EBOOT_H
10-
8+
#ifndef FLASH_H
9+
#define FLASH_H
1110

1211
int SPIEraseBlock(uint32_t block);
1312
int SPIEraseSector(uint32_t sector);
1413
int SPIRead(uint32_t addr, void *dest, size_t size);
1514
int SPIWrite(uint32_t addr, void *src, size_t size);
16-
15+
int SPIEraseAreaEx(const uint32_t start, const uint32_t size);
1716

1817
#define FLASH_SECTOR_SIZE 0x1000
1918
#define FLASH_BLOCK_SIZE 0x10000
@@ -41,4 +40,4 @@ typedef struct {
4140

4241

4342

44-
#endif //EBOOT_H
43+
#endif //FLASH_H

0 commit comments

Comments
 (0)