Skip to content

Commit

Permalink
Merge pull request #1107 from veremenko-y/pico1
Browse files Browse the repository at this point in the history
pico: SD card speed improvement, rudimentary pico2 support, initial net support
  • Loading branch information
EtchedPixels authored Nov 18, 2024
2 parents 1a6aeba + b886d1f commit 9e6066d
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 170 deletions.
3 changes: 3 additions & 0 deletions Kernel/platform/platform-rpipico/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ add_executable(fuzix
../../tty.c
../../usermem.c
../../version.c
../../dev/net/net_native.c
../../syscall_net.c
../../network.c
)

target_link_libraries(fuzix
Expand Down
31 changes: 20 additions & 11 deletions Kernel/platform/platform-rpipico/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# Set one of these depending.
export PICO_SDK_FETCH_FROM_GIT = yes
#export PICO_SDK_PATH = ${HOME}/.pico-sdk/sdk/1.5.1
#export PICO_SDK_PATH = ${HOME}/doclocal/pico-sdk
SUBTARGET=pico

# Set 'SUBTARGET' to one of pico-sdk compatible boards
ifndef SUBTARGET
$(error "Must set SUBTARGET to pico, pico_w or pico2")
endif

FSFAMILY=rp2040
ifeq (SUBTARGET, 'pico2')
FSFAMILY=data
endif

PICOTOOL=picotool

ifeq (, $(shell which picotool))
PICOTOOL=build/_deps/picotool/picotool
endif

include ../../../version.mk

Expand All @@ -12,16 +30,11 @@ build/fuzix.elf: ../../version.c build/Makefile

build/Makefile: CMakeLists.txt $(wildcard ../../*.[chS]) $(wildcard ../../*/*.[chS])
mkdir -p build
(cd build && cmake ..)
(cd build && cmake -DPICO_BOARD=${SUBTARGET} ..)

image:: world uf2conv
image:: world
./update-flash.sh
../../../Standalone/mkftl -s 1952 -e 0x1000 -g 10 filesystem.img -o filesystem.ftl
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

diskimage:

Expand Down Expand Up @@ -50,7 +63,3 @@ world: build/fuzix.elf
$(MAKE) -C ../../../Applications/cursesgames -f Makefile.armm0
$(MAKE) -C ../../../Standalone
$(MAKE) -C utils

uf2conv: tools/uf2conv.c
cc -O -g -o $@ $<

15 changes: 14 additions & 1 deletion Kernel/platform/platform-rpipico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#undef CONFIG_IDUMP
/* Enable to make ^A drop back into the monitor */
#undef CONFIG_MONITOR
/* Enable to support network stack */
#undef CONFIG_NET
#undef CONFIG_NET_NATIVE
/* Profil syscall support (not yet complete) */
#undef CONFIG_PROFIL
/* Multiple processes in memory at once */
Expand Down Expand Up @@ -68,7 +71,17 @@

#define UDATA_BLKS 3
#define UDATA_SIZE (UDATA_BLKS << BLKSHIFT)
#define USERMEM (160*1024)

#define TOTALMEM 160
#define NETMEM 0

#ifdef CONFIG_NET
#undef NETMEM
#define NETMEM 10
#endif

#define USERMEM ((TOTALMEM-NETMEM)*1024)

#define PROGSIZE (65536 - UDATA_SIZE)
extern uint8_t progbase[USERMEM];
#define udata (*(struct u_data*)progbase)
Expand Down
10 changes: 8 additions & 2 deletions Kernel/platform/platform-rpipico/devices.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "globals.h"
#include "picosdk.h"
#include <hardware/irq.h>
#include <pico/multicore.h>
#include "core1.h"

struct devsw dev_tab[] = /* The device driver switch table */
Expand All @@ -26,7 +25,7 @@ struct devsw dev_tab[] = /* The device driver switch table */
/* 3: /dev/lpr Printer devices */
{ no_open, no_close, no_rdwr, no_rdwr, no_ioctl },
/* 4: /dev/mem etc System devices (one offs) */
{ no_open, no_close, sys_read, sys_write, sys_ioctl },
{ no_open, sys_close, sys_read, sys_write, sys_ioctl },
/* Pack to 7 with nxio if adding private devices and start at 8 */
};

Expand Down Expand Up @@ -63,6 +62,10 @@ static void timer_tick_cb(unsigned alarm)
irqrestore(irq);
}

#ifdef CONFIG_NET
extern void netdev_init(void);
#endif

void device_init(void)
{
/* Timer interrup must be initialized before blcok devices.
Expand All @@ -76,6 +79,9 @@ void device_init(void)
* cause a crash on startup... oddly. */
#ifdef CONFIG_PICO_FLASH
flash_dev_init();
#endif
#ifdef CONFIG_NET
netdev_init();
#endif
sd_rawinit();
devsd_init();
Expand Down
9 changes: 7 additions & 2 deletions Kernel/platform/platform-rpipico/devsdspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@

#endif

#define SLOW_SPEED 250000
#define FAST_SPEED 4000000

void sd_rawinit(void)
{
//initilase GPIO ports
Expand All @@ -62,13 +65,15 @@ void sd_rawinit(void)
gpio_set_dir(Pico_SD_CS, true);

//initalise SPI module
spi_init(Pico_SD_SPI_MOD, 250000);

spi_init(Pico_SD_SPI_MOD, SLOW_SPEED);
spi_set_format(Pico_SD_SPI_MOD, 8, 0, 0, SPI_MSB_FIRST);
}

void sd_spi_clock(bool go_fast)
{
spi_set_baudrate(Pico_SD_SPI_MOD, 250000);
spi_set_baudrate(Pico_SD_SPI_MOD,
go_fast ? FAST_SPEED : SLOW_SPEED);
}

void sd_spi_raise_cs(void)
Expand Down
1 change: 1 addition & 0 deletions Kernel/platform/platform-rpipico/swapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static uint8_t get_slot(ptptr p)
uint8_t slot = p - ptab;
if (slot >= PTABSIZE)
panic("bad ptab");
return slot;
}

static uaddr_t get_proc_size(ptptr p)
Expand Down
73 changes: 0 additions & 73 deletions Kernel/platform/platform-rpipico/tools/uf2conv.c

This file was deleted.

77 changes: 0 additions & 77 deletions Kernel/platform/platform-rpipico/tools/uf2format.h

This file was deleted.

4 changes: 0 additions & 4 deletions Kernel/platform/platform-rpipico/update-flash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ IMG=filesystem.img

FSSIZE=2547

if [ "$1" = "sd" ]; then
FSSIZE=65535
fi

rm -f ${IMG}
../../../Standalone/mkfs ${IMG} 32 $FSSIZE
../../../Standalone/ucp ${IMG} <<EOF
Expand Down
1 change: 1 addition & 0 deletions Kernel/syscall_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#ifdef CONFIG_NET

extern void netdev_init(void);

#define N_MAKE 0x80
#define N_SOCKFD 0x40
Expand Down

0 comments on commit 9e6066d

Please sign in to comment.