Skip to content

Commit

Permalink
Merge pull request #5 from wickerwaka/v2
Browse files Browse the repository at this point in the history
New version of the PicoROM board. v1.5.
Adds level shifters to the address inputs, protecting the RP2040 from 5V signals.
Adds a reset pin that can be controlled from the picorom tool to allow resetting the target hardware.
  • Loading branch information
wickerwaka authored Jun 15, 2024
2 parents af12f37 + 371730b commit c7d5f01
Show file tree
Hide file tree
Showing 54 changed files with 44,443 additions and 48,726 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/firmware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
path: |
build/PicoROM.elf
build/PicoROM.uf2
build/PicoROM-1.2.elf
build/PicoROM-1.2.uf2
if-no-files-found: error

release:
Expand Down
Binary file removed docs/PicoROM_PCB.png
Binary file not shown.
Binary file modified docs/PicoROM_Schematic.pdf
Binary file not shown.
31 changes: 31 additions & 0 deletions docs/delay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import csv
import matplotlib.pyplot as plt

header = None
prev = []
rise = {}
delays = []
with open('166Mhz.csv') as fp:
reader = csv.reader(fp)
for row in reader:
if row[0].startswith(';'):
continue
if not header:
header = [x.strip() for x in row]
prev = [ 1 for _ in header[1:] ]
rise = dict(((x, 0) for x in header[1:]))
continue

for idx in range(len(prev)):
v = int(row[idx + 1])
name = header[idx+1]
if prev[idx] == 0 and v == 1:
rise[name] = float(row[0])
if name == 'D2':
a_rise = rise['A2']
delays.append((float(row[0]) - a_rise) * 1000000000)
prev[idx] = v

print(max(delays))
plt.hist(delays, bins=100)
plt.show()
Binary file modified docs/pcb_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 43 additions & 25 deletions firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,57 @@ project(rom_emulator C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
pico_sdk_init()
add_executable(PicoROM
main.cpp
pico_link.cpp
rom.cpp
comms.cpp
)

pico_set_float_implementation(PicoROM none)
pico_set_double_implementation(PicoROM none)
foreach(TARGET PicoROM PicoROM-1.2)
add_executable(${TARGET}
main.cpp
pico_link.cpp
rom.cpp
comms.cpp
)

pico_set_float_implementation(${TARGET} none)
pico_set_double_implementation(${TARGET} none)

pico_generate_pio_header(${TARGET} ${CMAKE_CURRENT_LIST_DIR}/data_bus.pio)
pico_generate_pio_header(${TARGET} ${CMAKE_CURRENT_LIST_DIR}/comms.pio)

pico_enable_stdio_usb(${TARGET} 1)
pico_enable_stdio_uart(${TARGET} 0)

pico_set_linker_script(${TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_firmware.ld)

pico_add_extra_outputs(${TARGET})
target_link_libraries(${TARGET}
pico_stdlib
pico_multicore
hardware_flash
hardware_pio
pico_unique_id
)

pico_set_program_name(${TARGET} PicoROM)
pico_set_program_url(${TARGET} https://github.com/wickerwaka/PicoROM)
endforeach()

pico_set_program_version(PicoROM 1.5/1.5)
pico_set_program_version(PicoROM-1.2 1.5/1.2)

target_compile_definitions(PicoROM PRIVATE
PICO_HEAP_SIZE=16
PICO_STACK_SIZE=640
PICO_CORE1_STACK_SIZE=4
USB_MAX_ENDPOINTS=4
PICO_STDIO_ENABLE_CRLF_SUPPORT=0
OUTPUT_BUFFER=1
ACTIVITY_LED=1
TCA_EXPANDER=1
)

pico_generate_pio_header(PicoROM ${CMAKE_CURRENT_LIST_DIR}/data_bus.pio)
pico_generate_pio_header(PicoROM ${CMAKE_CURRENT_LIST_DIR}/comms.pio)

pico_enable_stdio_usb(PicoROM 1)
pico_enable_stdio_uart(PicoROM 0)

pico_set_linker_script(PicoROM ${CMAKE_CURRENT_LIST_DIR}/memmap_firmware.ld)
target_compile_definitions(PicoROM-1.2 PRIVATE
PICO_HEAP_SIZE=16
PICO_STACK_SIZE=640
PICO_CORE1_STACK_SIZE=4
USB_MAX_ENDPOINTS=4
PICO_STDIO_ENABLE_CRLF_SUPPORT=0
TCA_EXPANDER=0
)

pico_add_extra_outputs(PicoROM)
target_link_libraries(PicoROM
pico_stdlib
pico_multicore
hardware_flash
hardware_pio
pico_unique_id
)
12 changes: 12 additions & 0 deletions firmware/data_bus.pio
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,16 @@ dis_out:
jmp start
en_out:
irq wait 0 rel

wait_clear:
mov osr, pins
out x, 2
jmp !x wait_clear
.wrap


.program tca5405

.wrap_target
out pins, 1
.wrap
98 changes: 86 additions & 12 deletions firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include "rom.h"
#include "comms.h"

#if TCA_EXPANDER
bi_decl(bi_program_feature("Reset"));
#endif

static constexpr uint FLASH_ROM_OFFSET = FLASH_SIZE - ROM_SIZE;
static constexpr uint FLASH_CFG_OFFSET = FLASH_ROM_OFFSET - FLASH_SECTOR_SIZE;
Expand Down Expand Up @@ -104,14 +107,70 @@ void configure_address_pins(uint32_t mask)

static uint8_t identify_request = 0;

#if ACTIVITY_LED==1
repeating_timer_t activity_timer;

static uint8_t identify_ack = 0;
static uint8_t activity_cycles = 0;
static uint8_t activity_duty = 0;
static uint8_t activity_count = 0;

static uint8_t link_cycles = 0;
static uint8_t link_duty = 0;
static uint8_t link_count = 0;

#if TCA_EXPANDER
bool activity_timer_callback(repeating_timer_t * /*unused*/)
{
if (activity_count >= activity_cycles)
{
bool rom_access = rom_check_oe();

activity_cycles = 0;
activity_duty = 0;

if (rom_access)
{
activity_cycles = 5;
activity_duty = 1;
}

activity_count = 0;
}

if (link_count >= link_cycles)
{
bool identify_req = identify_request != identify_ack;
bool usb_activity = pl_check_activity();

link_cycles = 0;
link_duty = 0;

if (identify_req)
{
identify_ack++;
link_cycles = 100;
link_duty = 90;
}
else if (usb_activity)
{
link_cycles = 20;
link_duty = 10;
}

link_count = 0;
}

tca_set_pin(TCA_LINK_PIN, link_count < link_duty);
tca_set_pin(TCA_READ_PIN, activity_count < activity_duty);

activity_count++;
link_count++;

return true;
}

#else

bool activity_timer_callback(repeating_timer_t * /*unused*/)
{
if (activity_count >= activity_cycles)
Expand Down Expand Up @@ -143,20 +202,13 @@ bool activity_timer_callback(repeating_timer_t * /*unused*/)
activity_count = 0;
}

if (activity_count >= activity_duty)
{
gpio_put(ACTIVITY_LED_PIN, false);
}
else
{
gpio_put(ACTIVITY_LED_PIN, true);
}
gpio_put(ACTIVITY_LED_PIN, activity_count < activity_duty);

activity_count++;

return true;
}
#endif // ACTIVITY_LED==1
#endif // TCA_EXPANDER

int main()
{
Expand All @@ -168,15 +220,15 @@ int main()

configure_address_pins(config.addr_mask);

#if ACTIVITY_LED==1
identify_ack = identify_request = 0;

#if !TCA_EXPANDER
gpio_init(ACTIVITY_LED_PIN);
gpio_set_dir(ACTIVITY_LED_PIN, true);
gpio_set_input_enabled(ACTIVITY_LED_PIN, false);
#endif

add_repeating_timer_ms(10, activity_timer_callback, nullptr, &activity_timer);
#endif

memcpy(rom_get_buffer(), flash_rom_data, ROM_SIZE);

Expand Down Expand Up @@ -312,6 +364,28 @@ int main()
break;
}

case PacketType::Reset:
{
#if TCA_EXPANDER
switch(req->payload[0])
{
case 'L':
tca_set_pin(TCA_RESET_VALUE_PIN, false);
tca_set_pin(TCA_RESET_PIN, true);
break;

case 'H':
tca_set_pin(TCA_RESET_VALUE_PIN, true);
tca_set_pin(TCA_RESET_PIN, true);
break;

default:
tca_set_pin(TCA_RESET_PIN, false);
break;
}
#endif // TCA_EXPANDER
}

default:
{
pl_send_error("Unrecognized packet", req->type, req->size);
Expand Down
1 change: 1 addition & 0 deletions firmware/pico_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum class PacketType : uint8_t

CommitFlash = 12,
CommitDone = 13,
Reset = 14,

CommsStart = 80,
CommsEnd = 81,
Expand Down
Loading

0 comments on commit c7d5f01

Please sign in to comment.