Basic SHA20127-badge port

This commit is contained in:
folkert van heusden 2023-04-01 19:07:59 +02:00
parent c875b943d1
commit 393ec9098b
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
8 changed files with 66 additions and 30 deletions

View file

@ -37,7 +37,7 @@ bool disk_backend_esp32::read(const off_t offset, const size_t n, uint8_t *const
{
DOLOG(debug, false, "disk_backend_esp32::read: read %zu bytes from offset %zu", n, offset);
#if defined(ESP32)
#if defined(ESP32) && !defined(SHA2017)
digitalWrite(LED_BUILTIN, LOW);
#endif
@ -49,7 +49,7 @@ bool disk_backend_esp32::read(const off_t offset, const size_t n, uint8_t *const
if (fh->read(target, n) != size_t(n)) {
DOLOG(debug, true, "fread error: %s", strerror(errno));
#if defined(ESP32)
#if defined(ESP32) && !defined(SHA2017)
digitalWrite(LED_BUILTIN, HIGH);
#endif
return false;
@ -57,7 +57,7 @@ bool disk_backend_esp32::read(const off_t offset, const size_t n, uint8_t *const
yield();
#if defined(ESP32)
#if defined(ESP32) && !defined(SHA2017)
digitalWrite(LED_BUILTIN, HIGH);
#endif
@ -68,7 +68,7 @@ bool disk_backend_esp32::write(const off_t offset, const size_t n, const uint8_t
{
DOLOG(debug, false, "disk_backend_esp32::write: write %zu bytes to offset %zu", n, offset);
#if defined(ESP32)
#if defined(ESP32) && !defined(SHA2017)
digitalWrite(LED_BUILTIN, LOW);
#endif
@ -80,7 +80,7 @@ bool disk_backend_esp32::write(const off_t offset, const size_t n, const uint8_t
if (fh->write(from, n) != n) {
DOLOG(ll_error, true, "RK05 fwrite error %s", strerror(errno));
#if defined(ESP32)
#if defined(ESP32) && !defined(SHA2017)
digitalWrite(LED_BUILTIN, HIGH);
#endif
return false;
@ -88,8 +88,8 @@ bool disk_backend_esp32::write(const off_t offset, const size_t n, const uint8_t
yield();
#if defined(ESP32)
digitalWrite(LED_BUILTIN, HIGH);
#if defined(ESP32) && !defined(SHA2017)
digitalWrite(LED_BUILTIN, HIGH);
#endif
return true;

View file

@ -188,8 +188,12 @@ std::optional<disk_backend_t> select_disk_backend(console *const c)
c->put_string("1. network (NBD), 2. local SD card, 9. abort");
int ch = -1;
while(ch == -1 && ch != '1' && ch != '2' && ch != '9')
ch = c->wait_char(500);
while(ch == -1 && ch != '1' && ch != '2' && ch != '9') {
auto temp = c->wait_char(500);
if (temp.has_value())
ch = temp.value();
}
c->put_string_lf(format("%c", ch));
@ -208,8 +212,12 @@ std::optional<disk_type_t> select_disk_type(console *const c)
c->put_string("1. RK05, 2. RL02, 9. abort");
int ch = -1;
while(ch == -1 && ch != '1' && ch != '2' && ch != '9')
ch = c->wait_char(500);
while(ch == -1 && ch != '1' && ch != '2' && ch != '9') {
auto temp = c->wait_char(500);
if (temp.has_value())
ch = temp.value();
}
c->put_string_lf(format("%c", ch));
@ -525,7 +533,9 @@ void setup()
Serial.print(F("Free RAM after init: "));
Serial.println(ESP.getFreeHeap());
#if !defined(SHA2017)
pinMode(LED_BUILTIN, OUTPUT);
#endif
Serial.flush();

View file

@ -2,10 +2,10 @@
# Released under MIT license
[platformio]
default_envs = ESP32
default_envs = ESP32-wemos
src_dir = .
[env:ESP32]
[env:ESP32-wemos]
lib_ldf_mode = deep+
build_src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<build> -<player.cpp>
platform = espressif32
@ -20,15 +20,18 @@ lib_deps = greiman/SdFat@^2.1.2
build_flags = -std=gnu++17 -Ofast -DESP32=1 -ggdb3 -D_GLIBCXX_USE_C99
build_unflags = -std=gnu++11 -Os
#[env:PICO]
#lib_ldf_mode = deep+
#src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<build> -<player.cpp>
#platform = raspberrypi
#board = pico
#framework = arduino
#monitor_speed = 115200
#upload_speed = 1000000
#lib_deps = greiman/SdFat@^2.1.2
# adafruit/Adafruit NeoPixel@^1.10.4
#build_flags = -std=gnu++17 -Ofast -DESP32=1 -ggdb3 -D_GLIBCXX_USE_C99
#build_unflags = -std=gnu++11 -Os
[env:SHA2017-badge]
lib_ldf_mode = deep+
build_src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/> -<build> -<player.cpp>
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
upload_speed = 460800
board_build.filesystem = littlefs
lib_deps = greiman/SdFat@^2.1.2
adafruit/Adafruit NeoPixel
bblanchon/ArduinoJson@^6.19.4
build_flags = -std=gnu++17 -Ofast -DESP32=1 -DSHA2017 -ggdb3 -D_GLIBCXX_USE_C99
build_unflags = -std=gnu++11 -Os
upload_protocol = esptool

View file

@ -50,6 +50,9 @@ Wiring of the MAX232 connection:
* RX : 16
See SHA2017-badge.md if you want to flash your SHA20127 badge with this software.
Released under MIT license.
Folkert van Heusden

12
SHA2017-badge.md Normal file
View file

@ -0,0 +1,12 @@
This procedure will remove the default micropython environment.
Maybe you can undo that, but I have not tried that.
* esptool.py erase\_flash
* pio run -e SHA2017-badge
* esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default\_reset --after hard\_reset write\_flash -z --flash\_mode dio --flash\_freq 80m --flash\_size detect 0x1000 ./.pio/build/ESP32-wemos/bootloader.bin
* pio run -e SHA2017-badge -t upload
After this, you can connect a serial terminal to /dev/ttyUSB0 at 115k2 bps.

View file

@ -650,6 +650,10 @@ void bus::addToMMR1(const int8_t delta, const uint8_t reg)
if (MMR1 > 255)
esp_backtrace_print(32);
#else
if (MMR1 > 255) {
extern FILE *lfh;
fflush(lfh);
}
assert(MMR1 < 256);
#endif

View file

@ -87,7 +87,7 @@ std::optional<char> console::wait_char(const int timeout_ms)
}
}
return -1;
return { };
}
void console::flush_input()

12
cpu.cpp
View file

@ -1571,14 +1571,14 @@ bool cpu::misc_operations(const uint16_t instr)
// PUSH link
pushStack(getRegister(link_reg));
b->addToMMR1(-2, 6);
// MOVE PC,link
setRegister(link_reg, getPC());
// JMP dst
setPC(dst_value);
b->addToMMR1(-2, 6);
return true;
}
@ -1628,9 +1628,11 @@ void cpu::trap(uint16_t vector, const int new_ipl, const bool is_interrupt)
}
else {
before_psw = getPSW();
b->addToMMR1(-2, 6);
before_pc = getPC();
b->addToMMR1(-2, 6);
// TODO set MMR2?
@ -2163,8 +2165,10 @@ void cpu::step_a()
if ((b->getMMR0() & 0160000) == 0)
b->clearMMR1();
if (any_queued_interrupts && check_queued_interrupts())
return; // documentation
if (any_queued_interrupts && check_queued_interrupts()) {
if ((b->getMMR0() & 0160000) == 0)
b->clearMMR1();
}
}
void cpu::step_b()