Skip to content
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
142 changes: 142 additions & 0 deletions esp_hosted_ng/host/platforms/beaglev-fire/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# BeagleV-Fire Platform Support

ESP-Hosted support for BeagleV-Fire (Microchip PolarFire SoC RISC-V platform).

## Hardware

- **Board**: BeagleV-Fire
- **SoC**: Microchip PolarFire SoC (RISC-V)
- **Interface**: SPI0
- **ESP32**: Any ESP32 module (ESP32-WROOM-32, DevKitC, etc.)

## Pin Connections

| Function | ESP32 GPIO | ESP32 Physical Pin | BeagleV-Fire Pin | BeagleV GPIO | Description |
| -------------- | ---------- | ------------------ | ---------------- | ------------ | --------------- |
| **SPI MOSI** | GPIO 13 | D13 | P9_18 | SPI0_MOSI | SPI Master Out |
| **SPI MISO** | GPIO 12 | D12 | P9_21 | SPI0_MISO | SPI Master In |
| **SPI CLK** | GPIO 14 | D14 | P9_22 | SPI0_CLK | SPI Clock |
| **SPI CS** | GPIO 15 | D15 | P9_17 | SPI0_CS0 | SPI Chip Select |
| **Handshake** | GPIO 26 | D26 | P8_03 | 512 | MSS GPIO_2[0] |
| **Data Ready** | GPIO 25 | D25 | P8_04 | 513 | MSS GPIO_2[1] |
| **Reset** | EN | EN | P8_05 | 514 | MSS GPIO_2[2] |
| **Ground** | GND | GND | P9_1 or P9_2 | GND | Common Ground |

## Configuration Details

### Hardware Configuration

- **SPI Interface**: SPI0 on BeagleV-Fire
- **GPIO Chip**: MSS GPIO_2 (base 512)
- **Reset Pin**: GPIO 514 (configured in `beaglev_init.sh`)
- **Handshake Pin**: GPIO 512 (configured in `spi/esp_spi.h`)
- **Data Ready Pin**: GPIO 513 (configured in `spi/esp_spi.h`)

## Files in This Directory

- **beaglev_init.sh** - Modified initialization script for BeagleV-Fire
- **beaglev-esp-hosted.dts** - Device tree overlay for SPI configuration
- **patches/esp_spi.h.patch** - GPIO pin modifications

## Quick Setup

### 1. Apply Device Tree Overlay
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attach logs after some commands so that the user can see the expected results?


```bash
# Compile overlay
dtc -O dtb -o beaglev-esp-hosted.dtbo -b 0 -@ beaglev-esp-hosted.dts

# Copy to firmware directory
sudo cp beaglev-esp-hosted.dtbo /lib/firmware/

# Apply overlay
sudo mkdir -p /sys/kernel/config/device-tree/overlays/esp-hosted
echo beaglev-esp-hosted.dtbo | sudo tee /sys/kernel/config/device-tree/overlays/esp-hosted/path

# Verify
cat /sys/kernel/config/device-tree/overlays/esp-hosted/status # Should show "applied"
ls /dev/spidev0.0 # Should exist
```

### 2. Apply GPIO Pin Patch

If not already applied in your fork:

```bash
cd ~/esp-hosted
patch -p1 < esp_hosted_ng/host/platforms/beaglev-fire/patches/esp_spi.h.patch
```

Or manually edit `esp_hosted_ng/host/linux/host_driver/esp32/spi/esp_spi.h`:

```c
#define HANDSHAKE_PIN 513 // Changed from 22
#define SPI_DATA_READY_PIN 514 // Changed from 27
```

### 3. Copy Init Script

```bash
cp esp_hosted_ng/host/platforms/beaglev-fire/beaglev_init.sh \
esp_hosted_ng/host/beaglev_init.sh
chmod +x esp_hosted_ng/host/beaglev_init.sh
```

### 4. Build and Load Driver

```bash
cd esp_hosted_ng/host
sudo ./beaglev_init.sh spi
```

### 5. Verify

```bash
# Check module loaded
lsmod | grep esp32_spi

# Check interface
ip link show wlan0

# Test WiFi
sudo iw dev wlan0 scan
```

## Troubleshooting

**No /dev/spidev0.0**:

```bash
# Load SPI modules
sudo modprobe spidev
sudo modprobe spi-microchip-core
sudo modprobe spi-microchip-core-qspi

# Reboot if needed
sudo reboot
```

**Module won't load**:

```bash
# Check kernel headers
ls /lib/modules/$(uname -r)/build/include/linux/module.h

# If missing, rebuild kernel headers
```

**No wlan0 interface**:

```bash
# Check ESP32 is powered and connected
# Check kernel logs
dmesg | grep -i esp

# Look for "ESP peripheral capabilities"
```

## Notes

- Bluetooth requires `bluetooth` kernel module (not in default BeagleV kernel)
- WiFi works independently of Bluetooth
- SPI speed can be increased to 20 MHz for better performance (experimental)
22 changes: 22 additions & 0 deletions esp_hosted_ng/host/platforms/beaglev-fire/beaglev-esp-hosted.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/dts-v1/;
/plugin/;

/ {
compatible = "microchip,mpfs-icicle-kit";

fragment@0 {
target = <&spi0>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;

status = "okay";

spidev@0 {
compatible = "rohm,dh2228fv";
reg = <0>;
spi-max-frequency = <10000000>;
};
};
};
};
96 changes: 96 additions & 0 deletions esp_hosted_ng/host/platforms/beaglev-fire/beaglev_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Platform-specific settings for BeagleV-Fire
resetpin=512 # BeagleV GPIO for ESP32 reset (was 6 for RPi)

# WLAN/BT initialization
wlan_init() {
echo "WLAN init"

cd "$SCRIPT_DIR" || exit 1

# Build for RISC-V architecture (not ARM)
make target=$IF_TYPE \
ARCH=riscv \
KERNEL=/lib/modules/$(uname -r)/build

if [ $? -ne 0 ]; then
echo "Failed to build driver"
exit 1
fi

# Insert module
sudo insmod esp32_spi.ko

if [ $? -ne 0 ]; then
echo "Failed to insert module"
exit 1
fi

sleep 2
echo "esp32_spi module loaded"
}

bt_init() {
echo "Bluetooth init"

# Note: raspi-gpio commands removed (BeagleV doesn't have this utility)
# GPIO configuration is handled by device tree

echo "Bluetooth initialization skipped (requires kernel support)"
}

# Main execution
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <spi|sdio>"
exit 1
fi

IF_TYPE=$1

if [ "$IF_TYPE" != "spi" ] && [ "$IF_TYPE" != "sdio" ]; then
echo "Error: Interface type must be 'spi' or 'sdio'"
exit 1
fi

echo "Interface type: $IF_TYPE"

# Note: spidev_disabler not needed on BeagleV-Fire
# SPI device configuration is handled by custom device tree overlay

# Reset ESP32
if [ -d /sys/class/gpio/gpio$resetpin ]; then
echo "GPIO $resetpin already exported"
else
echo $resetpin > /sys/class/gpio/export
fi

echo out > /sys/class/gpio/gpio$resetpin/direction
echo "Resetting ESP32 using GPIO $resetpin"
echo 0 > /sys/class/gpio/gpio$resetpin/value
sleep 1
echo 1 > /sys/class/gpio/gpio$resetpin/value
sleep 2

# Load kernel modules
if [ $(lsmod | grep bluetooth | wc -l) = "0" ]; then
echo "Attempting to load bluetooth module..."
sudo modprobe bluetooth 2>/dev/null || echo "Bluetooth not available, skipping"
fi

if [ $(lsmod | grep cfg80211 | wc -l) = "0" ]; then
echo "Attempting to load cfg80211 module..."
sudo modprobe cfg80211 2>/dev/null || echo "cfg80211 not available, will try to build anyway"
fi

# Initialize WLAN (always attempt, even if bluetooth failed)
wlan_init

echo "Setup complete!"
echo "Check dmesg for ESP32 initialization messages:"
echo " dmesg | grep -i esp"
echo ""
echo "If successful, wlan0 interface should be available:"
echo " ip link show wlan0"
18 changes: 18 additions & 0 deletions esp_hosted_ng/host/platforms/beaglev-fire/patches/esp_spi.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/esp_hosted_ng/host/linux/host_driver/esp32/spi/esp_spi.h b/esp_hosted_ng/host/linux/host_driver/esp32/spi/esp_spi.h
index abcdef1..1234567 100644
--- a/esp_hosted_ng/host/linux/host_driver/esp32/spi/esp_spi.h
+++ b/esp_hosted_ng/host/linux/host_driver/esp32/spi/esp_spi.h
@@ -17,11 +17,11 @@
#include "esp_api.h"

#ifndef HANDSHAKE_PIN
-#define HANDSHAKE_PIN 22
+#define HANDSHAKE_PIN 513
#endif

#ifndef SPI_DATA_READY_PIN
-#define SPI_DATA_READY_PIN 27
+#define SPI_DATA_READY_PIN 514
#endif

#ifndef RESETPIN