Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyGrosser committed Sep 12, 2024
1 parent 1aec542 commit 707bba0
Show file tree
Hide file tree
Showing 17 changed files with 1,386 additions and 33 deletions.
2 changes: 1 addition & 1 deletion rp2040_hal.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ project Rp2040_Hal is
case Rp2040_Hal_Config.Use_Startup is
when "True" =>
for Languages use ("Ada", "Asm_Cpp");
Startup_Dirs := ("src/startup");
Startup_Dirs := ("src/startup/" & Rp2040_Hal_Config.Device);
when others => null;
end case;

Expand Down
33 changes: 29 additions & 4 deletions scripts/preprocess_boot2
Original file line number Diff line number Diff line change
@@ -1,26 +1,51 @@
#!/bin/sh

WORKDIR=$PWD
STARTUP_DIR=${WORKDIR}/../src/startup/rp2350
PICO_SDK_PATH=pico-sdk
if [ ! -e ${PICO_SDK_PATH} ]; then
git clone --branch=develop --depth=1 https://github.com/raspberrypi/pico-sdk ${PICO_SDK_PATH}
fi
cd ${PICO_SDK_PATH}/src

prep() {
prep_boot2() {
arm-none-eabi-gcc -E \
-I${WORKDIR}/include \
-Icommon/pico_base_headers/include \
-Irp2350/pico_platform/include \
-Irp2_common/pico_platform_compiler/include \
-Irp2_common/pico_platform_panic/include \
-Irp2_common/pico_platform_sections/include \
-Irp2350/pico_platform/include \
-Irp2350/hardware_regs/include \
-Irp2350/hardware_structs/include \
-Irp2350/boot_stage2/asminclude \
rp2350/boot_stage2/boot2_$1.S >${WORKDIR}/../boot2/generated/boot2__rp2350_$1.S
echo "$1"
}

prep generic_03h
prep w25q080
prep_crt0() {
if [ ! -d ${STARTUP_DIR} ]; then
mkdir -p ${STARTUP_DIR}
fi

arm-none-eabi-gcc -E \
-I${WORKDIR}/include \
-Icommon/pico_base_headers/include \
-Icommon/pico_binary_info/include \
-Icommon/boot_picobin_headers/include \
-Irp2_common/pico_platform_compiler/include \
-Irp2_common/pico_platform_panic/include \
-Irp2_common/pico_platform_sections/include \
-Irp2_common/boot_bootrom_headers/include \
-Irp2_common/pico_bootrom/include \
-Irp2350/pico_platform/include \
-Irp2350/hardware_regs/include \
-Irp2350/hardware_structs/include \
rp2_common/pico_crt0/crt0.S >${STARTUP_DIR}/crt0.S
echo "crt0"
}

prep_boot2 generic_03h
prep_boot2 w25q080

prep_crt0
55 changes: 55 additions & 0 deletions scripts/preprocess_boot2_riscv
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/sh

TRIPLE=riscv64-unknown-elf
CC=${TRIPLE}-gcc
WORKDIR=${PWD}
STARTUP_DIR=${WORKDIR}/../src/startup/rp2350
PICO_SDK_PATH=pico-sdk
if [ ! -e ${PICO_SDK_PATH} ]; then
git clone --branch=develop --depth=1 https://github.com/raspberrypi/pico-sdk ${PICO_SDK_PATH}
fi
cd ${PICO_SDK_PATH}/src

prep_boot2() {
${CC} -E \
-I${WORKDIR}/include \
-Icommon/pico_base_headers/include \
-Irp2_common/pico_platform_compiler/include \
-Irp2_common/pico_platform_panic/include \
-Irp2_common/pico_platform_sections/include \
-Irp2_common/hardware_hazard3/include \
-Irp2350/pico_platform/include \
-Irp2350/hardware_regs/include \
-Irp2350/hardware_structs/include \
-Irp2350/boot_stage2/asminclude \
rp2350/boot_stage2/boot2_$1.S >${WORKDIR}/../boot2/generated/boot2__rp2350_$1.S
echo "$1"
}

prep_crt0() {
if [ ! -d ${STARTUP_DIR} ]; then
mkdir -p ${STARTUP_DIR}
fi

${CC} -E \
-I${WORKDIR}/include \
-Icommon/pico_base_headers/include \
-Icommon/pico_binary_info/include \
-Icommon/boot_picobin_headers/include \
-Irp2_common/pico_platform_compiler/include \
-Irp2_common/pico_platform_panic/include \
-Irp2_common/pico_platform_sections/include \
-Irp2_common/boot_bootrom_headers/include \
-Irp2_common/pico_bootrom/include \
-Irp2_common/hardware_hazard3/include \
-Irp2350/pico_platform/include \
-Irp2350/hardware_regs/include \
-Irp2350/hardware_structs/include \
rp2_common/pico_crt0/crt0_riscv.S >${STARTUP_DIR}/crt0_riscv.S
echo "crt0_riscv"
}

prep_boot2 generic_03h
prep_boot2 w25q080

prep_crt0
File renamed without changes.
24 changes: 12 additions & 12 deletions src/devices/rp2350/rp-gpio.adb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
-- SPDX-License-Identifier: BSD-3-Clause
--

with RP2040_SVD.SIO; use RP2040_SVD.SIO;
with RP2350_SVD.SIO; use RP2350_SVD.SIO;
with RP.Reset;

package body RP.GPIO is
function Pin_Mask (Pin : GPIO_Pin)
return GPIO_Pin_Mask
is (GPIO_Pin_Mask (Shift_Left (UInt32 (1), GPIO_Pin'Pos (Pin))));
return UInt32
is (Shift_Left (UInt32 (1), GPIO_Pin'Pos (Pin)));

procedure Enable is
use RP.Reset;
begin
Reset_Peripheral (Reset_IO_BANK0);
Reset_Peripheral (Reset_PADS_BANK0);

-- Errata RP2040-E6
-- Errata RP2350-E6
--
-- GPIO26-29 are shared with ADC inputs AIN0-3. The GPIO digital input
-- is enabled after RUN is released. If the pins are connected to an
Expand Down Expand Up @@ -51,7 +51,7 @@ package body RP.GPIO is
Slew_Fast : Boolean := False;
Drive : GPIO_Drive := Drive_4mA)
is
Mask : constant GPIO_Pin_Mask := Pin_Mask (This.Pin);
Mask : constant UInt32 := Pin_Mask (This.Pin);
begin
if not Enabled then
Enable;
Expand Down Expand Up @@ -82,8 +82,8 @@ package body RP.GPIO is
SLEWFAST => Slew_Fast,
DRIVE => GPIO0_DRIVE_Field'Val (GPIO_Drive'Pos (Drive)),
others => <>);
SIO_Periph.GPIO_OUT_CLR.GPIO_OUT_CLR := Mask;
SIO_Periph.GPIO_OE_SET.GPIO_OE_SET := Mask;
SIO_Periph.GPIO_OUT_CLR := Mask;
SIO_Periph.GPIO_OE_SET := Mask;
when Analog =>
PADS_BANK_Periph.GPIO (This.Pin) :=
(PUE => False,
Expand All @@ -101,7 +101,7 @@ package body RP.GPIO is
function Get
(This : GPIO_Point)
return Boolean
is ((SIO_Periph.GPIO_IN.GPIO_IN and Pin_Mask (This.Pin)) /= 0);
is ((SIO_Periph.GPIO_IN and Pin_Mask (This.Pin)) /= 0);

procedure Enable_Interrupt
(This : in out GPIO_Point;
Expand Down Expand Up @@ -224,30 +224,30 @@ package body RP.GPIO is
function Set
(This : GPIO_Point)
return Boolean
is ((SIO_Periph.GPIO_IN.GPIO_IN and Pin_Mask (This.Pin)) /= 0);
is ((SIO_Periph.GPIO_IN and Pin_Mask (This.Pin)) /= 0);

overriding
procedure Set
(This : in out GPIO_Point)
is
begin
SIO_Periph.GPIO_OUT_SET.GPIO_OUT_SET := Pin_Mask (This.Pin);
SIO_Periph.GPIO_OUT_SET := Pin_Mask (This.Pin);
end Set;

overriding
procedure Clear
(This : in out GPIO_Point)
is
begin
SIO_Periph.GPIO_OUT_CLR.GPIO_OUT_CLR := Pin_Mask (This.Pin);
SIO_Periph.GPIO_OUT_CLR := Pin_Mask (This.Pin);
end Clear;

overriding
procedure Toggle
(This : in out GPIO_Point)
is
begin
SIO_Periph.GPIO_OUT_XOR.GPIO_OUT_XOR := Pin_Mask (This.Pin);
SIO_Periph.GPIO_OUT_XOR := Pin_Mask (This.Pin);
end Toggle;

end RP.GPIO;
5 changes: 0 additions & 5 deletions src/devices/rp2350/rp-gpio.ads
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ private

GPIO_Enabled : Boolean := False;

subtype GPIO_Pin_Mask is UInt30;

function Pin_Mask (Pin : GPIO_Pin)
return GPIO_Pin_Mask;

type GPIO_CTRL_Register is record
FUNCSEL : GPIO_Function := HI_Z;
OUTOVER : GPIO0_CTRL_OUTOVER_Field := NORMAL;
Expand Down
16 changes: 10 additions & 6 deletions src/devices/rp2350/rp-reset.adb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
--
-- SPDX-License-Identifier: BSD-3-Clause
--
with RP2040_SVD;
with RP2350_SVD;
with RP.Timer;

package body RP.Reset is

type RESET_Register is array (Reset_Id) of Boolean
with Component_Size => 1,
with Volatile_Full_Access,
Effective_Writes,
Async_Readers,
Async_Writers,
Component_Size => 1,
Size => 32;

type RESETS_Peripheral is record
RESET : aliased RESET_Register;
WDSEL : aliased RESET_Register;
RESET_DONE : aliased RESET_Register;
RESET : RESET_Register;
WDSEL : RESET_Register;
RESET_DONE : RESET_Register;
end record
with Volatile;

Expand All @@ -26,7 +30,7 @@ package body RP.Reset is
end record;

RESETS_Periph : aliased RESETS_Peripheral
with Import, Address => RP2040_SVD.RESETS_Base;
with Import, Address => RP2350_SVD.RESETS_Base;

procedure Reset_Peripheral
(Peripheral : Reset_Id)
Expand Down
2 changes: 1 addition & 1 deletion src/devices/rp2350/rp-reset.ads
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ is
Reset_I2C0,
Reset_I2C1,
Reset_IO_BANK0,
Reset_QSPI,
Reset_IO_QSPI,
Reset_JTAG,
Reset_PADS_BANK0,
Reset_PADS_QSPI,
Expand Down
70 changes: 70 additions & 0 deletions src/devices/rp2350/rp-timer.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
--
-- Copyright 2021 (C) Jeremy Grosser
--
-- SPDX-License-Identifier: BSD-3-Clause
--
with RP2350_SVD.TIMER0; use RP2350_SVD.TIMER0;

package body RP.Timer is
function Clock
return Time
is
-- This implementation uses the non-latching TIMERAWH and TIMERAWL
-- registers in order to be safe for concurrent access.
Next_High : UInt32;
High : UInt32;
Low : UInt32;
begin
High := TIMER0_Periph.TIMERAWH;
Low := TIMER0_Periph.TIMERAWL;
Next_High := TIMER0_Periph.TIMERAWH;

if Next_High /= High then
-- If TIMERAWH changed while we were reading TIMERAWL it means that at
-- some point between the two reads TIMERAWL overflowed and the values
-- where:
-- - TIMERAWL = 0
-- - TIMERAWH = Next_High
--
-- These values denote a valid point in time between the call and the
-- return of this function.

Low := 0;
High := Next_High;
end if;

return Time (Shift_Left (UInt64 (High), 32) or UInt64 (Low));
end Clock;

procedure Busy_Wait_Until (Deadline : Time) is
DL_High : constant UInt32 :=
UInt32 (Shift_Right (Deadline, 32) and 16#FF_FF_FF_FF#);
DL_Low : constant UInt32 :=
UInt32 (Deadline and 16#FF_FF_FF_FF#);

High : UInt32 := TIMER0_Periph.TIMERAWH;
begin
loop
High := TIMER0_Periph.TIMERAWH;
exit when High >= DL_High;
end loop;

while High = DL_High and then TIMER0_Periph.TIMERAWL < DL_Low loop
High := TIMER0_Periph.TIMERAWH;
end loop;

end Busy_Wait_Until;

function Milliseconds
(T : Natural)
return Time
is ((Ticks_Per_Second / 1_000) * Time (T));

procedure Set_Debug_Pause
(Core_0, Core_1 : Boolean)
is
begin
TIMER0_Periph.DBGPAUSE.DBG := (As_Array => True, Arr => (0 => Core_0, 1 => Core_1));
end Set_Debug_Pause;

end RP.Timer;
File renamed without changes.
Loading

0 comments on commit 707bba0

Please sign in to comment.