A few weeks ago the SSD on my PC died. I replaced it and reinstalled Windows 11 and all my software from the latest versions. Arduino included. I restored all the Arduino sketches and libraries from a backup. I ran a series of test on my 'Arduino test' sketches. My latest board is a JC-ESP32P4_M3_DEV from Guition. I use the ESP32P4 DEV Module from Espressif as the board identifier. The board has a TF Card reader on it. The test sketch used to read the contents of an SD card (using SD_MMC) and print a list of files on it. The sketch then ran a simple test of a stepper motor. When I compile and download it now it fails with the messages:
E (206) sdmmc_periph: sdmmc_host_init_slot: Invalid GPIO number -1, returned 0x102
E (207) vfs_fat_sdmmc: slot init failed (0x102).
In spite of spending hours in vain trying to find what has changed I hope there is someone on the forum that can point me in the right direction.
The Sketch is as follows'
#include <SD_MMC.h>
#include <Arduino.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/timers.h"
#include "freertos/event_groups.h"
// Stepper driver pin definitions
#define PIN_DIRECTION 1
#define PIN_STEP 2
#define PIN_ENABLE 3
#define PIN_MS1 4
#define PIN_MS2 5
int microStep = 32;
int stepDelay = 9574;
//int stepDelay = 451;
int steps = microStep * 200;
void setup() {
Serial.begin(115200);
while (!Serial) {delay(100);}
if (!SD_MMC.begin()) {
Serial.println("No SD card mounted");
return;
}
else
{
Serial.println("SD card details");
if (!SD_MMC.begin("/sdcard", false))
{
Serial.println("SD_MMC checking for 1-bit or 4bit");
if (!SD_MMC.begin("/sdcard", true))
{
Serial.println("SD_MMC 1-bit: Reformat to FAT32 for 4bit");
return;
}
Serial.println("SD_MMC 1-bit OK");
}
else
{
Serial.println("SD_MMC 4-bit OK");
}
Serial.printf("SD type: %d | Size: %.2f GB\n\n",
SD_MMC.cardType(), SD_MMC.cardSize() / ( 1024.0 * 1024.0 * 1024.0));
if (SD_MMC.exists("/TestDir")) {
Serial.printf("Directory '/TestDir' already exists.\n");
File file = SD_MMC.open("/TestDir/test.txt", FILE_WRITE);
if(!file){
Serial.println("Failed to open file for writing");
return;
}
else
{
if(file.println("Hello, SD_MMC! This is a test file.")){
Serial.println("File written");
} else {
Serial.println("Write failed");
}
file.close();
Serial.println("File closed");
}
} else {
if (SD_MMC.mkdir("/TestDir")) { // Or SD_MMC.mkdir("TestDir")
Serial.println("Directory DATA created");
} else {
Serial.println("Directory TestDir already exists or creation failed");
}
}
listDir(SD_MMC, "/", 2); // List the root directory
const char* dirToDelete = "/TestDir";
Serial.printf("Attempting to delete directory: %s\n", dirToDelete);
if (SD_MMC.rmdir(dirToDelete)) {
Serial.printf("Directory '%s' deleted successfully.\n", dirToDelete);
} else {
Serial.printf("Failed to delete directory '%s'.\n", dirToDelete);
}
}
Serial.println("TMC2209 starting");
int mdelay = stepDelay / microStep;
// Configure stepper driver pins as OUTPUTs
pinMode(PIN_DIRECTION, OUTPUT);
pinMode(PIN_STEP, OUTPUT);
pinMode(PIN_ENABLE, OUTPUT);
pinMode(PIN_MS1, OUTPUT);
pinMode(PIN_MS2, OUTPUT);
digitalWrite(PIN_ENABLE, LOW);
digitalWrite(PIN_MS1, HIGH);
digitalWrite(PIN_MS2, LOW);
for (int i = 0; i < steps; i++)
{
digitalWrite(PIN_STEP, HIGH);
delayMicroseconds(50);
digitalWrite(PIN_STEP, LOW);
delayMicroseconds(stepDelay);
}
delay(1000);
digitalWrite(PIN_DIRECTION, HIGH);
for (int i = 0; i < steps; i++)
{
digitalWrite(PIN_STEP, HIGH);
delayMicroseconds(50);
digitalWrite(PIN_STEP, LOW);
delayMicroseconds(stepDelay);
}
digitalWrite(PIN_ENABLE, HIGH);
}
void loop() {
Serial.println("TMC2209 Idle");
delay(5000);
}
void listDir(fs::FS &fs, const char * dirname, uint8_t levels) {
Serial.printf("Listing of directory: %s\n", dirname);
File root = fs.open(dirname);
if (!root) {
Serial.println("Failed to open directory");
return;
}
if (!root.isDirectory()) {
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
Serial.print(" DIR : ");
Serial.println(file.name());
if (levels) {
String sDir = String(dirname) + String(file.name());
listDir(fs,sDir.c_str(), levels - 1); // Recursively list subdirectories
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
