Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker example #19

Merged
merged 2 commits into from
Aug 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions device/esp32/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
The ESP32 is a low-power Wifi/BL(E) module priced below 3 US-$.

*to work with the examples posted on this page you first have to install the ESP-SDK on your system following this [guide](https://esp-idf.readthedocs.io/en/v1.0/)*

or use a docker image as explained in "docker"
49 changes: 49 additions & 0 deletions device/esp32/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Use an official Python runtime as a parent image
FROM ubuntu


MAINTAINER ESP32-Toolchain

#USER root


# Update aptitude with new repo
RUN apt-get update

# Install software
RUN apt-get install -y git
RUN apt-get install git wget make libncurses-dev flex bison gperf python python-serial -y

#RUN useradd -d /esp32/ -m -s /bin/bash esp32

RUN mkdir -p /home/esp

# Set the working directory to ~/esp/esp-idf
WORKDIR /home/esp

RUN wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz
RUN tar -xzf xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz


#clone GIT
RUN git clone --recursive https://github.com/espressif/esp-idf.git

#go to example directory
#WORKDIR home/esp/hello_world
#RUN make -j5
# Copy the current directory contents into the container at /app
#ADD . /home/app

WORKDIR /home/app


ENV PATH $PATH:"/home/esp/xtensa-esp32-elf/bin"
ENV IDF_PATH "/home/esp/esp-idf"

RUN echo $PATH
RUN echo $IDF_PATH


CMD /bin/bash


60 changes: 60 additions & 0 deletions device/esp32/docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

PROJECT_NAME := hello-world
#this Flag is needed for setting all additional needed as default
BATCH_BUILD=1

include $(IDF_PATH)/make/project.mk


build:
subdirectory docker build --rm -t esp32 .

esp32:
docker run \
--device=/dev/ttyUSB0 \
-v ${shell pwd}:/home/app \
-it esp32 \
-e CROSSBAR_HTTP_BRIDGE \
-e WIFI_KEY \
-e WIFI_SSID \
make -j5 # build the project

esp32_monitor:
docker run \
--device=/dev/ttyUSB0 \
-v ${shell pwd}:/home/app \
-it esp32 \
make monitor # execute the monitor

esp32_flash:
docker run \
--device=/dev/ttyUSB0 \
-v ${shell pwd}:/home/app \
-e CROSSBAR_HTTP_BRIDGE \
-e WIFI_KEY \
-e WIFI_SSID \
-it esp32 \
make flash # flash the program to the chip

esp32_all:
docker run \
--device=/dev/ttyUSB0 \
-v ${shell pwd}:/home/app \
-e WIFI_KEY \
-e CROSSBAR_HTTP_BRIDGE \
-e WIFI_SSID \
-it esp32 \
make -j5 flash monitor # build and flash the program and load the monitor

esp32_bash:
docker run \
--device=/dev/ttyUSB0 \
-v ${shell pwd}:/home/app \
-e WIFI_KEY \
-e CROSSBAR_HTTP_BRIDGE \
-e WIFI_SSID \
-it esp32
71 changes: 71 additions & 0 deletions device/esp32/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Docker for ESP32

this library contains examples for working with an ESP32 and uses the IDE and the toolchain in a docker container.

## What you need
- a ESP-chip
- [docker installed on your pc](https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/)

## Build docker container

First thing you have to build the docker container.
Clone the docker-file in a folder of your choice
Run:
```console
make build
```
it will take a while depend on your download speed and build a docker container named "esp32"

## Build and flash your project

There are different ways to use the makefile:

```console
make esp32
```
will just build your project into a folder named "build"

```console
make esp32_monitor
```
will start the debugging serial monitor for your ESP32 only

```console
make esp32_flash
```
will only build and flash your program to your ESP32

```console
make esp32_all
```
will build and flash your program and start the debug monitor after flashing


```console
make esp32_bash
```

this will start an interactive bash environment in your docker container. this is a great thing for development cause you only have to build the whole library once you open the container.
Next time it will only compile the changes you made.

## Configure the Makefile

of course its possible two adapt the make file for your project and there are several things you need to know:

If you want to set environment variables you have to put an ```-e``` in Front of your variable name like:
```console
-e WIFI_KEY
```
if its a known variable or
```console
-e WIFI_KEY ="foo"
```
if its a new one

if you want to avoid to be asked your project settings you have to set the make variable ```BATCH_BUILD=1```
now the IDE will set all the settings to the default values and most of the times the build will be successful
If there are special settings needed there will be a error prompt and you have to run
```console
make esp32_bash
make menuconfig
```
49 changes: 49 additions & 0 deletions device/esp32/docker/hello_world/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Use an official Python runtime as a parent image
FROM ubuntu


MAINTAINER ESP32-Toolchain

#USER root


# Update aptitude with new repo
RUN apt-get update

# Install software
RUN apt-get install -y git
RUN apt-get install git wget make libncurses-dev flex bison gperf python python-serial -y

#RUN useradd -d /esp32/ -m -s /bin/bash esp32

RUN mkdir -p /home/esp

# Set the working directory to ~/esp/esp-idf
WORKDIR /home/esp

RUN wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz
RUN tar -xzf xtensa-esp32-elf-linux64-1.22.0-61-gab8375a-5.2.0.tar.gz


#clone GIT
RUN git clone --recursive https://github.com/espressif/esp-idf.git

#go to example directory
#WORKDIR home/esp/hello_world
#RUN make -j5
# Copy the current directory contents into the container at /app
#ADD . /home/app

WORKDIR /home/app


ENV PATH $PATH:"/home/esp/xtensa-esp32-elf/bin"
ENV IDF_PATH "/home/esp/esp-idf"

RUN echo $PATH
RUN echo $IDF_PATH


CMD /bin/bash


47 changes: 47 additions & 0 deletions device/esp32/docker/hello_world/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

PROJECT_NAME := hello-world

BATCH_BUILD=1
include $(IDF_PATH)/make/project.mk


build:
sudo docker build --rm -t esp32 .

esp32:
docker run \
--device=/dev/ttyUSB0 \
-v ${shell pwd}:/home/app \
-it esp32 \
make -j5 # build the project

esp32_monitor:
docker run \
--device=/dev/ttyUSB0 \
-v ${shell pwd}:/home/app \
-it esp32 \
make monitor # execute the monitor

esp32_flash:
docker run \
--device=/dev/ttyUSB0 \
-v ${shell pwd}:/home/app \
-it esp32 \
make flash # flash the program to the chip

esp32_all:
docker run \
--device=/dev/ttyUSB0 \
-v ${shell pwd}:/home/app \
-it esp32 \
make -j5 flash monitor # build and flash the program and load the monitor

esp32_bash:
docker run \
--device=/dev/ttyUSB0 \
-v ${shell pwd}:/home/app \
-it esp32
7 changes: 7 additions & 0 deletions device/esp32/docker/hello_world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Hello World Example

Starts a FreeRTOS task to print "Hello World"

it will be compiled and flashed with help of docker

no additional environment-variables or settings needed
5 changes: 5 additions & 0 deletions device/esp32/docker/hello_world/main/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

40 changes: 40 additions & 0 deletions device/esp32/docker/hello_world/main/hello_world_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Hello World Example

This example code is in the Public Domain (or CC0 licensed, at your option.)

Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"


void app_main()
{
printf("Hello world! \n");

/* Print chip information */
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
printf("This is ESP32 chip with %d CPU cores, WiFi%s%s, ",
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");

printf("silicon revision %d, ", chip_info.revision);

printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");

for (int i = 10; i >= 0; i--) {
printf("Restarting in %d seconds...\n", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("Restarting now.\n");
fflush(stdout);
esp_restart();
}
Loading