Skip to content

Commit

Permalink
Merge branch 'spi_slace_c3' into 'master'
Browse files Browse the repository at this point in the history
Support for ESP32-C3 added

See merge request app-frameworks/esp_hosted!132
  • Loading branch information
Mangesh Malusare committed Aug 3, 2021
2 parents 0f7ce11 + 82d0e3e commit dacac83
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 130 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ESP-Hosted solution provides following WLAN and BT/BLE features to host:
ESP-Hosted solution is supported on following ESP boards:
- ESP32
- ESP32S2
- ESP32C3

### 1.3 Supported Hosts

Expand Down Expand Up @@ -75,18 +76,24 @@ Below table explains which feature is supported on which transport interface for
| ESP32-S2 | SDIO | NA | NA | NA |
| ESP32-S2 | SPI | Yes | Yes | NA |
| ESP32-S2 | UART | No | No | NA |
| ESP32-C3 | SDIO | NA | NA | NA |
| ESP32-C3 | SPI | Yes | Yes | No |
| ESP32-C3 | UART | No | No | No |

##### 1.5.2 MCU Host
Below table explains which feature is supported on which transport interface for MCU based host.

| ESP device | Transport Interface | WLAN support | Virtual serial interface | BT/BLE support |
|:---------:|:-------:|:---------:|:--------:|:--------:|
|:------------:|:-------:|:---------:|:--------:|:--------:|
| ESP32 | SDIO | No | No | No |
| ESP32 | SPI | Yes | Yes | HCI interface can be implemented over virtual serial interface |
| ESP32 | UART | No | No | No |
| ESP32-S2 | SDIO | NA | NA | NA |
| ESP32-S2 | SPI | Yes | Yes | NA |
| ESP32-S2 | UART | No | No | NA |
| ESP32-C3 | SDIO | NA | NA | NA |
| ESP32-C3 | SPI | Yes | Yes | No |
| ESP32-C3 | UART | No | No | No |

---

Expand Down
15 changes: 11 additions & 4 deletions docs/Linux_based_host/Linux_based_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This document explains ESP-Hosted setup and usage. The document is divided in tw
### 1.1 Hardware Requirements
* Raspberry-Pi model 3 Model B/B+ or Raspberry-Pi 4 model B
* ESP32 board
* 8-12 jumper wires of 10cm length
* 8-12 jumper wires of length < 10cm

### 1.2 Host Setup
Make sure that Raspberry-Pi is equipped with following:
Expand All @@ -44,13 +44,19 @@ Make sure that Raspberry-Pi is equipped with following:
* Python 2.x or 3.x
```sh
$ sudo apt install python
$ sudo apt install python-pip
```
or
```sh
$ sudo apt install python3
$ sudo apt install python3-pip
```
* Protobuf
```sh
$ pip install protobuf
```
or
```sh
$ pip3 install protobuf
```
* Clone ESP-Hosted code repository
Expand Down Expand Up @@ -114,7 +120,7 @@ write_flash --flash_mode dio --flash_freq 40m --flash_size detect \

Where,
<serial_port> : serial port of ESP peripheral
<esp_peripheral> : esp32/esp32s2
<esp_peripheral> : esp32/esp32s2/esp32c3
<interface_type> : sdio/spi/sdio_uart
<release_version>: 0.1,0.2 etc
```
Expand Down Expand Up @@ -150,7 +156,7 @@ This section identifies Raspberry-Pi specific setup requirements.
$ sudo apt update
$ sudo apt install raspberrypi-kernel-headers
```
* Verify that kernel headers are installed properly by running following command. Failure of this command indicates that kernel headers are not installed correctly. In such case, follow https://github.com/notro/rpi-source/wiki and run rpi-source to get current kernel headers. Alternatively upgrade/downgrade kernel and reinstall kernel headers.
* Verify that kernel headers are installed properly by running following command. Failure of this command indicates that kernel headers are not installed correctly. In such case, follow https://github.com/notro/rpi-source/wiki and run `rpi-source` to get current kernel headers. Alternatively upgrade/downgrade kernel and reinstall kernel headers.
```sh
$ ls /lib/modules/$(uname -r)/build
```
Expand Down Expand Up @@ -185,7 +191,7 @@ This section identifies Raspberry-Pi specific setup requirements.
$ pip3 install protobuf
```
* Bluetooth Stack and utilities:
:warning:`Note: We have tested ESP-Hosted solution with bluez 5.43 and 5.45`
:warning:`Note: We have tested ESP-Hosted solution with bluez 5.43+`
* bluetooth
* bluez
* bluez-tools
Expand All @@ -201,6 +207,7 @@ ESP-IDF release version to be used for ESP peripherals are
|:----:|:----:|
| ESP32 | release v4.0 |
| ESP32-S2 | release v4.2 |
| ESP32-C3 | release v4.3 |

Clone appropriate ESP-IDF version as per your ESP peripheral. The control path between Linux host and ESP peripheral is based on `protobuf`. For that, corresponding stack layer, `protocomm` from ESP-IDF is used. Run following command in ESP-IDF directory to make `protocomm_priv.h` available for control path.
```
Expand Down
16 changes: 16 additions & 0 deletions docs/Linux_based_host/SPI_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ Setup image is here.

![alt text](rpi_esp32_s2_setup.jpg "setup of Raspberry-Pi as host and ESP32-S2 as ESP peripheral")

#### 1.1.3 ESP32-C3 setup
| Raspberry-Pi Pin | ESP32-C3 Pin | Function |
|:----------------:|:------------:|:--------:|
| 24 | IO10 | CS0 |
| 23 | IO06 | SCLK |
| 21 | IO02 | MISO |
| 19 | IO07 | MOSI |
| 25 | GND | Ground |
| 11 | IO03 | Handshake |
| 13 | IO04 | Data ready |
| 31 | RST | ESP32 Reset |

Setup image is here.

![alt text](rpi_esp32_c3_setup.jpg "setup of Raspberry-Pi as host and ESP32-C3 as ESP peripheral")

### 1.2 Raspberry-Pi Software Setup
The SPI master driver is disabled by default on Raspberry-Pi OS. To enable it add following commands in _/boot/config.txt_ file
```
Expand Down
Binary file added docs/Linux_based_host/rpi_esp32_c3_setup.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 16 additions & 16 deletions docs/MCU_based_host/Getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ Wi-Fi can be configured as either as `STATION` mode or `SOFTAP` mode or `STATION
* **STATION+SOFTAP Mode**
- This is combination of both the modes. In this mode, host behaves as station and connects to external AP. At the same time, host with help of ESP device, can create the Wi-Fi network.

Host firmware provides wifi connectivity using control path and data path. Control path commands uses `protocomm` layer of ESP-IDF to serialize structured control data and communicates using SPI transport interface between Host(MCU based Host) and ESP peripheral (ESP32/ESP32-S2). User can use control commands to build application.
Host firmware provides wifi connectivity using control path and data path. Control path commands uses `protocomm` layer of ESP-IDF to serialize structured control data and communicates using SPI transport interface between Host(MCU based Host) and ESP peripheral (ESP32/ESP32-S2/ESP32-C3). User can use control commands to build application.


### 1.1 Start Project with STM32

We have tested project with STM32F469I-Discovery board. If other than STM32F469I-Discovery board is used, peripheral like SPI, USART need to change as per board needs. STM32CubeIDE would be needed to follow next steps.

