Skip to content

Commit

Permalink
Add 133MHz variant
Browse files Browse the repository at this point in the history
Also fixes the github action
  • Loading branch information
kbeckmann committed Oct 31, 2024
1 parent 390d6ab commit ebeedb3
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 71 deletions.
55 changes: 35 additions & 20 deletions .github/workflows/20_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- main
- develop
- ci
- feature/133MHz
pull_request:
branches:
- main
Expand Down Expand Up @@ -53,18 +54,20 @@ jobs:
- name: Build testrom using the libdragon docker image
run: |
docker run \
--mount type=bind,source=$(pwd),target=/ci \
--workdir=/ci \
ghcr.io/dragonminded/libdragon:latest \
bash -c "\
git config --global --add safe.directory /ci/picocart64 && \
(cd libdragon && ./build.sh) && \
make -C ./picocart64/sw/n64/testrom"
mkdir artifacts
cp ./picocart64/sw/n64/testrom/build/testrom.z64 ./artifacts/
--mount type=bind,source=$(pwd),target=/ci \
--workdir=/ci \
ghcr.io/dragonminded/libdragon:latest \
bash -c "\
git config --global --add safe.directory /ci/picocart64 && \
(cd libdragon && ./build.sh) && \
make -C ./picocart64/sw/n64/testrom && \
echo 'we came this far' && \
mkdir -p artifacts && \
find . && \
cp ./picocart64/sw/n64/testrom/testrom.z64 ./artifacts/ "
- name: Prepare test ROM for build
run: python3 picocart64/sw/scripts/load_rom.py --compress picocart64/sw/n64/testrom/build/testrom.z64
run: python3 picocart64/sw/scripts/load_rom.py --compress picocart64/sw/n64/testrom/testrom.z64

- name: Build PicoCart64 using the pico-sdk-builder docker image
run: |
Expand All @@ -73,18 +76,30 @@ jobs:
--workdir=/ci \
ghcr.io/kbeckmann/pico-sdk-builder:latest \
bash -c "\
git config --global --add safe.directory /ci/picocart64 && \
mkdir picocart64/sw/build && \
cd picocart64/sw/build && \
cmake -DREGION=PAL .. && \
make && \
cp picocart64_v1/picocart64_v1.uf2 /ci/artifacts/picocart64-v1-pal.uf2 && \
cmake -DREGION=NTSC .. && \
make && \
cp picocart64_v1/picocart64_v1.uf2 /ci/artifacts/picocart64-v1-ntsc.uf2"
git config --global --add safe.directory /ci/picocart64 && \
mkdir picocart64/sw/build && \
cd picocart64/sw/build && \
cmake -DREGION=PAL .. && \
make && \
cp picocart64_v1/picocart64_v1.uf2 /ci/artifacts/picocart64-v1-pal.uf2 && \
\
cd .. && rm -rf build && mkdir build && cd build && \
cmake -DREGION=NTSC .. && \
make && \
cp picocart64_v1/picocart64_v1.uf2 /ci/artifacts/picocart64-v1-ntsc.uf2 && \
\
cd .. && rm -rf build && mkdir build && cd build && \
cmake -DREGION=PAL -DCPU_FREQ_MHZ=133 -DROM_HEADER_OVERRIDE=0x80372040 .. && \
make && \
cp picocart64_v1/picocart64_v1.uf2 /ci/artifacts/picocart64-v1-pal-133MHz.uf2 && \
\
cd .. && rm -rf build && mkdir build && cd build && \
cmake -DREGION=NTSC -DCPU_FREQ_MHZ=133 -DROM_HEADER_OVERRIDE=0x80372040 .. && \
make && \
cp picocart64_v1/picocart64_v1.uf2 /ci/artifacts/picocart64-v1-ntsc-133MHz.uf2"
- name: Upload PicoCart64 binaries with a bundled test rom to artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: picocart64
path: |
Expand Down
17 changes: 17 additions & 0 deletions sw/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64",
"compileCommands": "${workspaceFolder}/compile_commands.json"
}
],
"version": 4
}
64 changes: 17 additions & 47 deletions sw/n64/testrom/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
PROG_NAME = testrom
BUILD_DIR = build

ROOTDIR = $(N64_INST)
GCCN64PREFIX = $(ROOTDIR)/bin/mips64-elf-

CC = $(GCCN64PREFIX)gcc
AS = $(GCCN64PREFIX)as
LD = $(GCCN64PREFIX)ld
OBJCOPY = $(GCCN64PREFIX)objcopy
N64TOOL = $(ROOTDIR)/bin/n64tool
CHKSUM64 = $(ROOTDIR)/bin/chksum64
ECHO = echo
all: testrom.z64
.PHONY: all

# To enable verbose prints, set VERBOSE=1 when building:
# make VERBOSE=1
ifneq ($(strip $(VERBOSE)),1)
V = @
endif
BUILD_DIR = build
include $(N64_INST)/include/n64.mk


C_SOURCES = \
Expand All @@ -28,41 +14,25 @@ C_INCLUDES = \
-I$(BUILD_DIR) \
-I../../picocart64_shared/include \

OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
OBJS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))

ASFLAGS = -mtune=vr4300 -march=vr4300
CFLAGS = -std=gnu99 -march=vr4300 -mtune=vr4300 -Wall $(C_INCLUDES)
LDFLAGS = -L$(ROOTDIR)/mips64-elf/lib -ldragon -lc -lm -ldragonsys -Tn64.ld --gc-sections
N64TOOLFLAGS = -l 1M -h $(ROOTDIR)/mips64-elf/lib/header -t "PicoCart64 Test ROM"

all: $(BUILD_DIR)/$(PROG_NAME).z64
CFLAGS += $(C_INCLUDES)

testrom.z64: N64_ROM_TITLE = "PicoCart64 Test ROM"

$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
$(V)$(ECHO) "[ CC ]" $(notdir $<)
$(V)$(CC) -o $@ $< -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst))
$(BUILD_DIR)/testrom.elf: $(OBJS)

$(BUILD_DIR)/$(PROG_NAME).z64: $(BUILD_DIR)/$(PROG_NAME).bin
$(V)$(ECHO) "[ Z64 ]" $(notdir $@)
$(V)$(N64TOOL) $(N64TOOLFLAGS) -o $@ $^
$(V)$(ECHO) "[ CHK ]" $(notdir $@)
$(V)$(CHKSUM64) $@
$(BUILD_DIR)/testrom.o: $(BUILD_DIR)/git_info.h

$(BUILD_DIR)/$(PROG_NAME).bin: $(BUILD_DIR)/$(PROG_NAME).elf
$(V)$(ECHO) "[ BIN ]" $(notdir $@)
$(V)$(OBJCOPY) $< $@ -O binary

$(BUILD_DIR)/$(PROG_NAME).elf: $(OBJECTS)
$(V)$(ECHO) "[ LD ]" $(notdir $@)
$(V)$(LD) -o $@ $^ $(LDFLAGS)

$(BUILD_DIR):
$(V)mkdir -p $@
$(V)echo -n "#define GIT_REV 0x" > $(BUILD_DIR)/git_info.h
$(V)git rev-parse --short=8 HEAD >> $(BUILD_DIR)/git_info.h
$(BUILD_DIR)/git_info.h:
mkdir -p $(BUILD_DIR)
echo -n "#define GIT_REV 0x" > $(BUILD_DIR)/git_info.h
git rev-parse --short=8 HEAD >> $(BUILD_DIR)/git_info.h
.PHONY: $(BUILD_DIR)

.PHONY: clean
clean:
rm -rf ./build
rm -rf $(BUILD_DIR) *.z64
.PHONY: clean

