Skip to content

Commit

Permalink
Merge branch 'doc/fix_1' into 'feature/esp_as_mcu_host'
Browse files Browse the repository at this point in the history
Update spi_full_duplex.md

See merge request app-frameworks/esp_hosted!502
  • Loading branch information
mantriyogesh committed Sep 19, 2024
2 parents ddf29e1 + 2ed13d3 commit c1e1e70
Show file tree
Hide file tree
Showing 12 changed files with 2,297 additions and 840 deletions.
577 changes: 213 additions & 364 deletions README.md

Large diffs are not rendered by default.

File renamed without changes.
27 changes: 20 additions & 7 deletions docs/design_consideration.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,27 @@ connected together. Verify that the correct GPIOs are set-up in
> under Hosted. Check the ESP datasheet to verify the GPIOs you select
> can be used as a Hosted interface.
### 2.2. Using SPI insted of SDIO
### 2.2. Evaluate with jumpers first

In general, SPI imposes fewer hardware requirements compared to
It is flexible to evaluate with jumper cables or bread board than full-fledged PCB.
In general, SPI (Standard & Dual SPI) imposes fewer hardware requirements compared to
SDIO. SPI is easier to prototype, and available on more ESP chips and
MCUs compared to SDIO.

However, if you need a high-speed interface, SDIO should be
considered.
Before going to SDIO 4 bit mode PCB, it's better to evaluate SDIO 1-Bit mode.

Once you evaluate the solution on jumper cables, you can move to PCB solutions with same or high performance transport.

###### Jumper cable considerations
- Use high quality jumper cables
- Use jumper cables as small as possible. you can cut and solder the joints if need be.
- Use equal length jumper cables for all the connections
- Grounds: Connect as many grounds as possible, this lowers the interference.
- Jumper cable lengths
- Standard SPI: At max 10cm, lower the better
- Dual SPI: At max 10cm, lower the better
- SDIO 1 Bit: At max 5cm, lower the better
- Quad SPI : jumpers not supported, only PCB
- SDIO 4 Bit: Jumpers not supported, only PCB

### 2.3. Whenever possible, Use `IO_MUX` GPIOs.

Expand Down Expand Up @@ -102,7 +115,7 @@ For jumper cables, you can try surrounding the signals, especially the

> [!NOTE]
> For SDIO, external pull-up resistors (recommended value: 51 kOhms)
> are required. Using jumper cable are not recommended for SDIO. You
> are required. Using jumper cable are **not** recommended for SDIO. You
> may be able to get SDIO working with jumper cables by using a lower
> `CLK` frequency and using 1-bit SDIO mode.
Expand Down Expand Up @@ -130,7 +143,7 @@ be used to light a LED or trigger a capture on an oscilloscope or
logic analyzer, for example. This is useful for capturing rare or
intermittent conditions while testing Hosted.

In the future, Hosted may also offer more features, like controlling
In the future, Hosted may also offer newer transport options or more features, like controlling
power modes on the Host and Slave. These may require additional GPIOs
for control, so it would be good to keep some additional GPIOs
available and accesable for future use.
Expand Down
200 changes: 161 additions & 39 deletions docs/esp32_p4_function_ev_board.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,127 @@
# ESP-Hosted on the ESP32-P4-Function-EV-Board DevKit

**Table of Contents**