1) Create a workspace_directory outside of `ESP-Hosted` git cloned directory.
2) Browse and Open Workspace directory in STM32CubeIDE. It will take few seconds to open STM32CubeIDE.
3) From `Information Center` tab select `Start new project` from existing STM32CubeMX configuration file, i.e. ioc file option. It will take few seconds to open dialog box. In STM32CubeMX .ioc file field, choose appropriate .ioc file from `</path/to/esp_hosted>/host/stm32/proj/` directory.
* Create a workspace_directory outside of `ESP-Hosted` git cloned directory.
* Browse and Open Workspace directory in STM32CubeIDE. It will take few seconds to open STM32CubeIDE.
* From `Information Center` tab select `Start new project` from existing STM32CubeMX configuration file, i.e. ioc file option. It will take few seconds to open dialog box. In STM32CubeMX .ioc file field, choose appropriate .ioc file from `</path/to/esp_hosted>/host/stm32/proj/` directory.
```
For ESP32 peripheral: Select stm_spi_host_esp32.ioc file
For ESP32-S2 peripheral: Select stm_spi_host_esp32s2.ioc file
For ESP32-S2/ESP32-C3 peripheral: Select stm_spi_host_esp32s2_esp32c3.ioc file
```
4) Once file is selected, click `Open` and `Finish`. New dialog box will open as Open Associated Perspective, click on `Yes`. It may take 2-3 minutes to open. ESP_peripheral_hardware currently supported as either ESP32 or ESP32-S2.
4) Close ioc tab then close STM32CubeIDE and click on `exit`.
5) For Linux and Mac development hosts, In terminal, run
* Once file is selected, click `Open` and `Finish`. New dialog box will open as Open Associated Perspective, click on `Yes`. It may take 2-3 minutes to open. ESP_peripheral_hardware currently supported are ESP32, ESP32-S2 and ESP32-C3.
* Close ioc tab then close STM32CubeIDE and click on `exit`.
* For Linux and Mac development hosts, In terminal, run
```
$ cd </path/to/esp_hosted>/host/stm32/proj
$ bash ./prepare_project.sh </path/to/workspace_directory>
Expand All @@ -40,18 +40,18 @@ For Windows based systems, open "cmd.exe" or Windows Power Shell and run -
```
This will copy the project configuration files into workspace_directory

6) Re-open STM32CubeIDE with workspace as workspace_directory.
7) Ignore all warnings under `Problems` tab if any.
8) Configure all build variables as mentioned in [User configuration parameter](#12-user-configuration-parameter) section below. Variable `CODE_BASE` should already be populated. All parameters are mandatory to be filled. Please note that, every subsequent change in configuration parameter would need a clean build as mentioned ahead.
9) Uncheck `Build Automatically` from `menu -> Project` and Clean build the project as `Project menu -> Clean -> clean`.
10) Connect STM32 board to your machine if not already connected.
11) Before flashing the project, Open Tera Term or minicom to see STM32 debug logs once project flashed.
* Re-open STM32CubeIDE with workspace as workspace_directory.
* Ignore all warnings under `Problems` tab if any.
* Configure all build variables as mentioned in [User configuration parameter](#12-user-configuration-parameter) section below. Variable `CODE_BASE` should already be populated. All parameters are mandatory to be filled. Please note that, every subsequent change in configuration parameter would need a clean build as mentioned ahead.
* Uncheck `Build Automatically` from `menu -> Project` and Clean build the project as `Project menu -> Clean -> clean`.
* Connect STM32 board to your machine if not already connected.
* Before flashing the project, Open Tera Term or minicom to see STM32 debug logs once project flashed.
```
$ minicom -D /dev/ttyACM0
```
Note: /dev/ttyACM0 is used for For Linux, /dev/cu.usbmodemXXXXXX for Mac and COM port for Windows development host. Baud rate used is 115200. Parity bits configuration is 8N1.

12) In STM32CubeIDE, go to `Project Explorer`, right click on `stm_spi_host` project. Then `menu -> Run -> Run as -> STM32 Cortex-M C/C++ Application `. This will open Edit Configuration box, Click `OK`.
* In STM32CubeIDE, go to `Project Explorer`, right click on `stm_spi_host` project. Then `menu -> Run -> Run as -> STM32 Cortex-M C/C++ Application `. This will open Edit Configuration box, Click `OK`.
`Debug as` option can also be alternatively used if debugging is desired.

