8000 debuging · Networking-for-Arduino/ESPHost@524a573 · GitHub
[go: up one dir, main page]

Skip to conten 8000 t

Commit 524a573

Browse files
committed
debuging
1 parent 7285088 commit 524a573

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
# ESPHost library
22

3-
Arduino driver for communicating with Espressif's esp-hosted-fg firmware.
3+
Arduino driver for communicating with Espressif's [esp-hosted-fg firmware](https://github.com/espressif/esp-hosted).
44

55
The library is meant to serve as low level driver for a LwIP network interface implementation.
66

77
The library was originally written for Arduino Portenta C33 with Arduino Renesas Core.
8+
9+
Notes:
10+
11+
* configuration is TODO
12+
* pins are hardcoded in EspSpiDriver
13+
* SPI SCK is set to 10 MHz for classic ESP32
14+
15+
Notes on firmware
16+
17+
* [the released fg fw](https://github.com/espressif/esp-hosted/releases/tag/release%2Ffg-v0.0.5) for classic ESP32 uses SPI on pins [12, 13, 14, 15] even [the doc says](https://github.com/espressif/esp-hosted/blob/master/esp_hosted_fg/docs/MCU_based_host/SPI_setup.md#hardware-connections-for-esp32) it is [23, 19, 18, 5]

src/CEspControl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ int CEspControl::wait_for_answer(CCtrlMsgWrapper* response) {
304304

305305
do {
306306
/* send messages untill a valid message is received into the rx queu */
307-
esp_host_perform_spi_communication(true);
307+
if(isEspSpiInitialized() && !isSpiTransactionInProgress()) {
308+
esp_host_perform_spi_communication(true);
309+
}
308310

309311
if(process_msgs_received(response) == ESP_CONTROL_MSG_RX) {
310312
#ifdef ESP_HOST_DEBUG_ENABLED_AVOID

src/EspSpiDriver.cpp

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
static volatile uint8_t esp32_spi_rx_buffer[MAX_SPI_BUFFER_SIZE];
6464
static volatile uint8_t esp32_spi_tx_buffer[MAX_SPI_BUFFER_SIZE];
6565

66-
static bool spi_transaction_in_progress = false;
66+
static volatile bool spi_transaction_in_progress = false;
6767

6868
bool isSpiTransactionInProgress() {
6969
bool rv = spi_transaction_in_progress;
@@ -146,13 +146,10 @@ bool esp_host_there_are_data_to_be_rx() {
146146
bool rv = digitalRead(DATA_READY);
147147

148148
#ifdef ESP_HOST_DEBUG_ENABLED_AVOID
149-
Serial.print("**** RX data? ");
150149
if(rv) {
150+
Serial.print("**** RX data? ");
151151
Serial.println("YES!!!!!");
152152
}
153-
else {
154-
Serial.println("no");
155-
}
156153
#endif
157154
return rv;
158155
}
@@ -166,13 +163,10 @@ bool esp_host_there_are_data_to_be_tx() {
166163
}
167164
// __enable_irq();
168165
#ifdef ESP_HOST_DEBUG_ENABLED_AVOID
169-
Serial.print("**** TX data? ");
170166
if(rv) {
167+
Serial.print("**** TX data? ");
171168
Serial.println("YES!!!!!");
172169
}
173-
else {
174-
Serial.println("no");
175-
}
176170
#endif
177171
return rv;
178172
}
@@ -222,6 +216,7 @@ int esp_host_perform_spi_communication(bool wait_for_valid_msg) {
222216

223217
} while(continue_spi_communication);
224218

219+
spi_transaction_in_progress = false;
225220
return rv;
226221
}
227222

@@ -270,10 +265,6 @@ int esp_host_spi_transaction(void) {
270265

271266
}
272267
}
273-
else {
274-
275-
spi_transaction_in_progress = false;
276-
}
277268
return rv;
278269
}
279270

@@ -299,10 +290,6 @@ int esp_host_send_and_receive(void) {
299290
} while(time_num < 5000);
300291

301292
if(esp_ready) {
302-
SPIWIFI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE2));
303-
/* Put CS LOW */
304-
digitalWrite(ESP_CS, LOW);
305-
delayMicroseconds(100);
306293

307294
/* memset RX buffer */
308295
memset((void *)esp32_spi_rx_buffer,0x00, MAX_SPI_BUFFER_SIZE);
@@ -317,10 +304,13 @@ int esp_host_send_and_receive(void) {
317304
Serial.println();
318305
#endif
319306

320-
307+
SPIWIFI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE2));
308+
digitalWrite(ESP_CS, LOW);
321309
for (int i = 0; i < MAX_SPI_BUFFER_SIZE; i++) {
322310
esp32_spi_rx_buffer[i] = SPIWIFI.transfer(esp32_spi_tx_buffer[i]);
323311
}
312+
digitalWrite(ESP_CS, HIGH);
313+
SPIWIFI.endTransaction();
324314

325315
rv = ESP_HOSTED_SPI_DRIVER_OK;
326316

@@ -332,10 +322,6 @@ int esp_host_send_and_receive(void) {
332322
}
333323
Serial.println();
334324
#endif
335-
spi_transaction_in_progress = false;
336-
/* in any case de-select ESP32 */
337-
digitalWrite(ESP_CS, HIGH);
338-
SPIWIFI.endTransaction();
339325
}
340326
else {
341327
rv = ESP_HOSTED_SPI_ESP_NOT_READY;

src/EspSpiDriver.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#ifndef ESP_HOSTED_SPI_DRIVER_H
2222
#define ESP_HOSTED_SPI_DRIVER_H
2323

24-
#define ESP_HOST_DEBUG_ENABLED
24+
//#define ESP_HOST_DEBUG_ENABLED
2525
//#define ESP_HOST_DEBUG_ENABLED_AVOID
2626

2727
#include "Arduino.h"
@@ -42,7 +42,6 @@ int esp_host_spi_init(void);
4242
int esp_host_perform_spi_communication(bool wait_for_valid_msg);
4343

4444
bool isEspSpiInitialized() ;
45-
bool arePendingRxMsg();
4645

4746
bool isSpiTransactionInProgress();
4847

0 commit comments

Comments
 (0)
0