- [1. Introduction](#1-introduction)
- [2. Building ESP-Hosted as Host for the P4](#2-building-esp-hosted-as-host-for-the-p4)
- [2.1. Adding Wifi Remote and Hosted Components](#21-adding-wifi-remote-and-hosted-components)
- [2.2. Building the Firmware](#22-building-the-firmware)
- [3. Checking that ESP-Hosted is Running](#3-checking-that-esp-hosted-is-running)
- [4. Flashing the On-board ESP32-C6 using ESP-Prog](#4-flashing-the-on-board-esp32-c6-using-esp-prog)
- [5. Troubleshooting](#5-troubleshooting)
- [6. Flashing the On-board ESP32-P4 through the Serial Interface](#6-flashing-the-on-board-esp32-p4-through-the-serial-interface)
- [7. References](#7-references)
<details>
<summary>**Table of Contents**</summary>

- [Introduction](#1-introduction)
- [Set-Up ESP-IDF](#2-set-up-esp-idf)
- [Building Host for the P4](#3-building-host-for-the-p4)
- [Adding Components](#31-adding-components)
- [Configuring Defaults](#32-configuring-defaults)
- [Building Firmware](#33-building-firmware)
- [Checking ESP-Hosted](#4-checking-esp-hosted)
- [Flashing ESP32-C6](#5-flashing-esp32-c6)
- [Using ESP-Prog](#51-using-esp-prog)
- [OTA Updates](#52-ota-updates)
- [Troubleshooting](#6-troubleshooting)
- [Flashing the On-board ESP32-P4 through the ESP-Prog](#7-flashing-esp32-p4)
- [References](#8-references)

</details>

## 1. Introduction

This page documents using ESP-Hosted on the
ESP32-P4-Function-EV-Board. The board comes with an on-board ESP32-C6
module, pre-flashed with ESP-Hosted slave code (v0.0.6). The board
provides a Wi-Fi connection to the on-board ESP32-P4, which acts as
the host.
This page documents using ESP-Hosted-MCU on the ESP32-P4-Function-EV-Board. The board comes with an on-board ESP32-C6 module, pre-flashed with ESP-Hosted-MCU slave code (v0.0.6). The board provides a Wi-Fi connection to the on-board ESP32-P4, which acts as the host.

The image below shows the board.

<img src="images/esp32-p4-function-ev-board.jpg"
alt="ESP32-P4-Function-EV-Board" width="800" />
<img src="images/esp32-p4-function-ev-board.jpg" alt="ESP32-P4-Function-EV-Board" width="800" />

*ESP32-P4-Function-EV-Board*

The ESP32-P4 communicates with the ESP32-C6 module using SDIO.

## 2. Building ESP-Hosted as Host for the P4
## 2. Set-Up ESP-IDF

As you have reached here, it is highly likely that you have already setup ESP-IDF.

If not done, Please set up ESP-IDF:

#### Option 1: Installer Way

- **Windows**
- Install and setup ESP-IDF on Windows as documented in the [Standard Setup of Toolchain for Windows](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/windows-setup.html).
- Use the ESP-IDF [Powershell Command Prompt](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/windows-setup.html#using-the-command-prompt) for subsequent commands.

- **Linux or MacOS**
- For bash:
```bash
bash docs/setup_esp_idf__latest_stable__linux_macos.sh
```
- For fish:
```fish
fish docs/setup_esp_idf__latest_stable__linux_macos.fish
```

#### Option 2: Manual Way

### 2.1. Adding Wifi Remote and Hosted Components
Please follow the [ESP-IDF Get Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html) for manual installation.

The Wi-Fi service is provided to the ESP32-P4 using the
`esp_wifi_remote` component. Check your project's `idf_component.yml`
file) to see if it is already present. If not, you can add this
component to your project:
## 3. Building Host for the P4

### 3.1. Adding Components

Add `esp_wifi_remote` and `esp_hosted` components to the project:

```
idf.py add-dependency "espressif/esp_wifi_remote"
idf.py add-dependency "espressif/esp_hosted"
```
Remove 'esp-extconn' if present in `main/idf_component.yml`, as esp-extconn and esp-hosted cannot work together.
Open the `main/idf_component.yml` file and remove/comment the following block if present:
```
# ------- Delete or comment this block ---------
espressif/esp-extconn:
version: "~0.1.0"
rules:
- if: "target in [esp32p4]"
# -----------------------------------
```
The `esp_wifi_remote` component has a dependency on ESP-Hosted and
will also add the `esp_hosted` component to your build.
It is always good to use `esp_wifi_remote` as it provides all the Wi-Fi config and a wrapper abstraction layer.
But you can also evaluate without using it.
### 2.2. Building the Firmware
### 3.2. Configuring Defaults
Edit the `sdkconfig.defaults.esp32p4` file such that, it would have following content:
```
#### Comment below two lines if present:
# CONFIG_ESP_HOST_WIFI_ENABLED=y
# CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y

#### Add Wi-Fi Remote config for better performance:
CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=16
CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=64
CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM=64
CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=y
CONFIG_ESP_WIFI_TX_BA_WIN=32
CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y
CONFIG_ESP_WIFI_RX_BA_WIN=32

CONFIG_LWIP_TCP_SND_BUF_DEFAULT=65534
CONFIG_LWIP_TCP_WND_DEFAULT=65534
CONFIG_LWIP_TCP_RECVMBOX_SIZE=64
CONFIG_LWIP_UDP_RECVMBOX_SIZE=64
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=64

CONFIG_LWIP_TCP_SACK_OUT=y
```
### 3.3. Building Firmware
Set the ESP32-P4 as the target, build, flash the firmware and
(optionally) monitor ESP32-P4 console output:
```sh
idf.py set-target esp32p4
idf.py build
idf.py -p <Serial Port> flash monitor`
idf.py -p <Serial Port> flash monitor
```

## 3. Checking that ESP-Hosted is Running
## 4. Checking ESP-Hosted

When the P4 is running with Hosted, you should see console output similar to this after start-up:

Expand Down Expand Up @@ -114,17 +179,68 @@ I (1848) H_SDIO_DRV: Received INIT event
I (1868) rpc_wrap: Received Slave ESP Init
```

## 4. Flashing the On-board ESP32-C6 using ESP-Prog
## 5. Flashing ESP32-C6
ESP32-C6 flashing is totally **optional**, as C6 is expected to be pre-flashed with ESP-Hosted slave firmware, 0.0.6. If you wish to get updated ESP-Hosted slave firmware, you can flash it using two ways, Either with ESP-Prog on ESP32-C6, or using OTA update configured using web server.

### 5.1 OTA Updates

To update the ESP32-C6 slave module using Over-The-Air (OTA) updates, follow these steps:

1. Build the ESP-Hosted slave firmware for the ESP32-C6 module:

```
idf.py create-project-from-example "espressif/esp_hosted:slave"
```

2. Set the target and start `Menuconfig`:

```sh
idf.py set-target esp32c6
idf.py menuconfig
```

3. Under **Example Configuration**, ensure that the Hosted transport
selected is `SDIO`.

4. Build the firmware:

```sh
idf.py build
```

5. Upload the firmware (the build/network_adapter.bin file) to a server or a local directory accessible via HTTP.

6. On the ESP32-P4 host, add the following code to your application to initiate the OTA update:

```
#include "esp_hosted.h"
esp_err_t esp_hosted_ota_start(const char *url);
```

7. Call the `esp_hosted_ota_start` function with the URL of the firmware binary:

```
esp_err_t err = esp_hosted_ota_start("http://example.com/path/to/network_adapter.bin");
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to start OTA update: %s", esp_err_to_name(err));
}
```

8. Monitor the console output to see the OTA update progress.

### 5.2 Using ESP-Prog

> [!NOTE]
> ESP-Prog is only required if you want to flash firmware to the
> ESP32-C6 module using the standard ESP Tools.
This step is optional, as C6 is expected to be pre-flashed with ESP-Hosted slave firmware, 0.0.6.

The image below shows the board with an ESP-Prog connected to the
header to communicate with the on-board ESP32-C6..

<img src="images/esp32-p4-function-ev-board-esp-prog.jpg"
alt="ESP32-P4-Function-EV-Board with ESP-Prog Connected to ESP32-C6" width="800" />
<img src="images/esp32-p4-function-ev-board-esp-prog.jpg" alt="ESP32-P4-Function-EV-Board with ESP-Prog Connected to ESP32-C6" width="800" />

*ESP32-P4-Function-EV-Board with ESP-Prog Connected to ESP32-C6*

Expand All @@ -133,7 +249,6 @@ ESP32-C6 module using ESP-Prog, follow these steps:

1. Check out the ESP-Hosted slave example project:

```
idf.py create-project-from-example "espressif/esp_hosted:slave"
```
Expand Down Expand Up @@ -174,28 +289,36 @@ prevent the P4 interfering with the C6 while flashing (by asserting
the C6 Reset signal during the firmware download), set the P4 into
Bootloader mode before flashing the firmware to the C6:

###### Manual Way
1. hold down the `BOOT` button on the board
2. press and release the `RST` button on the board
3. release the `BOOT` button

###### Script Way

```sh
esptool.py -p <host_serial_port> --before default_reset --after no_reset run
```

You can now flash the firmware to the C6 (and monitor the console
output):

```sh
idf.py -p <Serial Port> flash monitor
```

## 5. Troubleshooting


## 6. Troubleshooting

If you encounter issues with using ESP-Hosted, see the following guide:

- [Troubleshooting Guide](troubleshooting.md)

<details>

<summary>Flashing the On-board ESP32-P4 through the Serial Interface</summary>

## 6. Flashing the On-board ESP32-P4 through the Serial Interface
## 7. Flashing the On-board ESP32-P4 through the ESP-Prog

The USB connector on the board is the standard method for flashing the
firmware to the P4. An alternative method is to flash the P4 through
Expand All @@ -204,8 +327,7 @@ its serial interface using a ESP-Prog.
The image below shows the connection between the ESP-Prog and the
serial port pins on the P4 header for programming.

<img src="images/esp32-p4-esp-prog.jpg"
alt="ESP32-P4 Serial Connection with ESP-Prog" width="600" />
<img src="images/esp32-p4-esp-prog.jpg" alt="ESP32-P4 Serial Connection with ESP-Prog" width="600" />

*ESP32-P4 Serial Connection with ESP-Prog*

Expand Down Expand Up @@ -236,7 +358,7 @@ on the board.

</details>

## 7. References
## 8. References

- ESP32-P4-Function-EV-Board: https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32p4/esp32-p4-function-ev-board/
- ESP-Prog: https://docs.espressif.com/projects/esp-iot-solution/en/latest/hw-reference/ESP-Prog_guide.html
Expand Down
4 changes: 4 additions & 0 deletions docs/images/ESP-Hosted-FG-MCU_design.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c1e1e70

Please sign in to comment.