Expected output on `Console` tab in STM32CubeIDE as follows:
Expand Down Expand Up @@ -163,7 +163,7 @@ Once the connection is setup between STM32 and ESP peripheral, ARP can be tested
For station mode, `INPUT_STATION_SRC_IP` is used as STM32 IPv4 address and `INPUT_STATION_ARP_DEST_IP` is considered as destination IPv4 address. This could be configured as IPv4 address of your machine.
For softAP mode, `INPUT_SOFTAP_SRC_IP` will be used as STM32 IPv4 address and `INPUT_SOFTAP_ARP_DEST_IP` used as destination IPv4 address.

Please note,
**Please note**,
1. In case of softAP mode, only static IPv4 addresses are supported currently. You can use your machine to connect to softAP and assign static address as `INPUT_SOFTAP_ARP_DEST_IP`.
2. IP addresses configured are in same subnet for that interface.

Expand Down
51 changes: 29 additions & 22 deletions docs/MCU_based_host/MCU_based_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ Setup image is here.

![alt text](stm_esp32_s2_setup.jpg "Setup of STM32F469I as host and ESP32-S2 as peripheral")

#### Hardware connections for ESP32-C3
| STM32 Pin | ESP32-C3 Pin | Function |
|:---------:|:-----------:|:--------:|
| PB4 (pin5) | IO02 | MISO |
| PA5 (pin7) | IO06 | CLK |
| PB5 (pin9) | IO07 | MOSI |
| PA15 (pin11)| IO10 | CS |
| GND (pin2) | GND | GND |
| PC6 (pin6) | IO03 | Handshake |
| PC7 (pin8) | IO04 | Data ready from ESP |
| PB13 (pin10) | RST | Reset ESP |

Setup image is here.

![alt text](stm_esp32_c3_setup.jpg "Setup of STM32F469I as host and ESP32-C3 as peripheral")

# 2. ESP peripheral setup
## 2.1 ESP-IDF requirement
MCU based ESP-Hosted solution is compatible with ESP-IDF version 4.0 and above.
Expand All @@ -86,33 +102,20 @@ $ git mv components/protocomm/src/common/protocomm_priv.h components/protocomm/i

#### 2.2.1 Using pre-built binary
For pre built hosted mode firmware is present in `release` tab. Execute below command to flash it on ESP peripheral.
##### ESP32
```sh
$ python esptool.py --chip esp32 --port <serial_port> --baud 960000 --before default_reset \
--after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect \
0x1000 esp_hosted_bootloader_esp32_spi_v<release_version>.bin \
0x10000 esp_hosted_firmware_esp32_spi_v<release_version>.bin \
0x8000 esp_hosted_partition-table_esp32_spi_v<release_version>.bin

Where,
<serial_port> : serial port of ESP peripheral
<release_version>: 0.1,0.2 etc. Latest from [release page](https://github.com/espressif/esp-hosted/releases)
```
* This command will flash `SPI` interface binaries on `esp32` chip.

##### ESP32-S2
```sh
$ python esptool.py --port <serial_port> --baud 960000 --before default_reset --after hard_reset \
--chip esp32s2 write_flash --flash_mode dio --flash_size detect --flash_freq 80m \
0x1000 esp_hosted_bootloader_esp32s2_spi_v<release_version>.bin \
0x8000 esp_hosted_partition-table_esp32s2_spi_v<release_version>.bin \
0x10000 esp_hosted_firmware_esp32s2_spi_v<release_version>.bin
$ python esptool.py --chip <chipset> --port <serial_port> --baud 960000 --before default_reset \
--after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect \
0x1000 esp_hosted_bootloader_<chipset>_spi_v<release_version>.bin \
0x10000 esp_hosted_firmware_<chipset>_spi_v<release_version>.bin \
0x8000 esp_hosted_partition-table_<chipset>_spi_v<release_version>.bin

Where,
<chipset> : esp32/esp32s2/esp32c3
<serial_port> : serial port of ESP peripheral
<release_version>: 0.1,0.2 etc. Latest from [release page](https://github.com/espressif/esp-hosted/releases)
```
* This command will flash `SPI` interface binaries on `esp32s2` chip.
* This command will flash `SPI` interface binaries on ESP module

