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
ESP32-CAM can't upload new IDE sketch after an sd initialization.. SPI&SD keep MISO level HIGH #6290
Comments
I know, i have seen this work around before, But the issue was and still is that the SPI setting (&SD) should have a simple call/method to disable the used ( and modified) SPI signals (also the SD) and leave the hardware in a state that does not interfere with functions that normally work. |
When will it switch the pins? You are uploading a firmware and resetting the Chip through the hardware enable pin, so it will check the pin state when entering Download mode and IO2 high will not fly :) |
basically i stumbled on this issue while checking some other camera functionality. Downloading all kind of other Sketches |
the uploaded sketch in here is just to show the issue.. |
When the SD Card is initialized, it itself pulls MISO. It's not the SPI peripheral that is at fault. At the moment that the ESP reboots into download, all GPIOs AFAIK are reset to their default modes, but since the SD Card is still powered, it's still pulling MISO high. |
Correct, it have a feeling that MISO just shifts out the data and leaves the last bit (LEVEL) at the output Perhaps it is therefore a good idea to implement something usefull to set the SD in a pre-defined state in your lLIB |
typo.. sorry |
PS: after ("SD.end" , SPI.end , put CS to high, perform a number of dummy clocks ) the SD MISO pin is tri-state |
this would still not work for you and is only needed if IO2 is used for MISO. The chip does not know that it's about to be reset into download, so there is no way to trigger execution of such |
thanks for your info. I will keep this issue in mind. Just taking care to unmount the SD when not needed anymore void MountSD_By_SPI() {
unsigned long time1;
Serial.println("Initalizing SD card...");
// The way to start SPI is: SPI.begin(SCK,MISO,MOSI,CS);
// Start SPI for the ESP32-CAM SD card
time1 = micros();
SPI.begin(/*SCK*/14, /*MISO*/2, /*MOSI*/15, /*CS-SS*/13);
if (!SD.begin(13) ) {
Serial.println("initialization of the SD-Micro failed!");
Serial.println("Check the SD-micro on a laptop to assure the SD-micro is OK");
while (1);
}
Serial.printf("Mounting the SD-micro by SPI takes : %ld [uSec]\n", (micros() - time1) );
Serial.println(F("WARNING: THE ESP32-CAM will not upload new sketches as long an activated SD-micro is mounted "));
Serial.println(F(" The reason for this error is the MISO pin HIGH level and is preventing a correct upload "));
Serial.println(F(" You will see the white LED Flashing and IDE text: Connecting........_____....._____....._____..... "));
Serial.println(F(" Use Unmount_SD() as in the example or remove the SD-Micro before you try to upload a new Sketch\n"));
}
void Unmount_SD() {
// Tested with Kingston 32GB
unsigned long time1;
time1 = micros();
Serial.println("Ejecting the ESP32-CAM SD");
SD.end();
SPI.end();
// Set MOSI High
pinMode(15, INPUT_PULLUP);
// Disable the SD by an HIGH CS/SS
pinMode(13, OUTPUT); digitalWrite(13, HIGH);
// Provide dummy clocks
pinMode(14, OUTPUT);
for (int i = 1; i <= 8; i++) {
digitalWrite(14, LOW);
digitalWrite(14, HIGH);
}
// Set CLK High
pinMode(14, INPUT_PULLUP);
// Check if MISO became "LOW"
pinMode(2, INPUT_PULLDOWN);
delay(1);
if (digitalRead(2)) {
Serial.println(F("Failed to unmount the SD"));
} else
{ Serial.printf("Unmounting of the SD-micro card takes : %ld [uSec]\n", (micros() - time1) );
Serial.println(F("SD has been unmounted safely"));
}
} |
Thanks for sharing it, @qbox4u . Solution with Unmount_SD works with me. But I think it should be part of the library, or SD.end() should clean up all the resources so this issue is not happening anymore. |
I was able to circumvent this problem by using a PNP transistor. Instead of connecting the MISO pin of the SD card reader directly to the ESP32, I connected it to the emitter of the transistor. Then I connected the MISO pin of the ESP32 to the collector and the CS pin to the base via a 10K Ohm resistor. This way, when CS goes low it switches on the transistor allowing the communication on the MISO line, but when the communication is over and the CS returns to high, the transistor turns off, interrupting the connection in the MISO line. |
Board
ESP32-CAM
Device Description
ESP32-CAM mounted on a ESP32-cam-MB
Hardware Configuration
on board SD connected to :
1 DATA2 HS2DATA2 GPIO12 x
2 CD/DATA3 HS2DATA3 GPIO13 CS CS
3 CMD HS2CMD GPIO15 DI MOSI
4 3.3v
5 CLK HS@CLK GPIO14 SCLK SCLK
6 GND
7 DATA0 HS2DATA0 GPIO02 DO MISO
8 DATA1 x
Version
latest master
IDE Name
Arduino IDE 1.8.19
Operating System
WIN10
Flash frequency
240mhz
PSRAM enabled
yes
Upload speed
115200
Description
The ESP32-CAM has a SD-micro slot on the main board. and is mounted on a ESP32-CAM-MB board
for providing serial communication.
(eg https://universal-solder.ca/wp-content/uploads/2021/03/5083_b61d93cb-2cb4-4503-b537-ca77679cc7ad0.jpg)
The SD is blocking a new reload of a Sketch after the SD-micro has been initialized.
Schematic SD-micro connections on ESP32-CAM
1 DATA2 HS2DATA2 GPIO12 x
2 CD/DATA3 HS2DATA3 GPIO13 CS CS
3 CMD HS2CMD GPIO15 DI MOSI
4 3.3v
5 CLK HS@CLK GPIO14 SCLK SCLK
6 GND
7 DATA0 HS2DATA0 GPIO02 DO MISO
8 DATA1 x
After the following commands the board cant reload a new IDE sketch
SPI.begin(14, 2, 15, 13);
if (!SD.begin(13) ) {
Serial.println("initialization failed!");
while (1);
}
Pressing the reset-button of the ESP32-CAM board does not solve the issue as the SD-micro card
still blocks a new sketch upload.
The only way to reload a new sketch is to remove the SD-micro (basically a power down) after which the MISO signal
of the SD card is disabled (high impedance again).....
Sketch
Debug Message
Other Steps to Reproduce
Identified the issue at Arduino SD.h. They pointed out that this is for the ESP32 group
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: