Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RP2350 support #24187

Open
vidma opened this issue Jan 8, 2025 · 4 comments
Open

RP2350 support #24187

vidma opened this issue Jan 8, 2025 · 4 comments

Comments

@vidma
Copy link

vidma commented Jan 8, 2025

Describe problem solved by the proposed feature

Raspberry Pico 2 seem to be very good/performant, popular, simple (need very few external PCB components) and cheap CPU

Describe your preferred solution

  • upgrade NuttX (or backport - started backporting from unreleased master branch)
  • current state:
    • NuttX backported on top of current 10.3.2+ PX4/NuttX branch
    • compiles
    • linking kinda works, get uf2
    • still need to debug why it does not boot

Describe possible alternatives

  • wait for NuttX release and do full NuttX upgrade/backporting?

Additional context

  • currently testing on Raspberry Pico 2 W (RP2350 A2, 4MB flash, no PSRAM)

continuation of #18083

@vidma
Copy link
Author

vidma commented Jan 17, 2025

P.S. seems PX4 is booting up already, but still need to debug more what's happening there (no USB serial/mavlink yet):
will make a WIP PR once I get it slightly more functional.


Image

https://blog.flyuav.lt/raspberry-pico-2-a-cheap-flight-controller/

@akhodeir
Copy link

I am crossing my fingers till you finish 👍
Good job

@vidma
Copy link
Author

vidma commented Jan 17, 2025

btw, meanwhile, I'm listing a few less clear points - @akhodeir do you or someone else have any clue about these (preliminarily it seems it kinda works when SMP disabled):

  • SMP/IRQ: g_current_regs[CONFIG_SMP_NCPUS] / CURRENT_REGS . what are these? and how is it supposed to be defined in case SMP is enabled vs disabled?
  • Linker scripts: any LD script pecularities special to PX4? in memory_map.ld or also called script.ld/flash.ld . w/o SMP, seem to work I guess
  • gdb and stuff for PX4: I still need to setup some better debugging env, then this damn USB serial / mavlink / nsh doesn't seem to be possible to connect to. gdb is doing its work, but it would be very nice to see the PX4 log messages somehow when USB serial do not work. any clues? e.g. maybe we have some existing helper which would redirect PX4/Nuttx log messages to gdb ?
  • shall we use FAR annotation or not ? this was changed in some recent non-PX4 Nuttx commit.

for now, I probably, temporarily, hacked it like that (will need further fixes/cleanup I guess):

IRQ/SMP/CURRENT_REGS

diff --git a/arch/arm/src/rp23xx/rp23xx_irq.c b/arch/arm/src/rp23xx/rp23xx_irq.c
index a3baff0d6c..e8a66ede85 100644
--- a/arch/arm/src/rp23xx/rp23xx_irq.c
+++ b/arch/arm/src/rp23xx/rp23xx_irq.c
+#ifndef CONFIG_SMP
+// FIXME nasty hack: make it compile if CONFIG_SMP is disabled
+// FIXME: in case SMP disabled, what should be the value here? {0}?
+volatile uint32_t *g_current_regs[CONFIG_SMP_NCPUS] = {0};
+#endif
+
 #if defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7
 /* In the SMP configuration, we will need custom interrupt stacks.
  * These definitions provide the aligned stack allocations.
@@ -76,6 +81,12 @@ const uint32_t g_cpu_intstack_top[CONFIG_SMP_NCPUS] =
 };
 #endif /* defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7 */

+/* This is the address of the  exception vector table (determined by the
+ * linker script).
+ */
+
+extern uint32_t _vectors[];
+
diff --git a/arch/arm/include/irq.h b/arch/arm/include/irq.h
index 1fac0e1e55..2508a36b15 100644
--- a/arch/arm/include/irq.h
+++ b/arch/arm/include/irq.h
@@ -89,10 +89,16 @@ extern "C"
 /* For the case of architectures with multiple CPUs, then there must be one
  * such value for each processor that can receive an interrupt.
  */
-
+//#ifdef CONFIG_SMP
 EXTERN volatile uint32_t *g_current_regs[CONFIG_SMP_NCPUS];
 #define CURRENT_REGS (g_current_regs[up_cpu_index()])

+//#else
+// FIXME: when CONFIG_SMP not defined, I commented/disabled these lines out, as:
+// up_cpu_index() macro was conflicting with up_cpu_index() in nuttx/arch/arm/src/rp23xx/rp23xx_cpuindex.c
+//and maybe something g_current_regs defined /arch/arm/src/rp23xx/rp23xx_irq.c
+//volatile FAR uint32_t **g_current_regs;
+//#define CURRENT_REGS (g_current_regs[up_cpu_index()])
+//#endif
+
 /****************************************************************************
  * Public Function Prototypes
  ****************************************************************************/
@@ -116,7 +122,8 @@ EXTERN volatile uint32_t *g_current_regs[CONFIG_SMP_NCPUS];
 #ifdef CONFIG_SMP
 int up_cpu_index(void);
 #else
-#  define up_cpu_index() (0)
+int up_cpu_index(void);
+//  define up_cpu_index() (0)
 #endif

LD / Linker script:

+++ b/arch/arm/src/rp23xx/rp23xx_cpuindex.c
@@ -30,11 +30,9 @@
 #include "hardware/rp23xx_sio.h"

 #ifdef CONFIG_ARCH_HAVE_MULTICPU
...

int up_cpu_index(void)
{
  return getreg32(RP23XX_SIO_CPUID);
}

+// !!! NOTE/FIXE: this looks fishy because:
+//  - ifdef CONFIG_ARCH_HAVE_MULTICPU 
+//  - and closing  comment mentions CONFIG_SMP
#endif /* CONFIG_SMP */

Linkerscript: memory_map.ld or also called script.ld/flash.ld:

...

MEMORY
{
    FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 4096k
    RAM(rwx) : ORIGIN =  0x20000000, LENGTH = 512k
    SCRATCH_X(rwx) : ORIGIN = 0x20080000, LENGTH = 4k
    SCRATCH_Y(rwx) : ORIGIN = 0x20081000, LENGTH = 4k
}

+/* added EXTERN */
+EXTERN(_vectors)
ENTRY(_stext)
+/* where is _entry_point defined in ? what's the difference from  _stext? */
-/*ENTRY(_entry_point)*/
+/*EXTERN(bootStr)*/


SECTIONS
{
    .flash_begin : {
        __flash_binary_start = .;
    } > FLASH

    ...

    .text : {
        __logical_binary_start = .;
        _stext = ABSOLUTE(.);

        KEEP (*(.vectors))

        LONG(0xffffded3)
        LONG(0x10210142)
        LONG(0x000001ff)
        LONG(0x00000000)
        LONG(0xab123579)

        KEEP (*(.binary_info_header))

        ...

        . = ALIGN(4);
        /* init data */
+        /* vidma: added _sinit */
+        _sinit = ABSOLUTE(.);
        PROVIDE_HIDDEN (__init_array_start = .);
        KEEP(*(SORT(.init_array.*)))
        KEEP(*(.init_array))
        PROVIDE_HIDDEN (__init_array_end = .);
+        /* vidma: added _einit */
+        _einit = ABSOLUTE(.);

        ...

    } > FLASH

   ...

@akhodeir
Copy link

those are really advanced questions.

I advise you to ask here : https://forums.raspberrypi.com/viewforum.php?f=143&sid=291ab055d458508bb26aadeb341f19da
The forum is really helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants