Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions firmware/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,20 @@
"version": "0.2.0",
"configurations": [
{
"name": "Pico Debug",
"cwd": "${workspaceRoot}",
"name": "Cortex Debug",
"cwd": "${workspaceFolder}",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
// This may need to be arm-none-eabi-gdb depending on your system
"gdbPath" : "arm-none-eabi-gdb",
"device": "RP2040",
"configFiles": [
"interface/cmsis-dap.cfg",
"target/rp2040.cfg"
],
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
"runToMain": true,
// Work around for stopping at main on restart
"postRestartCommands": [
"break main",
"continue"
],
"searchDir": ["/Users/akawaka/Source/openocd/tcl"],
"serverArgs": [ "-c adapter speed 5000" ]
"runToEntryPoint": "main",
"servertype": "jlink",
"serverpath": "/Applications/SEGGER/JLink_V888/JLinkGDBServerCLExe",
"serverArgs": [],
"device": "RP2040_M0_0",
"interface": "swd",
"serialNumber": "", //If you have more than one J-Link probe, add the serial number here.
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/RP2040.svd",
"armToolchainPath": "/opt/homebrew/bin/"
}
]
}
12 changes: 8 additions & 4 deletions firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ string(REPLACE . _ FILENAME_VERSION ${VERSION})

pico_sdk_init()


pico_define_boot_stage2(boot_div4 ${PICO_DEFAULT_BOOT_STAGE2_FILE})
target_compile_definitions(boot_div4 PRIVATE PICO_FLASH_SPI_CLKDIV=4)


foreach(BUILD_CONFIG 2MBit 2MBit_100ns 1MBit_Clock)
foreach(BUILD_CONFIG 2MBit 2MBit_100ns 28P_512KBit)
set(TARGET PicoROM-${BUILD_CONFIG}-${FILENAME_VERSION})
add_executable(${TARGET} EXCLUDE_FROM_ALL
main.cpp
Expand Down Expand Up @@ -66,15 +65,20 @@ foreach(BUILD_CONFIG 2MBit 2MBit_100ns 1MBit_Clock)
pico_set_program_version(${TARGET} ${VERSION})
endforeach()

target_compile_definitions(PicoROM-1MBit_Clock-${FILENAME_VERSION} PRIVATE
FEATURE_CLOCK=1
target_compile_definitions(PicoROM-2MBit-${FILENAME_VERSION} PRIVATE
BOARD_32P_TCA=1
)

target_compile_definitions(PicoROM-2MBit_100ns-${FILENAME_VERSION} PRIVATE
BOARD_32P_TCA=1
FEATURE_STABLE_ADDRESS=1
)

target_compile_definitions(PicoROM-28P_512KBit-${FILENAME_VERSION} PRIVATE
BOARD_28P=1
)

set_target_properties(PicoROM-2MBit-${FILENAME_VERSION} PROPERTIES EXCLUDE_FROM_ALL FALSE)
set_target_properties(PicoROM-2MBit_100ns-${FILENAME_VERSION} PROPERTIES EXCLUDE_FROM_ALL FALSE)
set_target_properties(PicoROM-28P_512KBit-${FILENAME_VERSION} PROPERTIES EXCLUDE_FROM_ALL FALSE)

20 changes: 19 additions & 1 deletion firmware/data_bus.pio
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,25 @@

; Report activity to CPU
; 8 ops
.program report_data_access
.program report_data_access_24
wait_oe:
mov y, pins ; read in all pins
mov osr, y ; move into the osr so we can shift them out
out null, 24 ; skip all the other pins
out x, 2 ; move OE in x
jmp x-- wait_oe ; if /OE or /CS are high, check again

irq nowait 0 rel ; tell the cpu

.wrap_target
wait_change:
mov x, pins ; read all pins again
jmp x!=y wait_oe ; if any have changed, restart and check oe again
.wrap

; Report activity to CPU
; 8 ops
.program report_data_access_20
wait_oe:
mov y, pins ; read in all pins
mov osr, y ; move into the osr so we can shift them out
Expand Down
28 changes: 27 additions & 1 deletion firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,23 @@ bool activity_timer_callback(repeating_timer_t * /*unused*/)
link_count = 0;
}

#if defined(BOARD_32P_TCA)
tca_set_pin(TCA_LINK_PIN, link_count < link_duty);
tca_set_pin(TCA_READ_PIN, activity_count < activity_duty);

#else
if (link_count < link_duty)
{
gpio_put(INFO_LED_PIN, true);
}
else if (activity_count < activity_duty)
{
gpio_put(INFO_LED_PIN, true);
}
else
{
gpio_put(INFO_LED_PIN, false);
}
#endif
activity_count++;
link_count++;

Expand All @@ -120,19 +134,31 @@ void reset_set(ResetLevel level)
switch (level)
{
case ResetLevel::Low:
#if defined(BOARD_32P_TCA)
tca_set_pin(TCA_RESET_VALUE_PIN, false);
tca_set_pin(TCA_RESET_PIN, true);
#else
gpio_put(RESET_PIN, false);
#endif
current_reset = ResetLevel::Low;
break;

case ResetLevel::High:
#if defined(BOARD_32P_TCA)
tca_set_pin(TCA_RESET_VALUE_PIN, true);
tca_set_pin(TCA_RESET_PIN, true);
#else
gpio_put(RESET_PIN, false);
#endif
current_reset = ResetLevel::High;
break;

default:
#if defined(BOARD_32P_TCA)
tca_set_pin(TCA_RESET_PIN, false);
#else
gpio_put(RESET_PIN, true);
#endif
current_reset = ResetLevel::Z;
break;
}
Expand Down
69 changes: 53 additions & 16 deletions firmware/pico_sdk_import.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@
# This can be dropped into an external project to help locate this SDK
# It should be include()ed prior to project()

# Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
# following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
Expand Down Expand Up @@ -40,25 +62,40 @@ if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
# GIT_SUBMODULES_RECURSE was added in 3.17
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
GIT_SUBMODULES_RECURSE FALSE
)
else ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
)
endif ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
)

if (NOT pico_sdk)
message("Downloading Raspberry Pi Pico SDK")
FetchContent_Populate(pico_sdk)
# GIT_SUBMODULES_RECURSE was added in 3.17
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
FetchContent_Populate(
pico_sdk
QUIET
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
GIT_SUBMODULES_RECURSE FALSE

SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src
BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build
SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild
)
else ()
FetchContent_Populate(
pico_sdk
QUIET
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}

SOURCE_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-src
BINARY_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-build
SUBBUILD_DIR ${FETCHCONTENT_BASE_DIR}/pico_sdk-subbuild
)
endif ()

set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
Expand Down
8 changes: 7 additions & 1 deletion firmware/pio_programs.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "pio_programs.h"

#include "system.h"
#include "comms.pio.h"
#include "data_bus.pio.h"
#include <hardware/pio.h>
Expand Down Expand Up @@ -51,7 +52,12 @@ bool pio_programs_init()
add_program(pio0, 3, data_output, prg_data_output);

add_program(pio1, 0, set_output_enable, prg_set_output_enable);
add_program(pio1, 1, report_data_access, prg_report_data_access);

if (BASE_OE_PIN == 20)
add_program(pio1, 1, report_data_access_20, prg_report_data_access);
else
add_program(pio1, 1, report_data_access_24, prg_report_data_access);

add_program(pio1, 2, comms_clock, prg_comms_clock);
add_program(pio1, 3, write_tca_bits, prg_write_tca_bits);

Expand Down
29 changes: 28 additions & 1 deletion firmware/rom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ static void rom_pio_init_output_enable_report_program()
{
PRG_LOCAL(prg_report_data_access, p, sm, offset, cfg);

// TODO - should we use BASE_OE_PIN here?
// This program looks at all input pins
sm_config_set_in_pins(&cfg, 0);

Expand All @@ -137,6 +138,7 @@ static void rom_pio_init_output_enable_report_program()
}
}

#if defined(BOARD_32P_TCA)
static void rom_pio_init_tca_program()
{
if (prg_write_tca_bits.valid())
Expand All @@ -155,6 +157,7 @@ static void rom_pio_init_tca_program()
pio_sm_set_enabled(p, sm, true);
}
}
#endif

void rom_init_programs()
{
Expand Down Expand Up @@ -183,19 +186,41 @@ void rom_init_programs()
gpio_set_inover(BUF_OE_PIN, GPIO_OVERRIDE_LOW);
gpio_set_slew_rate(BUF_OE_PIN, GPIO_SLEW_RATE_FAST);

#if defined(BOARD_32P_TCA)
pio_gpio_init(prg_write_tca_bits.pio(), TCA_EXPANDER_PIN);
gpio_set_input_enabled(TCA_EXPANDER_PIN, false);
gpio_set_inover(TCA_EXPANDER_PIN, GPIO_OVERRIDE_LOW);
gpio_set_drive_strength(TCA_EXPANDER_PIN, GPIO_DRIVE_STRENGTH_2MA);
rom_pio_init_tca_program();
#else
gpio_init(INFO_LED_PIN);
gpio_set_input_enabled(INFO_LED_PIN, false);
gpio_set_inover(INFO_LED_PIN, GPIO_OVERRIDE_LOW);
gpio_set_dir(INFO_LED_PIN, true);
gpio_put(INFO_LED_PIN, false);

gpio_init(BUF_DIR_PIN);
gpio_set_input_enabled(BUF_DIR_PIN, false);
gpio_set_inover(BUF_DIR_PIN, GPIO_OVERRIDE_LOW);
gpio_set_dir(BUF_DIR_PIN, true);
gpio_put(BUF_DIR_PIN, false);

gpio_init(RESET_PIN);
gpio_set_input_enabled(RESET_PIN, false);
gpio_set_inover(RESET_PIN, GPIO_OVERRIDE_LOW);
gpio_set_dir(RESET_PIN, true);
gpio_put(RESET_PIN, false);
#endif

rom_pio_init_output_program();
rom_pio_init_pindirs_program();
rom_pio_init_output_enable_program();
rom_pio_init_output_enable_report_program();
rom_pio_init_tca_program();

#if defined(BOARD_32P_TCA)
tca_set_pins(0x00);
tca_set_pins(0x00);
#endif
}

uint8_t *rom_get_buffer()
Expand Down Expand Up @@ -227,6 +252,7 @@ bool rom_check_oe()
return false;
}

#if defined(BOARD_32P_TCA)
static uint8_t tca_pins_state = 0x0;
void tca_set_pins(uint8_t pins)
{
Expand All @@ -248,3 +274,4 @@ void tca_set_pin(int pin, bool en)
tca_set_pins(new_state);
}
}
#endif
4 changes: 3 additions & 1 deletion firmware/rom.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ uint8_t *rom_get_buffer();

bool rom_check_oe();

#if defined(BOARD_32P_TCA)
void tca_set_pins(uint8_t pins);
void tca_set_pin(int pin, bool en);
#endif

#endif // ROM_H
#endif // ROM_H
Loading
Loading