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

support Beaglebone Black board use esp-hosted over SPI #130

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions docs/Linux_based_host/Linux_based_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ Prepare connections based on interface requirements and setup host as below.
* Prepare connections as per section [1.1 Hardware Setup](SPI_setup.md#11-hardware-setup) of [SPI Setup document](SPI_setup.md)
* Host Software
* Prepare Raspberry-Pi as per [1.2 Raspberry-Pi Software Setup](SPI_setup.md#12-raspberry-pi-software-setup) of [SPI Setup document](SPI_setup.md)
* Compile and load host driver as below:
* Compile and load host driver as below:
```sh
$ cd host/linux/host_control/
$ ./rpi_init.sh spi
```
* Prepare Beaglebone Black [SPI Setup document for BBB](SPI_setup_for_BBB.md)

* **Wi-Fi over SDIO and Bluetooth over UART**
* Connection Setup
* Prepare SDIO connections as per section [1.1 Hardware Setup](SDIO_setup.md#11-hardware-setup) of [SDIO setup document](SDIO_setup.md)
Expand Down Expand Up @@ -228,7 +230,8 @@ ESP-Hosted solutions supports SDIO and SPI as transport for Wi-Fi and Bluetooth/

* [Wi-Fi and BT/BLE connectivity Setup over SDIO](SDIO_setup.md)

* [Wi-Fi and BT/BLE connectivity Setup over SPI](SPI_setup.md)
* [Wi-Fi and BT/BLE connectivity Setup over SPI for RPi](SPI_setup.md)
* [Wi-Fi and BT/BLE connectivity Setup over SPI for BBB](SPI_setup_for_BBB.md)

* [Bluetooth/BLE connectivity Setup over UART](UART_setup.md)

Expand Down
163 changes: 163 additions & 0 deletions docs/Linux_based_host/SPI_setup_for_BBB.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Wi-Fi and BT/BLE connectivity Setup over SPI
## 1. Setup
### 1.1 Hardware Setup
In this setup, ESP board acts as a SPI peripheral and provides Wi-Fi capabilities to host. Please connect ESP peripheral to Beaglebone Black with jumper cables as mentioned below. It may be good to use small length cables to ensure signal integrity. Power ESP and BBB separately with a power supply that provide sufficient power. ESP can be powered through PC using micro-USB cable.

BBB pinout can be found [here!](https://beagleboard.org/support/bone101)

#### 1.1.1 ESP32 setup
| BBB pin label | BBB pin ID | ESP32 pin ID | ESP32 pin function |
| --- | --- | --- | --- |
| P9_23 | 49 | 21 | GPIO_HANDSHAKE |
| P9_15 | 48 | 22 | GPIO_DATA_READY |
| SPI0_CS0 | P9_17 | 5 | CS |
| SPI0_SCLK | P9_22 | 18 | SCLK |
| SPI0_MISO D0 | P9_21 | 19 | MISO |
| SPI0_MOSI D1 | P9_18 | 23 | MOSI |
| P9_12 | 60 | RESET | RESET |


![alt text](bbb_esp_spi_setup.jpg "setup of Beaglebone Black as host and ESP32 WROOM 32 as slave")

### 1.2 Beaglebone Black Software Setup
The SPI master driver is enabled by default on BBB OS. To disable it.
```
cd host/linux/host_control/
./bbb_init.sh load_dtoverlay
```
the script will be update overlay for device tree to disable spi which used by default linux SPI driver.
The scrip will automatically reboot BBB after 10s to take effect. you could cancel.

## 2. Load ESP-Hosted Solution
### 2.1 Host Software
* Execute following commands in root directory of cloned ESP-Hosted repository on BBB
```sh
$ cd host/linux/host_control/
$ ./bbb_init.sh spi
```
* This script compiles and loads host driver on BBB. It also creates virtual serial interface `/dev/esps0` which is used as a control interface for Wi-Fi on ESP peripheral

### 2.2 ESP Peripheral Firmware
One can load pre-built release binaries on ESP peripheral or compile those from source. Below subsection explains Source Compilation methods due to this is a new commit for support BBB.

#### 2.2.1 Source Compilation
:warning:<code>Note: Please check [ESP-IDF Setup](Linux_based_readme.md#22-esp-idf-setup) and use appropriate ESP-IDF version</code>

* In root directory of ESP-Hosted repository, execute below command

```sh
$ cd esp/esp_driver/network_adapter
```

##### Using cmake

* :warning: `Set target if the ESP32-S2 or ESP32-C3 is being used. Skip if ESP32 is being used. and use configuration at NOTE for ESP32 WROOM`

```
$ idf.py set-target esp32
```
or
```
$ idf.py set-target esp32s2
```
or
```
$ idf.py set-target esp32c3
```

* Execute following command to configure project
```sh
$ idf.py menuconfig
```
* This will open project configuration window. To select SPI transport interface, navigate to `Example Configuration -> Transport layer -> SPI interface -> select` and exit from menuconfig.

* For ESP32-C3, select chip revision in addition. Navigate to `Component config → ESP32C3-Specific → Minimum Supported ESP32-C3 Revision` and select chip version of ESP32-C3.

* Use below command to compile and flash the project. Replace <serial_port> with ESP peripheral's serial port.
```sh
$ idf.py -p <serial_port> build flash
```

## 3. Checking the Setup for SPI
Once ESP peripheral has a valid firmware and booted successfully, you should be able to see successful enumeration on BBB side as:
```
$ dmesg
[ 96.439911] Bluetooth: Core ver 2.22
[ 96.440145] NET: Registered protocol family 31
[ 96.440153] Bluetooth: HCI device and connection manager initialized
[ 96.440181] Bluetooth: HCI socket layer initialized
[ 96.440195] Bluetooth: L2CAP socket layer initialized
[ 96.440261] Bluetooth: SCO socket layer initialized
[ 196.746813] esp32_spi: loading out-of-tree module taints kernel.
[ 196.755748] esp_reset, ESP32: Resetpin of Host is 60
[ 196.755892] esp_reset, ESP32: Triggering ESP reset.
[ 196.775022] ESP32 peripheral is registered to SPI bus [0],chip select [0], SPI Clock [10]
[ 199.310809]
Received INIT event from ESP32 peripheral
[ 199.310839] EVENT: 2
[ 199.310853] EVENT: 1
[ 199.310857] EVENT: 0
[ 199.310864] ESP peripheral capabilities: 0x78
[ 200.155504] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[ 200.155519] Bluetooth: BNEP filters: protocol multicast
[ 200.155551] Bluetooth: BNEP socket layer initialized
[ 200.699800] Bluetooth: RFCOMM TTY layer initialized
[ 200.699842] Bluetooth: RFCOMM socket layer initialized
[ 200.699906] Bluetooth: RFCOMM ver 1.11

```
## 4. Note
Configuration for ESP32 WROOM
```
CONFIG_ESP32_DEFAULT_CPU_FREQ_160=y
CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=160
CONFIG_SDIO_DAT2_DISABLED=

# BT Configuration
CONFIG_BT_ENABLED=y
CONFIG_BT_CONTROLLER_ONLY=y
CONFIG_BT_BLUEDROID_ENABLED=
CONFIG_BTDM_CONTROLLER_MODE_BTDM=y
CONFIG_BTDM_CONTROLLER_HCI_MODE_VHCI=y
CONFIG_BTDM_CTRL_AUTO_LATENCY=y

CONFIG_ESP32_WIFI_NVS_ENABLED=

# BT over UART
#CONFIG_BTDM_CONTROLLER_HCI_MODE_UART_H4=y
#CONFIG_BTDM_CTRL_HCI_MODE_UART_H4=y
#CONFIG_BT_HCI_UART_NO=1
#CONFIG_BT_HCI_UART_BAUDRATE=921600

#CO-EX config
CONFIG_FREERTOS_UNICORE=n
CONFIG_FREERTOS_HZ=400
CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1=y
CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE=0
CONFIG_BTDM_CTRL_PINNED_TO_CORE=0
CONFIG_BTDM_CTRL_PINNED_TO_CORE_0=y

CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=16
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=64

# OTA
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_PARTITION_TABLE_TWO_OTA=y
#
# Example Configuration
#
# CONFIG_ESP_SDIO_HOST_INTERFACE is not set
CONFIG_ESP_SPI_HOST_INTERFACE=y

#
# SPI Configuration
#
CONFIG_ESP_SPI_CONTROLLER=3
CONFIG_ESP_SPI_GPIO_HANDSHAKE=21
CONFIG_ESP_SPI_GPIO_DATA_READY=22
# end of SPI Configuration


```
Binary file added docs/Linux_based_host/bbb_esp_spi_setup.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions host/linux/host_control/BBB_spidev_disabler.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/dts-v1/;
/plugin/;

/ {
compatible = "ti,beaglebone", "ti,beaglebone-black";
part-number = "spi0pinmux";

fragment@0 {
// spi_SCLK
target = <&P9_22_default_pin>;
__overlay__ {
pinctrl-single,pins = <0x150 0x30>;
};
};

fragment@1 {
// spi_D0 MISO
target = <&P9_21_default_pin>;
__overlay__ {
pinctrl-single,pins = <0x154 0x30>;
};
};
fragment@3 {
// spi_CS0
target = <&P9_17_default_pin>;
__overlay__ {
pinctrl-single,pins = <0x15c 0x10>;
};
};
fragment@4 {
// spi_D1 MOSI
target = <&P9_18_default_pin>;
__overlay__ {
pinctrl-single,pins = <0x158 0x10>;
};
};

fragment@5 {
target = <&spi0>;
__overlay__ {
status = "okay";
channel@0 {
status = "disabled";
};
channel@1 {
status = "disabled";
};
};
};
};
154 changes: 154 additions & 0 deletions host/linux/host_control/bbb_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#!/bin/sh

# Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

RESETPIN="resetpin=60"
BT_INIT_SET="0"
IF_TYPE="spi"
MODULE_NAME="esp32_${IF_TYPE}.ko"

echo "setup default HANDSHAKE_PIN (GPIO_49) and SPI_DATA_READY_PIN (GPIO_48)\n"
sed -i 's/#define SPI_DATA_READY_PIN.*/#define SPI_DATA_READY_PIN 48/g' ../host_driver/esp32/spi/esp_spi.h
sed -i 's/#define HANDSHAKE_PIN.*/#define HANDSHAKE_PIN 49/g' ../host_driver/esp32/spi/esp_spi.h

build_c_demo_app()
{
cd c_support/
make clean
make -j8
make -j8 stress
cd ..
}

build_python_demo_app()
{
cd python_support/
make clean
make -j8
cd ..
}

wlan_init()
{
build_c_demo_app
build_python_demo_app

cd ../host_driver/esp32/
if [ `lsmod | grep esp32 | wc -l` != "0" ]; then
sudo rm /dev/esps0
if [ `lsmod | grep esp32_sdio | wc -l` != "0" ]; then
sudo rmmod esp32_sdio &> /dev/null
else
sudo rmmod esp32_spi &> /dev/null
fi
fi

make -j8 target=$IF_TYPE CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- KERNEL="/lib/modules/$(uname -r)/build" ARCH=arm

if [ "$RESETPIN" = "" ] ; then
echo "By Default, use resetpin=60"
sudo insmod $MODULE_NAME resetpin=60
else
echo "Use resetpin value from argument"
sudo insmod $MODULE_NAME $RESETPIN
fi
if [ `lsmod | grep esp32 | wc -l` != "0" ]; then
echo "esp32 module inserted "
sudo mknod /dev/esps0 c 221 0
sudo chmod 666 /dev/esps0
echo "/dev/esps0 device created"
echo "BBB init successfully completed"
fi
}

load_overlay()
{
echo "build .dtbo"

dtc -O dtb -o BB-SPI0-01-00A0.dtbo -b 0 -@ BBB_spidev_disabler.dts

echo "cp BB-SPI0-01-00A0.dtbo /lib/firmware/"
sudo mv BB-SPI0-01-00A0.dtbo /lib/firmware/

echo "updating /boot/uEnv.txt for active overlay. default I'll update overlay entry 0\n"

sudo sed -Ei 's/#?uboot_overlay_addr0.*/uboot_overlay_addr0=\/lib\/firmware\/BB-SPI0-01-00A0.dtbo/g' /boot/uEnv.txt
}


usage()
{
echo "This script prepares BBB for wlan and bt/ble operation over esp32 device"
echo "\nUsage: ./bbb_init.sh [arguments]"
echo "\nArguments are optional and are as below"
echo " load_dtoverlay: to disable SPI0 which is used by default linux device driver (spidev)"
echo " spi: sets ESP32<->BBB communication over SPI"
echo " resetpin=60: Set GPIO pins on BBB connected to EN pin of ESP32, used to reset ESP32 (default:60 for P9_12 )"
echo "\nExample:"
echo "\n - Use spi for host<->ESP32 communication"
echo " # ./bbb.sh spi"
echo "\n - use GPIO pin P9_12 (GPIO_60) for reset"
echo " # ./bbb.sh resetpin=60"
}

parse_arguments()
{
while [ "$1" != "" ] ; do
case $1 in
--help | -h )
usage
exit 0
;;
spi)
IF_TYPE=$1
;;
load_dtoverlay)
load_overlay
echo "NEED TO REBOOT to take effect. I'll reboot in 10s. This only need only one time."
sleep 10; reboot
;;
resetpin=*)
echo "Recvd Option: $1"
RESETPIN=$1
;;
*)
echo "$1 : unknown option"
usage
exit 1
;;
esac
shift
done
}


parse_arguments $*
if [ "$IF_TYPE" = "" ] ; then
echo "Error: No protocol selected"
usage
exit 1
else
echo "Building for $IF_TYPE protocol"
MODULE_NAME=esp32_${IF_TYPE}.ko
fi

if [ `lsmod | grep bluetooth | wc -l` = "0" ]; then
echo "bluetooth module inserted"
sudo modprobe bluetooth
fi

if [ `lsmod | grep bluetooth | wc -l` != "0" ]; then
wlan_init
fi
Loading