[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.
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: [DEV] RP2040 support

Post by alex31 »

Hi,

Thanks for the answer, nice to know it's possible to do it,
can you point me any link to example for gcc ?

When you speak of scatter file, you means gcc linker script, or is it another file ?

ps: if this ITCM thread question grows, perhaps one must move it outside RP2040 thread.

Alexandre
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 »

Giovanni wrote:You need to create a custom scatter file, you can place things where you want.

To my knowledge, scatter files are used by the ARM compilers (armcc and armclang) and Keil. They are the equivalent to GCC linker scripts and serve the same purpose, just have a different syntax. GCC doesn't support these scatter files, you have to use linker scripts when you are using gcc and gnu ld.

Both, scatter files and linker scripts, allow you to place code in different parts of the memory. But they both rely on section names in the code to do this. So you have to add section attributes to the code to be able to place different parts of the code into different sections.

So to my knowledge scatter files and linker scripts are one part of the puzzle for support of loading code into RAM or ITCM. The other part is how and where to assign the section attributes to the functions.

Or am I misunderstanding something there?
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 »

Scatter files are a synonym of linker scripts.

GCC assigns each function a separate section name, you can allocate those section names freely. You may leverage the common prefix "ch" of function names also.

Giovanni
szilveszter
Posts: 12
Joined: Mon Jun 14, 2021 5:42 pm
Has thanked: 9 times
Been thanked: 5 times

Re: [DEV] RP2040 support

Post by szilveszter »

Hi,

From looking at your linker script it looks like you put the whole executable code into the flash and execute it directly from there (XIP). Is this correct?

As I know it is right, the code is executed directly from the FLASH (XIP), but be aware my knowledge in this area is pretty limited. At this stage it wasn't a priority to copy things over to the RAM anyway, I focused on getting the Pico to boot from flash. There is a memmap_copy_to_ram.ld linker script in the PICO SDK which theoretically does what you want to achieve. The .data and .text sections are copied from flash to ram by marking the flash as the load memory address (LMA) and the RAM as the virtual memory address(VMA), but I don't know what does copy over the marked sections at runtime.

Szilveszter
szilveszter
Posts: 12
Joined: Mon Jun 14, 2021 5:42 pm
Has thanked: 9 times
Been thanked: 5 times

Re: [DEV] RP2040 support

Post by szilveszter »

Hi again,

This time I want to ask Giovanni or other ChibiOS experts, that what are the consequences if I remove the ALIGN(1024) from the line 21 in os/common/startup/ARMCMx/compilers/GCC/ld/rules_code.ld.

Code: Select all

SECTIONS
{
    .vectors : ALIGN(1024)
    {
        KEEP(*(.vectors))
    } > VECTORS_FLASH AT > VECTORS_FLASH_LMA
   


Regards,
Szilveszter
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 »

Vectors need to be aligned, the system would crash otherwise.

Giovanni
hanya
Posts: 7
Joined: Mon Aug 09, 2021 2:14 pm
Been thanked: 3 times

Re: [DEV] RP2040 support

Post by hanya »

Some base addresses are wrong defined in rp2040.h file.

Code: Select all

#define __USB_BASE                        (__AHBPERIPH_BASE + 0x01100000U)
#define __PIO0_BASE                       (__AHBPERIPH_BASE + 0x02000000U)
#define __PIO1_BASE                       (__AHBPERIPH_BASE + 0x03000000U)

USB is 0x50110000, PIOs are 0x50200000 and 0x50300000. Another zero is added to these addresses.
User avatar
FXCoder
Posts: 403
Joined: Sun Jun 12, 2016 4:10 am
Has thanked: 188 times
Been thanked: 134 times

Re: [DEV] RP2040 support

Post by FXCoder »

Fixed in trunk.
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 write USB low level but it did not work well. The code is here: https://github.com/hanya/ChibiOS-Contri ... 558d3d7419
USB driver: https://github.com/hanya/ChibiOS-Contri ... LLD/USBDv1
Test code: https://github.com/hanya/ChibiOS-Contri ... 0-PICO-HID

It looks the device can respond to GET_DESCRIPTOR request. But the state does not proceed from SET_ADDRESS state.
The address received from the host is set to USB->DEVADDRCTRL register in usb_lld_set_address function.
But after that, anothre or more set address request is received from the host. So it seems somthings wrong in the response.
I have no enough knowledge to fix this problem.

Here is the result when I run the code, this output is came from UART by the picoprobe for debugging.

Code: Select all

-- Started in c1
1, setup
2, copy setup data, setup data is following 8 bytes
0x1000680, GET_DESCRIPTOR, device descriptor, device to host
0x400000, length up to 64
4, start_in
7, endpoint done
1
2
0x1000680
0x400000
4
7
1
2
0x160500, SET_ADDRESS, address 0x16, host to device
0x0, always zero
3, set_address from data
1
2
0x1000680
0x400000
4
7
1
2
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 »

If I remember well there was an option in the USB HLD about 2 possible modes of handling SET ADDRESS, you should look into that and decide which one matches this device.

Edit: search for USB_SET_ADDRESS_MODE in hal_usb.c.

Giovanni
Post Reply