-include $(wildcard $(BUILD_DIR)/*.d))
17 changes: 17 additions & 0 deletions sw/picocart64_v1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ else()
message(FATAL_ERROR "Please set the variable REGION to either NTSC or PAL")
endif()

if(NOT DEFINED CPU_FREQ_MHZ)
message("CPU_FREQ_MHZ: Using default overclocked CPU Frequency of 266 MHz")
set(CONFIG_CPU_FREQ_MHZ 266)
else()
message("CPU_FREQ_MHZ: Using custom CPU Frequency of ${CPU_FREQ_MHZ} MHz")
set(CONFIG_CPU_FREQ_MHZ ${CPU_FREQ_MHZ})
endif()
if(NOT DEFINED ROM_HEADER_OVERRIDE)
message("ROM_HEADER_OVERRIDE: Disabled")
set(CONFIG_ROM_HEADER_OVERRIDE 0)
else()
message("ROM_HEADER_OVERRIDE: Using custom header=${ROM_HEADER_OVERRIDE}")
set(CONFIG_ROM_HEADER_OVERRIDE ${ROM_HEADER_OVERRIDE})
endif()

if(NOT DEFINED FLASH_SIZE_MB)
set(FLASH_SIZE_MB 2)
endif()
Expand All @@ -41,6 +56,8 @@ target_compile_definitions(picocart64_v1 PRIVATE
PICO_STDOUT_MUTEX=0
CONFIG_REGION_NTSC=${CONFIG_REGION_NTSC}
CONFIG_REGION_PAL=${CONFIG_REGION_PAL}
CONFIG_CPU_FREQ_MHZ=${CONFIG_CPU_FREQ_MHZ}
CONFIG_ROM_HEADER_OVERRIDE=${CONFIG_ROM_HEADER_OVERRIDE}
)

# Generate git_info.h
Expand Down
35 changes: 35 additions & 0 deletions sw/picocart64_v1/n64_pi_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,41 @@ void n64_pi_run(void)
// most timing critical to least.
if (last_addr >= CART_DOM1_ADDR2_START && last_addr <= CART_DOM1_ADDR2_END) {
// Domain 1, Address 2 Cartridge ROM

#if CONFIG_ROM_HEADER_OVERRIDE != 0
if (last_addr == 0x10000000) {
// Special case to patch PI access speed paramenters

// 16 MSB
next_word = CONFIG_ROM_HEADER_OVERRIDE >> 16;
addr = n64_pi_get_value(pio);
if (addr == 0) {
// READ
pio_sm_put(pio, 0, next_word);
} else if ((addr & 0xffff0000) == 0xffff0000) {
// WRITE, ignore
} else {
// New address
continue;
}
last_addr += 2;

// 16 LSB
next_word = CONFIG_ROM_HEADER_OVERRIDE & 0xFFFF;
addr = n64_pi_get_value(pio);
if (addr == 0) {
// READ
pio_sm_put(pio, 0, next_word);
} else if ((addr & 0xffff0000) == 0xffff0000) {
// WRITE, ignore
} else {
// New address
continue;
}
last_addr += 2;
}
#endif

do {
// Pre-fetch from the address
#if COMPRESSED_ROM
Expand Down
11 changes: 7 additions & 4 deletions sw/picocart64_v1/picocart64_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ void cic_task_entry(__unused void *params)
n64_cic_task(sram_save_to_flash);
}

void second_task_entry(__unused void *params)
#if 0
static void second_task_entry(__unused void *params)
{
uint32_t count = 0;

Expand Down Expand Up @@ -126,11 +127,12 @@ void second_task_entry(__unused void *params)

}
}
#endif

void vLaunch(void)
{
xTaskCreateStatic(cic_task_entry, "CICThread", configMINIMAL_STACK_SIZE, NULL, CIC_TASK_PRIORITY, cic_task_stack, &cic_task);
xTaskCreateStatic(second_task_entry, "SecondThread", configMINIMAL_STACK_SIZE, NULL, SECOND_TASK_PRIORITY, second_task_stack, &second_task);
// xTaskCreateStatic(second_task_entry, "SecondThread", configMINIMAL_STACK_SIZE, NULL, SECOND_TASK_PRIORITY, second_task_stack, &second_task);

/* Start the tasks and timer running. */
vTaskStartScheduler();
Expand Down Expand Up @@ -159,8 +161,7 @@ int main(void)
// but since it's used with a 2x clock divider,
// 266 MHz is safe in this regard.

// set_sys_clock_khz(133000, true);
set_sys_clock_khz(266000, true); // Required for SRAM @ 200ns
set_sys_clock_khz(CONFIG_CPU_FREQ_MHZ * 1000, true);

// Init GPIOs before starting the second core and FreeRTOS
for (int i = 0; i <= 27; i++) {
Expand All @@ -185,6 +186,8 @@ int main(void)
// Init UART on pin 28/29
stdio_async_uart_init_full(UART_ID, BAUD_RATE, UART_TX_PIN, UART_RX_PIN);
printf("PicoCart64 Boot (git rev %08x)\r\n", GIT_REV);
printf(" CPU_FREQ_MHZ=%d\n", CONFIG_CPU_FREQ_MHZ);
printf(" ROM_HEADER_OVERRIDE=%08lX\n", CONFIG_ROM_HEADER_OVERRIDE);

#if ENABLE_N64_PI
// Launch the N64 PI implementation in the second core
Expand Down

0 comments on commit ebeedb3

Please sign in to comment.