Skip to content

Commit

Permalink
Merge pull request #2 from esp8266/esp8266
Browse files Browse the repository at this point in the history
Esp8266
  • Loading branch information
me-no-dev committed Jun 8, 2015
2 parents d14dfc9 + b364bcb commit 45b5baf
Show file tree
Hide file tree
Showing 23 changed files with 665 additions and 140 deletions.
77 changes: 61 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,51 @@ Allows the sketch to respond to multicast DNS queries for domain names like "foo
Currently the library only works on STA interface, AP interface is not supported.
See attached example and library README file for details.

#### Servo ####

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.
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.

#### Other libraries (not included with the IDE)

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:

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

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

#### Power Supply ####

For stable use of the ESP8266 a power supply with 3V3 and >= 250mA is required.

* Note
- using Power from USB to Serial is may unstable, they not deliver enough current.

#### Serial Adapter ####

There are many different USB to Serial adapters / boards.

* Note
- for full upload management you need RTS and DTR
- the chip need to have 3V3 TTL (5V may damage the chip)
- not all board have all pins of the ICs as breakout (check before order)
- CTS and DSR are not useful for upload (they are Inputs)

* Working ICs
- FT232RL
- CP2102
- may others (drop a comment)

#### Minimal hardware Setup for Bootloading and usage ####

ESPxx Hardware
Expand All @@ -221,26 +249,43 @@ ESPxx Hardware
- Reset is also named RSBT or REST (adding PullUp improves the stability of the Module)
- GPIO2 is alternative TX for the boot loader mode

ESP01 example:

![ESP01 connect](https://raw.githubusercontent.com/Links2004/Arduino/esp8266/docs/ESP01_connect.jpg)
###### esp to Serial
![ESP to Serial](https://raw.githubusercontent.com/Links2004/Arduino/esp8266/docs/ESP_to_serial.png)

#### Minimal hardware Setup for Bootloading only ####
ESPxx Hardware

| PIN | Resistor | Serial Adapter |
| ------------- | -------- | -------------- |
| VCC | | VCC (3.3V) |
| GND | | GND |
| TX or GPIO2 | | RX |
| RX | | TX |
| GPIO0 | | GND |
| PIN | Resistor | Serial Adapter |
| ------------- | -------- | --------------- |
| VCC | | VCC (3.3V) |
| GND | | GND |
| TX or GPIO2 | | RX |
| RX | | TX |
| GPIO0 | | GND |
| Reset | | RTS* |
| GPIO15 | PullDown | |
| CH_PD | PullUp | |
| GPIO15 | PullDown | |
| CH_PD | PullUp | |

* Note
- if no RTS is used a manual power toggle is needed
#### Minimal hardware Setup for running only ####

ESPxx Hardware

| PIN | Resistor | Power supply |
| ------------- | -------- | --------------- |
| VCC | | VCC (3.3V) |
| GND | | GND |
| GPIO0 | PullUp | |
| GPIO15 | PullDown | |
| CH_PD | PullUp | |

###### minimal
![ESP min](https://raw.githubusercontent.com/Links2004/Arduino/esp8266/docs/ESP_min.png)

###### improved stability
![ESP improved stability](https://raw.githubusercontent.com/Links2004/Arduino/esp8266/docs/ESP_improved_stability.png)

### Issues and support ###

Expand Down
Binary file added docs/ESP_improved_stability.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/ESP_min.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/ESP_to_serial.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 7 additions & 6 deletions hardware/esp8266com/esp8266/bootloaders/eboot/Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
XTENSA_TOOCHAIN ?=
XTENSA_TOOLCHAIN ?=

BIN_DIR := ./
TARGET_DIR := ./

TARGET_OBJ_FILES := \
eboot.o \
eboot_command.o \
flash.o \

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

CC := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-gcc
CXX := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-g++
AR := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-ar
LD := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-gcc
OBJDUMP := $(XTENSA_TOOCHAIN)xtensa-lx106-elf-objdump
CC := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-gcc
CXX := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-g++
AR := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-ar
LD := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-gcc
OBJDUMP := $(XTENSA_TOOLCHAIN)xtensa-lx106-elf-objdump


CFLAGS += -std=gnu99
Expand Down
57 changes: 16 additions & 41 deletions hardware/esp8266com/esp8266/bootloaders/eboot/eboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "eboot.h"
#include "flash.h"
#include "eboot_command.h"
extern void* flashchip;

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

Expand Down Expand Up @@ -73,53 +72,21 @@ int load_app_from_flash_raw(const uint32_t flash_addr)



int erase(const uint32_t start, const uint32_t size)
{
if (start & (FLASH_SECTOR_SIZE - 1) != 0) {
return 1;
}

const uint32_t sectors_per_block = FLASH_BLOCK_SIZE / FLASH_SECTOR_SIZE;
uint32_t current_sector = start / FLASH_SECTOR_SIZE;
uint32_t sector_count = (size + FLASH_SECTOR_SIZE - 1) / FLASH_SECTOR_SIZE;
const uint32_t end = current_sector + sector_count;

for (; current_sector < end && (current_sector & (sectors_per_block-1));
++current_sector, --sector_count) {
if (SPIEraseSector(current_sector)) {
return 2;
}
}

for (;current_sector + sectors_per_block <= end;
current_sector += sectors_per_block,
sector_count -= sectors_per_block) {
if (SPIEraseBlock(current_sector / sectors_per_block)) {
return 3;
}
}

for (; current_sector < end;
++current_sector, --sector_count) {
if (SPIEraseSector(current_sector)) {
return 4;
}
}

return 0;
}

int copy_raw(const uint32_t src_addr,
const uint32_t dst_addr,
const uint32_t size)
{
ets_putc('\n');
ets_putc('c');
ets_putc('p');
ets_putc('\n');
// require regions to be aligned
if (src_addr & 0xfff != 0 ||
dst_addr & 0xfff != 0) {
return 1;
}

if (erase(dst_addr, size)) {
if (SPIEraseAreaEx(dst_addr, size)) {
return 2;
}

Expand Down Expand Up @@ -153,17 +120,25 @@ void main()
int res = 9;
struct eboot_command cmd;

eboot_command_read(&cmd);
if (eboot_command_read(&cmd)) {
cmd.action = ACTION_LOAD_APP;
cmd.args[0] = 0;
ets_putc('e');
} else {
ets_putc('@');
}
eboot_command_clear();

if (cmd.action == ACTION_COPY_RAW) {
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2]);
if (res == 0) {
cmd.action = ACTION_LOAD_APP;
cmd.args[0] = cmd.args[1];
}
}

if (cmd.action == ACTION_LOAD_APP) {
res = load_app_from_flash_raw(0);
res = load_app_from_flash_raw(cmd.args[0]);
}

if (res) {
Expand Down
Binary file modified hardware/esp8266com/esp8266/bootloaders/eboot/eboot.elf
Binary file not shown.
26 changes: 22 additions & 4 deletions hardware/esp8266com/esp8266/bootloaders/eboot/eboot_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ uint32_t eboot_command_calculate_crc32(const struct eboot_command* cmd)
offsetof(struct eboot_command, crc32));
}

void eboot_command_read(struct eboot_command* cmd)
int eboot_command_read(struct eboot_command* cmd)
{
const uint32_t dw_count = sizeof(struct eboot_command) / sizeof(uint32_t);
uint32_t* dst = (uint32_t *) cmd;
Expand All @@ -39,9 +39,27 @@ void eboot_command_read(struct eboot_command* cmd)
uint32_t crc32 = eboot_command_calculate_crc32(cmd);
if (cmd->magic & EBOOT_MAGIC_MASK != EBOOT_MAGIC ||
cmd->crc32 != crc32) {

cmd->action = ACTION_LOAD_APP;
cmd->args[0] = 0;
return 1;
}

return 0;
}

void eboot_command_write(struct eboot_command* cmd)
{
cmd->magic = EBOOT_MAGIC;
cmd->crc32 = eboot_command_calculate_crc32(cmd);

const uint32_t dw_count = sizeof(struct eboot_command) / sizeof(uint32_t);
const uint32_t* src = (const uint32_t *) cmd;
for (uint32_t i = 0; i < dw_count; ++i) {
RTC_MEM[i] = src[i];
}
}

void eboot_command_clear()
{
RTC_MEM[offsetof(struct eboot_command, magic) / sizeof(uint32_t)] = 0;
RTC_MEM[offsetof(struct eboot_command, crc32) / sizeof(uint32_t)] = 0;
}

12 changes: 10 additions & 2 deletions hardware/esp8266com/esp8266/bootloaders/eboot/eboot_command.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/* Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
* This file is part of eboot bootloader.
*
* Redistribution and use is permitted according to the conditions of the
* 3-clause BSD license to be found in the LICENSE file.
*/

#ifndef EBOOT_COMMAND_H
#define EBOOT_COMMAND_H

Expand All @@ -23,7 +30,8 @@ struct eboot_command {
};


void eboot_command_read(struct eboot_command* cmd);

int eboot_command_read(struct eboot_command* cmd);
void eboot_command_write(struct eboot_command* cmd);
void eboot_command_clear();

#endif //EBOOT_COMMAND_H
49 changes: 49 additions & 0 deletions hardware/esp8266com/esp8266/bootloaders/eboot/flash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
* This file is part of eboot bootloader.
*
* Redistribution and use is permitted according to the conditions of the
* 3-clause BSD license to be found in the LICENSE file.
*/

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "flash.h"


int SPIEraseAreaEx(const uint32_t start, const uint32_t size)
{
if (start & (FLASH_SECTOR_SIZE - 1) != 0) {
return 1;
}

const uint32_t sectors_per_block = FLASH_BLOCK_SIZE / FLASH_SECTOR_SIZE;
uint32_t current_sector = start / FLASH_SECTOR_SIZE;
uint32_t sector_count = (size + FLASH_SECTOR_SIZE - 1) / FLASH_SECTOR_SIZE;
const uint32_t end = current_sector + sector_count;

for (; current_sector < end && (current_sector & (sectors_per_block-1));
++current_sector, --sector_count) {
if (SPIEraseSector(current_sector)) {
return 2;
}
}

for (;current_sector + sectors_per_block <= end;
current_sector += sectors_per_block,
sector_count -= sectors_per_block) {
if (SPIEraseBlock(current_sector / sectors_per_block)) {
return 3;
}
}

for (; current_sector < end;
++current_sector, --sector_count) {
if (SPIEraseSector(current_sector)) {
return 4;
}
}

return 0;
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
* 3-clause BSD license to be found in the LICENSE file.
*/

#ifndef EBOOT_H
#define EBOOT_H

#ifndef FLASH_H
#define FLASH_H

int SPIEraseBlock(uint32_t block);
int SPIEraseSector(uint32_t sector);
int SPIRead(uint32_t addr, void *dest, size_t size);
int SPIWrite(uint32_t addr, void *src, size_t size);

int SPIEraseAreaEx(const uint32_t start, const uint32_t size);

#define FLASH_SECTOR_SIZE 0x1000
#define FLASH_BLOCK_SIZE 0x10000
Expand Down Expand Up @@ -41,4 +40,4 @@ typedef struct {



#endif //EBOOT_H
#endif //FLASH_H
Loading

0 comments on commit 45b5baf

Please sign in to comment.