[DEV] RP2040 support

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
hanya
Posts: 7
Joined: Mon Aug 09, 2021 2:14 pm
Been thanked: 3 times

Re: [DEV] RP2040 support

Post by hanya »

I tried to link boot_double_tap_check function from pico-sdk which allow us to enter bootloader by double push the reset button.
The function has __attribute__((constructor)) attribute, so it called before main function.
In the case of pico-sdk based program, runtime_init function is called before main function is called to set up some state including clocks.
But in the case of ChibiOS based program, clocks are set up in halInit function called in main function.
As a result, boot_double_tap_check function can not work with ChibiOS startup program.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: [DEV] RP2040 support

Post by Giovanni »

hanya wrote:Please add structure definition for PWM register.

Code: Select all

diff --git a/os/common/ext/RP/RP2040/rp2040.h b/os/common/ext/RP/RP2040/rp2040.h
index 01c911d..7423d88 100644
--- a/os/common/ext/RP/RP2040/rp2040.h
+++ b/os/common/ext/RP/RP2040/rp2040.h
@@ -896,6 +896,67 @@ struct {
   } CLR;
 } ADC_TypeDef;


Hi,

Forgot about this, committed.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: [DEV] RP2040 support

Post by Giovanni »

hanya wrote:I tried to link boot_double_tap_check function from pico-sdk which allow us to enter bootloader by double push the reset button.
The function has __attribute__((constructor)) attribute, so it called before main function.
In the case of pico-sdk based program, runtime_init function is called before main function is called to set up some state including clocks.
But in the case of ChibiOS based program, clocks are set up in halInit function called in main function.
As a result, boot_double_tap_check function can not work with ChibiOS startup program.


I expect many more incompatibilities with the SDK, please feel free to make suggestions on the various topics.

Giovanni
electronic_eel
Posts: 95
Joined: Sat Mar 19, 2016 8:07 pm
Has thanked: 8 times
Been thanked: 23 times

Re: [DEV] RP2040 support

Post by electronic_eel »

Just to keep the RP2040 related posts in this thread:

I have created patches to build the stage2 bootloader into ChibiOS. This allows to boot from flash.
I posted the patches here.
LordsBoards
Posts: 1
Joined: Tue Feb 22, 2022 5:34 am

Re: [DEV] RP2040 support

Post by LordsBoards »

electronic_eel wrote:Just to keep the RP2040 related posts in this thread:

I have created patches to build the stage2 bootloader into ChibiOS. This allows to boot from flash.
I posted the patches here.


I would like to confirm that the demo program supplied compiled successfully and worked on my RP2040.
electronic_eel
Posts: 95
Joined: Sat Mar 19, 2016 8:07 pm
Has thanked: 8 times
Been thanked: 23 times

Re: [DEV] RP2040 support

Post by electronic_eel »

The Raspberry Pi foundation released the pico-sdk 1.3.0 version some time ago.

Updating the pico-sdk in ChibiOS worked without issues, I just had to update the files in the "ext" directory and the version file in "/os/various/pico_bindings/dumb/include/pico/version.h".

In the release notes they mention that the pico-sdk now contains CMSIS headers. Unfortunately they just have included CMSIS-core, meaning just the IRQ definitions, SystemCoreClock and very basic defines like "__CM0PLUS_REV". What is not included are the register and address definitions for all the peripheral functions. They still have those just defined in their own scheme and don't provide them in a CMSIS compatible way. So the custom file "/os/common/ext/RP/RP2040/rp2040.h" can't be replaced with a upstream version.
miranb
Posts: 2
Joined: Sun Nov 06, 2022 3:52 pm
Been thanked: 2 times

Re: [DEV] RP2040 support

Post by miranb »

Hi,

I noticed that the RP2040 PAL driver does not support events so I extended the LL driver to support line events. There are 2 configuration options:
1. RP_PAL_EVENT_CORE_AFFINITY (default 0) - core that handles the interrupts
2. RP_IO_IRQ_BANK0_PRIORITY (default 2) - priority of the interrupt handler

Since the Git repository is RO, I am attaching the two files here.
Attachments
hal_pal_lld.zip
(5.57 KiB) Downloaded 573 times
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: [DEV] RP2040 support

Post by Giovanni »

Hi Thanks,

I will handle that, feel free to join our discord server for code contributions, the link is in the standing post.

Giovanni
miranb
Posts: 2
Joined: Sun Nov 06, 2022 3:52 pm
Been thanked: 2 times

Re: [DEV] RP2040 support

Post by miranb »

Hi,

I just realized that there is a bug in the IRQ handler that suppresses callbacks/events for line # > 7. Here is a diff of the fix:

--- a/hal_pal_lld.c
+++ b/hal_pal_lld.c
@@ -62,11 +62,10 @@ palevent_t _pal_events[30];
OSAL_IRQ_HANDLER(RP_IO_IRQ_BANK0_HANDLER) {
OSAL_IRQ_PROLOGUE();

- int line = 0;
-
for(int i=0; i < 4; ++i) {
uint32_t ints = IO_BANK0->PROC[RP_PAL_EVENT_CORE_AFFINITY].INTS[i];
IO_BANK0->INTR[i] = ints;
+ int line = i*8;
while(ints) {
if (ints & 0x0FU)
_pal_isr_code(line);

BR
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: [DEV] RP2040 support

Post by Giovanni »

Hi miranb,

Change committed on trunk.

Giovanni
Post Reply