SD card interface
This commit is contained in:
parent
1d87ecc570
commit
9bf367bb51
6 changed files with 62 additions and 21 deletions
|
@ -4,7 +4,11 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "disk_backend.h"
|
#include "disk_backend.h"
|
||||||
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
#include "rp2040.h"
|
||||||
|
#else
|
||||||
#include "esp32.h"
|
#include "esp32.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class disk_backend_esp32 : public disk_backend
|
class disk_backend_esp32 : public disk_backend
|
||||||
|
|
|
@ -8,14 +8,10 @@
|
||||||
#include <HardwareSerial.h>
|
#include <HardwareSerial.h>
|
||||||
#endif
|
#endif
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
#if defined(BUILD_FOR_RP2040)
|
|
||||||
#include <SD.h>
|
|
||||||
#endif
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#if defined(BUILD_FOR_RP2040)
|
#if defined(BUILD_FOR_RP2040)
|
||||||
//#include <pico/stdio_uart.h>
|
|
||||||
#else
|
#else
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <sys/poll.h>
|
#include <sys/poll.h>
|
||||||
|
@ -31,12 +27,14 @@
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "debugger.h"
|
#include "debugger.h"
|
||||||
#include "disk_backend.h"
|
#include "disk_backend.h"
|
||||||
#if !defined(BUILD_FOR_RP2040)
|
|
||||||
#include "disk_backend_esp32.h"
|
#include "disk_backend_esp32.h"
|
||||||
|
#if !defined(BUILD_FOR_RP2040)
|
||||||
#include "disk_backend_nbd.h"
|
#include "disk_backend_nbd.h"
|
||||||
#endif
|
#endif
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#if !defined(BUILD_FOR_RP2040)
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
#include "rp2040.h"
|
||||||
|
#else
|
||||||
#include "esp32.h"
|
#include "esp32.h"
|
||||||
#endif
|
#endif
|
||||||
#include "gen.h"
|
#include "gen.h"
|
||||||
|
@ -67,7 +65,9 @@ console *cnsl = nullptr;
|
||||||
|
|
||||||
uint16_t exec_addr = 0;
|
uint16_t exec_addr = 0;
|
||||||
|
|
||||||
SdFat32 sd;
|
#if !defined(BUILD_FOR_RP2040)
|
||||||
|
SdFat32 SD;
|
||||||
|
#endif
|
||||||
|
|
||||||
std::atomic_uint32_t stop_event { EVENT_NONE };
|
std::atomic_uint32_t stop_event { EVENT_NONE };
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ std::optional<disk_backend_t> select_disk_backend(console *const c)
|
||||||
{
|
{
|
||||||
#if defined(BUILD_FOR_RP2040)
|
#if defined(BUILD_FOR_RP2040)
|
||||||
return BE_SD;
|
return BE_SD;
|
||||||
#endif
|
#else
|
||||||
c->put_string("1. network (NBD), 2. local SD card, 9. abort");
|
c->put_string("1. network (NBD), 2. local SD card, 9. abort");
|
||||||
|
|
||||||
int ch = -1;
|
int ch = -1;
|
||||||
|
@ -222,6 +222,7 @@ return BE_SD;
|
||||||
|
|
||||||
// if (ch == '2')
|
// if (ch == '2')
|
||||||
return BE_SD;
|
return BE_SD;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<disk_type_t> select_disk_type(console *const c)
|
std::optional<disk_type_t> select_disk_type(console *const c)
|
||||||
|
@ -302,17 +303,33 @@ std::optional<std::pair<std::vector<disk_backend *>, std::vector<disk_backend *>
|
||||||
c->put_string_lf("Files on SD-card:");
|
c->put_string_lf("Files on SD-card:");
|
||||||
|
|
||||||
#if defined(SHA2017)
|
#if defined(SHA2017)
|
||||||
if (!sd.begin(21, SD_SCK_MHZ(10)))
|
if (!SD.begin(21, SD_SCK_MHZ(10)))
|
||||||
sd.initErrorHalt();
|
SD.initErrorHalt();
|
||||||
#elif defined(BUILD_FOR_RP2040)
|
#elif !defined(BUILD_FOR_RP2040)
|
||||||
// SD.begin(cspin, SPI1); FIXME
|
if (!SD.begin(SS, SD_SCK_MHZ(15)))
|
||||||
#else
|
SD.initErrorHalt();
|
||||||
if (!sd.begin(SS, SD_SCK_MHZ(15)))
|
|
||||||
sd.initErrorHalt();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
sd.ls("/", LS_DATE | LS_SIZE | LS_R);
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
File root = SD.open("/");
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
|
auto entry = root.openNextFile();
|
||||||
|
if (!entry)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!entry.isDirectory()) {
|
||||||
|
c->put_string(entry.name());
|
||||||
|
c->put_string("\t\t");
|
||||||
|
c->put_string_lf(format("%ld", entry.size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.close();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
SD.ls("/", LS_DATE | LS_SIZE | LS_R);
|
||||||
|
#endif
|
||||||
|
|
||||||
c->flush_input();
|
c->flush_input();
|
||||||
|
|
||||||
|
@ -334,7 +351,6 @@ std::optional<std::pair<std::vector<disk_backend *>, std::vector<disk_backend *>
|
||||||
if (fh.open(selected_file.c_str(), O_RDWR)) {
|
if (fh.open(selected_file.c_str(), O_RDWR)) {
|
||||||
fh.close();
|
fh.close();
|
||||||
|
|
||||||
#if !defined(BUILD_FOR_RP2040) // FIXME
|
|
||||||
disk_backend *temp = new disk_backend_esp32(selected_file);
|
disk_backend *temp = new disk_backend_esp32(selected_file);
|
||||||
|
|
||||||
if (!temp->begin()) {
|
if (!temp->begin()) {
|
||||||
|
@ -351,7 +367,6 @@ std::optional<std::pair<std::vector<disk_backend *>, std::vector<disk_backend *>
|
||||||
|
|
||||||
if (disk_type.value() == DT_RL02)
|
if (disk_type.value() == DT_RL02)
|
||||||
return { { { }, { temp } } };
|
return { { { }, { temp } } };
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c->put_string_lf("open failed");
|
c->put_string_lf("open failed");
|
||||||
|
@ -521,6 +536,21 @@ void setup() {
|
||||||
Serial.println(getCpuFrequencyMhz());
|
Serial.println(getCpuFrequencyMhz());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
#if defined(BUILD_FOR_RP2040)
|
||||||
|
SPI.setRX(MISO);
|
||||||
|
SPI.setTX(MOSI);
|
||||||
|
SPI.setSCK(SCK);
|
||||||
|
|
||||||
|
for(int i=0; i<3; i++) {
|
||||||
|
if (SD.begin(false, SD_SCK_MHZ(10), SPI))
|
||||||
|
break;
|
||||||
|
|
||||||
|
Serial.println(F("Cannot initialize SD card"));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(BUILD_FOR_RP2040)
|
#if defined(BUILD_FOR_RP2040)
|
||||||
LittleFSConfig cfg;
|
LittleFSConfig cfg;
|
||||||
cfg.setAutoFormat(false);
|
cfg.setAutoFormat(false);
|
||||||
|
|
1
RP2040/disk_backend_esp32.cpp
Symbolic link
1
RP2040/disk_backend_esp32.cpp
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../ESP32/disk_backend_esp32.cpp
|
1
RP2040/disk_backend_esp32.h
Symbolic link
1
RP2040/disk_backend_esp32.h
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../ESP32/disk_backend_esp32.h
|
|
@ -3,6 +3,7 @@
|
||||||
#if defined(BUILD_FOR_RP2040)
|
#if defined(BUILD_FOR_RP2040)
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <FreeRTOS.h>
|
#include <FreeRTOS.h>
|
||||||
|
#include <SD.h>
|
||||||
#include <semphr.h>
|
#include <semphr.h>
|
||||||
#include <task.h>
|
#include <task.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -371,12 +371,14 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
|
||||||
#endif
|
#endif
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#if defined(ESP32)
|
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
|
||||||
else if (cmd == "cfgdisk") {
|
else if (cmd == "cfgdisk") {
|
||||||
configure_disk(cnsl);
|
configure_disk(cnsl);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(ESP32)
|
||||||
else if (cmd == "cfgnet") {
|
else if (cmd == "cfgnet") {
|
||||||
configure_network(cnsl);
|
configure_network(cnsl);
|
||||||
|
|
||||||
|
@ -453,10 +455,12 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
|
||||||
cnsl->put_string_lf("cfgnet - configure network (e.g. WiFi)");
|
cnsl->put_string_lf("cfgnet - configure network (e.g. WiFi)");
|
||||||
cnsl->put_string_lf("startnet - start network");
|
cnsl->put_string_lf("startnet - start network");
|
||||||
cnsl->put_string_lf("chknet - check network status");
|
cnsl->put_string_lf("chknet - check network status");
|
||||||
cnsl->put_string_lf("cfgdisk - configure disk");
|
|
||||||
cnsl->put_string_lf("serspd - set serial speed in bps (8N1 are default)");
|
cnsl->put_string_lf("serspd - set serial speed in bps (8N1 are default)");
|
||||||
cnsl->put_string_lf("init - reload (disk-)configuration from flash");
|
cnsl->put_string_lf("init - reload (disk-)configuration from flash");
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
|
||||||
|
cnsl->put_string_lf("cfgdisk - configure disk");
|
||||||
|
#endif
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue