8000 EspSpiDriver - pins and frequency configuration defines · Networking-for-Arduino/ESPHost@7a1b5cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 7a1b5cb

Browse files
committed
EspSpiDriver - pins and frequency configuration defines
1 parent 9d82058 commit 7a1b5cb

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ The library is meant to serve as low level driver for a LwIP network interface i
66

77
The library was originally written for Arduino Portenta C33 with Arduino Renesas Core.
88

9-
## Notes:
9+
## Configuration
1010

11-
* configuration is TODO
12-
* pins are hardcoded in EspSpiDriver
13-
* SPI SCK is set to 10 MHz for classic ESP32
11+
Pins are configured with defines. To add the defines, modify boards.txt or create boards.local.txt next to boards.txt and add <board>.build.extra_flags=. For boards with defines for the WiFiNINA library it is enough to add `-DESPHOSTSPI`.
12+
13+
Complete settings require to specify pins. Example:
14+
15+
```
16+
rpipico.build.extra_flags=-DESPHOST_RESET=D5 -DESPHOST_HANDSHAKE=D7 -DESPHOST_DATA_READY=D6 -DESPHOST_CS=D10 -DESPHOSTSPI=SPI
17+
```
18+
19+
Default SPI frequency set in the library is 10 MHz. It is the highest SPI speed for classic ESP32. Firmware for C and S series ESP32 are build with higher SPI frequency. To specify the SPI frequency to be used by the ESPHost library, add `-DESPHOSTSPI_MHZ=30` to `<board>.build.extra_flags`.
1420

1521
## Firmware
1622

src/EspSpiDriver.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@
4141
#define DATA_READY SPIWIFI_ACK
4242
#define ESP_CS SPIWIFI_SS
4343

44+
#elif defined(ESPHOSTSPI)
45+
#define ESP_RESET ESPHOST_RESET
46+
#define HANDSHAKE ESPHOST_HANDSHAKE
47+
#define DATA_READY ESPHOST_DATA_READY
48+
49+
#define ESP_CS ESPHOST_CS
50+
#define SPIWIFI ESPHOSTSPI
51+
4452
#elif USE_ESP32_DEVKIT
4553
/* GPIOs */
4654
#define ESP_RESET 5
@@ -61,6 +69,10 @@
6169
#define ESP_CS 103
6270
#endif
6371

72+
#ifndef ESPHOSTSPI_MHZ
73+
#define ESPHOSTSPI_MHZ 10
74+
#endif
75+
6476
/* #################
6577
* PRIVATE Variables
6678
* ################# */
@@ -318,8 +330,9 @@ int esp_host_send_and_receive(void) {
318330
Serial.println();
319331
#endif
320332

321-
SPIWIFI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE2));
333+
SPIWIFI.beginTransaction(SPISettings(1000000ul * ESPHOSTSPI_MHZ, MSBFIRST, SPI_MODE2));
322334
digitalWrite(ESP_CS, LOW);
335+
delayMicroseconds(100);
323336
for (int i = 0; i < MAX_SPI_BUFFER_SIZE; i++) {
324337
esp32_spi_rx_buffer[i] = SPIWIFI.transfer(esp32_spi_tx_buffer[i]);
325338
}

0 commit comments

Comments
 (0)
0