Skip to content

Commit

Permalink
Pi Pico port improvements
Browse files Browse the repository at this point in the history
    * /dev/tty1 is not fully blocking console for kput
    * /dev/tty2-5 can be configured as independent USB ttys
        * USB ttys operate through a small ring-buffer to minimize
          dropouts at high rate of transmission
    * NAND flash (as block device) can be disabled in config to save 7KB of RAM
    * /dev/pico device can be used to trigger reboot into flash mode.
      See utils/rpi script
    * Trimmed pico SDK to save 5KB of RAM
    * Patched ps to report number of used blocks (4KB) per process
    * Misc fix of makeversion.c to prevent overflow
  • Loading branch information
veremenko-y committed Mar 31, 2024
1 parent 83151c8 commit dfb65d4
Show file tree
Hide file tree
Showing 29 changed files with 595 additions and 110 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ size.report
.obj
*.elf
bin
*.debug
7 changes: 7 additions & 0 deletions Kernel/platform/platform-rpipico/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
utils/progbase.h
utils/ps
utils/ps.c
utils/*.o
filesystem.*
uf2conv

21 changes: 18 additions & 3 deletions Kernel/platform/platform-rpipico/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_BUILD_TYPE Debug)
set(PICO_COPY_TO_RAM 1)

add_compile_definitions(
PICO_HEAP_SIZE=0x0
PICO_NO_BINARY_INFO=1
PICO_TIME_DEFAULT_ALARM_POOL_DISABLED
PICO_NO_GC_SECTIONS
)

remove_definitions(
LIB_PICO_STDIO_UART
LIB_PICO_STDIO_USB
LIB_PICO_STDIO_SEMIHOSTING
PICO_NO_GC_SECTIONS
)

pico_sdk_init()

include_directories(
Expand All @@ -20,13 +34,16 @@ include_directories(

add_executable(fuzix
devices.c
devrpi.c
devflash.c
devsdspi.c
#/*devsdspidma.c*/
devtty.c
elf.c
main.c
misc.c
rawflash.c
rawuart.c
swapper.c
tricks.S
core1.c
Expand Down Expand Up @@ -70,9 +87,7 @@ target_link_libraries(fuzix
pico_multicore
hardware_flash
hardware_spi
hardware_uart
tinyusb_device_unmarked
tinyusb_board
tinyusb_device
)

pico_set_float_implementation(fuzix none)
Expand Down
5 changes: 5 additions & 0 deletions Kernel/platform/platform-rpipico/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ image:: world uf2conv
arm-none-eabi-objcopy -I binary -O elf32-littlearm --change-section-vma .data=0x10018000 filesystem.ftl filesystem.elf
./uf2conv filesystem.ftl filesystem.uf2 0x10018000

image-sd:: world uf2conv
./update-flash.sh sd

clean:
rm -rf build
$(MAKE) -C ../../../Library/libs -f Makefile.armm0 clean
Expand All @@ -31,6 +34,7 @@ clean:
$(MAKE) -C ../../../Applications/cave -f Makefile.armm0 clean
$(MAKE) -C ../../../Applications/cursesgames -f Makefile.armm0 clean
$(MAKE) -C ../../../Standalone clean
$(MAKE) -C utils clean

world: build/fuzix.elf
$(MAKE) -C ../../../Library/libs -f Makefile.armm0
Expand All @@ -42,6 +46,7 @@ world: build/fuzix.elf
$(MAKE) -C ../../../Applications/cave -f Makefile.armm0
$(MAKE) -C ../../../Applications/cursesgames -f Makefile.armm0
$(MAKE) -C ../../../Standalone
$(MAKE) -C utils

uf2conv: tools/uf2conv.c
cc -O -g -o $@ $<
Expand Down
15 changes: 15 additions & 0 deletions Kernel/platform/platform-rpipico/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ You can't turn swap off again.

You probably can swap to the NAND flash, but it's a terrible idea.

## Boot device

Edit config.h to select appropriate boot device.

`#define BOOTDEVICE 0x0000` - for NAND flash (hda)

`#define BOOTDEVICE 0x0011` - for the first partioin on the SD card (hdb1)

## Using the NAND flash

The Pico's built-in NAND flash is supported, appearing as `/dev/hda` insize
Expand All @@ -131,6 +139,13 @@ gets notified when sectors become free, but if the filesystem gets very full
and Dhara runs out it can get extremely slow as it constantly does garbage
collection.

## Using SD Card

1. Create dos partition table
* Partition 1: 32MB partition
* Partition 2: 4MB partition (optional)
2. Run `dd if=filesystem.img bs=512 seek=2048 of=/dev/sdX conv=notrunc status=progress` to copy image onto SD card. (**Be careful to not damage your system drive**)

## Issues

There are many, the biggest of which are:
Expand Down
27 changes: 22 additions & 5 deletions Kernel/platform/platform-rpipico/config.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef CONFIG_H
#define CONFIG_H
#include "tusb_config.h"
/*
* Set this according to your SD card pins (default
* is the David Given arrangement).
Expand Down Expand Up @@ -42,13 +45,22 @@
#undef CONFIG_VT
#undef CONFIG_FONT8X8

/* Disable block device in flash. Warning, it's unstable. */
#define PICO_DISABLE_FLASH

/* Program layout */
#ifndef PICO_DISABLE_FLASH
#define FLASHCODESIZE 7
#else
#define FLASHCODESIZE 0
#endif

#define USERMEM ((172-FLASHCODESIZE)*1024)

#define UDATA_BLKS 3
#define UDATA_SIZE (UDATA_BLKS << BLKSHIFT)
#define USERMEM (160*1024)
#define PROGSIZE (65536 - UDATA_SIZE)
extern uint8_t progbase[USERMEM];
extern char progbase[USERMEM];
#define udata (*(struct u_data*)progbase)

#define USERSTACK (4*1024) /* 4kB */
Expand All @@ -69,11 +81,16 @@ extern uint8_t progbase[USERMEM];
/* We need a tidier way to do this from the loader */
#define CMDLINE NULL /* Location of root dev name */

#define BOOTDEVICE 0x0000 /* hda */
#define BOOTDEVICE 0x0011 /* hda 0x0000 hdb1 0x0011 */
#define SWAPDEV (swap_dev) /* dynamic swap */

/* Device parameters */
#define NUM_DEV_TTY 1
#define NUM_DEV_TTY_UART 1
#define NUM_DEV_TTY_USB (CFG_TUD_CDC)
#define NUM_DEV_TTY (NUM_DEV_TTY_UART + NUM_DEV_TTY_USB)

#define USB_TO_TTY(x) (x + 1 + NUM_DEV_TTY_UART)
#define TTY_TO_USB(x) (x - 1 - NUM_DEV_TTY_UART)

#define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */
#define NBUFS 20 /* Number of block buffers */
Expand All @@ -91,5 +108,5 @@ extern uint8_t progbase[USERMEM];
#define MANGLED 1
#include "mangle.h"

#endif
// vim: sw=4 ts=4 et

Loading

0 comments on commit dfb65d4

Please sign in to comment.