espressif / esp-hosted-mcu

Apache License 2.0
0 stars 0 forks source link

ESP-Hosted-MCU: Espressif SoCs as Communication Co-Processors

Component Registry

1 Introduction

ESP-Hosted-MCU is an open-source solution that allows you to use Espressif Chipsets and modules as a communication co-processor. This solution provides wireless connectivity (Wi-Fi and Bluetooth) to the host microprocessor or microcontroller, enabling it to communicate with other devices. Additionally, the user has complete control over the co-processor's resources.

This high-level block diagram shows ESP-Hosted's relationship with the host MCU and slave co-processor.

ESP-Hosted

For detailed design diagrams in Wi-Fi and Bluetooth, refer to the following design documents:

This branch, feature/esp_as_mcu_host is dedicated for any host as MCU support. If you are interested in Linux as host, please refer to master branch.

2 Architecture

Hosted Co-Processor

This is an ESP chip that provides Wi-Fi, Bluetooth, and other capabilities. It is also referred as hosted-slave interchangeably.

Host MCU

This can be any generic microcontroller (MCU). We demonstrate any ESP as host. Using port layer, any host can act as host MCU.

Communication

3 Solution Flexibility

4 Quick Demo with ESP32-P4-Function-EV-Board

Impatient to test? We've got you covered! The ESP32-P4-Function-EV-Board can be used as a host MCU with an on-board ESP32-C6 as co-processor, already connected via SDIO as transport. Prerequisite: You need to have an ESP32-P4-Function-EV-Board`

[!NOTE] If you have already set up ESP-IDF (version 5.3 or later), you can skip to 5 Source Code and Dependencies.

4.1 Set-Up ESP-IDF

4.2 Set-Up P4 with C6

The host, ESP32-P4, lacks native Wi-Fi/Bluetooth support. Our Quick Demo will help you run iperf over P4--SDIO--C6.

4.3 Don't Have ESP32-P4-Function-EV-Board?

No worries if you don't have an ESP32-P4. In fact, most users don't. You can choose and use any two ESP chipsets/SoCs/Modules/DevKits. DevKits are convenient to use as they have GPIO headers already in place. From these two ESP chipsets, one would act as host and another as slave/co-processor. However, as these are not connected directly, you would need to manually connect some transport, which is explained later in the section Detailed Setup.

5 Source Code and Dependencies

5.1 ESP-Hosted-MCU Source Code

5.2 Dependencies

ESP-Hosted-MCU Solution is dependent on ESP-IDF, esp_wifi_remote and protobuf-c

ESP-IDF
Wi-Fi Remote
Protobuf
5.2.1 How Dependencies Work Together (short explanation)

6 Decide the communication bus in between host and slave

The communication bus is required to be setup correctly between host and slave. We refer this as transport medium or simply transport.

ESP-Hosted-MCU supports SPI/SDIO/UART transports. User can choose which transport to use. Choosing specific transport depends on factors: high performance, easy and quick to test, number of GPIOs used, or simply co-processor preference

Below is chart for the transport medium comparison.

Legends:

Host can be any ESP chipset or any non-ESP MCU.

Hosted Transports table
Transport Type Num of GPIOs Setup with Co-processor supported Host Tx iperf Host Rx iperf Remarks
Standard SPI FD 6 jumper or PCB Any_Slave udp: 24 tcp: 22 udp: 25 tcp: 22 Simplest solution for quick test
Dual SPI HD 5 jumper or PCB Any_Slave [1] udp: 32 tcp: 26 (O) udp: 33 tcp: 25 (O) Better throughput, but half duplex
Quad SPI HD 7 PCB only Any_Slave [1] udp: 41 tcp: 29 (O) udp: 42 tcp: 28 (O) Due to signal integrity, PCB is mandatory
SDIO 1-Bit HD 4 jumper or PCB ESP32, ESP32-C6 TBD TBD Stepping stone for PCB based SDIO 4-bit
SDIO 4-Bit HD 6 PCB only ESP32, ESP32-C6 udp: 79.5 tcp: 53.4 (S) udp: 68.1 tcp: 44 (S) Highest performance
Only BT over UART FD 2 or 4 jumper or PCB Any_Slave NA NA Dedicated Bluetooth over UART pins
UART FD 2 jumper or PCB Any_Slave udp: 0.68 tcp: 0.67 (O) udp: 0.68 tcp: 0.60 (O) UART dedicated for BT & Wi-Fi [2]
Dedicated platforms FD Extra 2 or 4 jumper or PCB Any_Slave NA NA UART dedicated for BT & Wi-Fi on any other transport

[!NOTE]

  • [1] Dual/Quad SPI is not supported on ESP32

  • [2] UART is only suitable for low throughput environments

With jumper cables, 'Standard SPI' and 'Dual SPI' solutions are easiest to evaluate, without much of hardware dependencies. SDIO 1-Bit can be tested with jumper cables, but it needs some additional hardware config, such as installation of external pull-up registers.

In case case of dedicated platforms, Blutooth uses standard HCI over UART. In rest of cases, Bluetooth and Wi-Fi uses same transport and hence less GPIOs and less complicated. In shared mode, bluetooth runs as vHCI (multiplexed mode)

7 ESP-Hosted-MCU Header

7.1 ESP Hosted header

Host and slave always populate below header at the start of every frame, irrespective of actual or dummy data in payload.

Field Type Bits Mandatory? Description
if_type uint8_t 4 M Interface type
if_num uint8_t 4 M Interface number
flags uint8_t 8 M Flags for additional information
len uint16_t 16 M Length of the payload
offset uint16_t 16 M Offset for the payload
checksum uint16_t 16 M Checksum for error detection (0 if checksum disabled)
seq_num uint16_t 16 O Sequence number for tracking packets (Useful in debugging)
throttle_cmd uint8_t 0 or 2 O Flow control command
reserved2 uint8_t 6 or 8 M Reserved bits
reserved3 uint8_t 8 M Reserved byte (union field)
hci_pkt_type or priv_pkt_type uint8_t 8 M Packet type for HCI interface (union field)

7.2 Interface Types

Start of header states which type of frame is being carried.

Interface Type Value Description
ESP_INVALID_IF 0 Invalid interface
ESP_STA_IF 1 Station frame
ESP_AP_IF 2 SoftAP frame
ESP_SERIAL_IF 3 Control frame
ESP_HCI_IF 4 Bluetooth vHCI frame
ESP_PRIV_IF 5 Private communication between slave and host
ESP_TEST_IF 6 Transport throughput test
ESP_ETH_IF 7 Invalid
ESP_MAX_IF 8 type mentioned in dummy or empty frame

8 Detailed Setup

Once you decided the transport to use, this section should guide how to set this transport, with hardware connections, configurations and verification. Users can evaluate one transport first and then move to other.

[!IMPORTANT]

Design Considerations that could be reffered to, before you stick to any transport option. Referring to these consideration would help to get you faster to solution, make your design stable and less error-prone.

Irrespective of transport chosen, following steps are needed, which are step-wise explained in each transport.

  1. Set-up the hosted-transport
  2. Slave Flashing
    • Slave project creation
    • Slave configuration
    • Slave flashing
    • Slave logs
  3. Host flashing
    • Host project integration with ESP-IDF example
    • Host configuration
    • Host flashing
    • Host logs

9 Examples

Check examples directory for sample applications using ESP-Hosted.

10 Troubleshooting

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

11 References