For windows user, you can also program the binaries using ESP Flash Programming Tool.

Expand All @@ -126,7 +129,7 @@ $ git mv components/protocomm/src/common/protocomm_priv.h components/protocomm/i
Navigate to `esp/esp_driver/network_adapter` directory
##### Using make

:warning: *make* build system is only supported till ESP32. Please refer cmake section below for ESP32-S2.
:warning: *make* build system is only supported till ESP32. Please refer cmake section below for other ESP modules.

```
$ make clean
Expand All @@ -148,10 +151,14 @@ $ make flash
```
$ idf.py fullclean
```
:warning: Skip this step for ESP32. Run for ESP32-S2 only.
:warning: Skip this step for ESP32. Run for ESP32-S2 or ESP32-C3 only.
```
$ idf.py set-target esp32s2
```
or
```
$ idf.py set-target esp32c3
```

Run following command and navigate to `Example Configuration -> Transport layer -> SPI interface -> select` and exit from menuconfig. Read more about [idf.py](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-guides/build-system.html#using-the-build-system) here.
```
Expand Down
Binary file added docs/MCU_based_host/stm_esp32_c3_setup.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions esp/esp_driver/network_adapter/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ menu "Example Configuration"

config ESP_SPI_GPIO_HANDSHAKE
int "GPIO pin for handshake"
default 3 if IDF_TARGET_ESP32C3
default 2
help
GPIO pin to use for handshake with other spi controller
Expand Down
13 changes: 9 additions & 4 deletions esp/esp_driver/network_adapter/main/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include "nvs_flash.h"
#include "sdkconfig.h"
#include <unistd.h>
#ifndef CONFIG_IDF_TARGET_ARCH_RISCV
#include "xtensa/core-macros.h"
#endif
#include "esp_private/wifi.h"
#include "interface.h"
#include "esp_wpa.h"
Expand Down Expand Up @@ -324,7 +326,7 @@ void send_task(void* pvParameters)
ESP_LOG_BUFFER_HEXDUMP(TAG_TX, buf_handle.payload, buf_handle.payload_len, ESP_LOG_INFO);
#endif
/* Post processing */
if (buf_handle.free_buf_handle) {
if (buf_handle.free_buf_handle && buf_handle.priv_buffer_handle) {
buf_handle.free_buf_handle(buf_handle.priv_buffer_handle);
buf_handle.priv_buffer_handle = NULL;
}
Expand All @@ -345,8 +347,10 @@ void send_task(void* pvParameters)
#endif

/* Post processing */
if (buf_handle.free_buf_handle)
if (buf_handle.free_buf_handle && buf_handle.priv_buffer_handle) {
buf_handle.free_buf_handle(buf_handle.priv_buffer_handle);
buf_handle.priv_buffer_handle = NULL;
}
}

sleep(1);
Expand Down Expand Up @@ -414,8 +418,9 @@ void process_rx_task(void* pvParameters)
}

/* Free buffer handle */
if (buf_handle.free_buf_handle) {
if (buf_handle.free_buf_handle && buf_handle.priv_buffer_handle) {
buf_handle.free_buf_handle(buf_handle.priv_buffer_handle);
buf_handle.priv_buffer_handle = NULL;
}
}
}
Expand Down Expand Up @@ -447,7 +452,7 @@ void recv_task(void* pvParameters)

if (ret != pdTRUE) {
ESP_LOGE(TAG, "Host -> Slave: Failed to send buffer\n");
if (buf_handle->free_buf_handle) {
if (buf_handle->free_buf_handle && buf_handle->priv_buffer_handle) {
buf_handle->free_buf_handle(buf_handle->priv_buffer_handle);
}
}
Expand Down
Loading

0 comments on commit dacac83

Please sign in to comment.