raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.64k stars 903 forks source link

Please add support for Keil #877

Open myjtag opened 2 years ago

myjtag commented 2 years ago

Hi, Since we have lots of libraries and code on ARM Keil tools, it would be very helpful if you could add support for it.

GorgonMeducer commented 3 months ago

@bgolab Can you attach the linker script also? The reason I ask this is because, the map file looks strange. I know you suppose to use the linker script I provided, but just in case, please send me the one you actually uses

Memory Map of the image

  Image Entry point : 0x200000c1

  Load Region LR_IROM1 (Base: 0x20000000, Size: 0x000052e0, Max: 0x0003e000, ABSOLUTE)

    Execution Region ER_BINRAY_INFO (Exec base: 0x20000000, Load base: 0x20000000, Size: 0x00000000, Max: 0xffffffff, ABSOLUTE)

    **** No section assigned to this execution region ****

    Execution Region ER_FLASH (Exec base: 0x20000000, Load base: 0x20000000, Size: 0x00000900, Max: 0xffffffff, ABSOLUTE)

    Exec Addr    Load Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x20000000   0x20000000   0x000000c0   Data   RO          709    RESET               lto-llvm-5f2a3e.o
    0x200000c0   0x200000c0   0x00000008   Code   RO          220  * !!!main             c_p.l(__main.o)
    0x200000c8   0x200000c8   0x00000054   Code   RO          729    !!!scatter          c_p.l(__scatter.o)
    0x2000011c   0x2000011c   0x0000001a   Code   RO          733    !!handler_copy      c_p.l(__scatter_copy.o)

This is the one on myside:

Memory Map of the image

  Image Entry point : 0x20000001

  Load Region LR_IROM1 (Base: 0x20000000, Size: 0x00005430, Max: 0x0003e000, ABSOLUTE)

    Execution Region ER_BINRAY_INFO (Exec base: 0x20000000, Load base: 0x20000000, Size: 0x0000002c, Max: 0xffffffff, ABSOLUTE)

    Exec Addr    Load Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x20000000   0x20000000   0x0000002c   Code   RO          751  * .text.Reset_Handler  lto-llvm-483d6d.o

    Execution Region ER_RAM_VECTOR_TABLE (Exec base: 0x20000100, Load base: 0x20000100, Size: 0x00000000, Max: 0xffffffff, ABSOLUTE)

    **** No section assigned to this execution region ****

    Execution Region ER_FLASH (Exec base: 0x20000100, Load base: 0x20000100, Size: 0x00000858, Max: 0xffffffff, ABSOLUTE)

    Exec Addr    Load Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x20000100   0x20000100   0x000000c0   Data   RO          795    RESET               lto-llvm-483d6d.o
    0x200001c0   0x200001c0   0x00000008   Code   RO          268  * !!!main             c_p.l(__main.o)
    0x200001c8   0x200001c8   0x00000054   Code   RO          834    !!!scatter          c_p.l(__scatter.o)
    0x2000021c   0x2000021c   0x0000001a   Code   RO          838    !!handler_copy      c_p.l(__scatter_copy.o)

You might notice that the key difference is the Reset_Handler is placed at the start of the 0x20000000

    Exec Addr    Load Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x20000000   0x20000000   0x0000002c   Code   RO          751  * .text.Reset_Handler  lto-llvm-483d6d.o

This is the key difference.

image

In your map file, I found this:

Reset_Handler                            0x200031e9   Thumb Code    24  lto-llvm-5f2a3e.o(.text.Reset_Handler)

This is the location of Reset_Handler in my map file:

Reset_Handler                            0x20000001   Thumb Code    24  lto-llvm-483d6d.o(.text.Reset_Handler)

Based on this, I really want to check the linker script you actually use.

bgolab commented 3 months ago

Current settings of the Linker tab and latest / freshest file (BTW. I have not touched the content of the linker file): image

RP2040_debug_in_sra [rp2040_example.map.txt](https://github.com/raspberrypi/pico-sdk/files/15417666/rp2040_example.map.txt) m.sct.txt

GorgonMeducer commented 3 months ago

@bgolab You are not using the latest RP2040_debug_in_sram.sct

Please use the latest one.

https://github.com/GorgonMeducer/Pico_Template/blob/main/project/mdk/RP2040_debug_in_sram.sct

It is different from the one you currently using.

Thank you.

This is the one you using:

image

This is the latest one:

image

bgolab commented 3 months ago

I lost control of this. This time should be ok:

Program Size: Code=18804 RO-data=2152 RW-data=260 ZI-data=41148
After Build - User command #2: C:/Users/abg015/AppData/Local/Arm/Packs/RaspberryPi/RP2xxx_DFP/0.9.4/tools\elf2uf2.exe "C:\Users\abg015\Documents\Keil\test1-sram\Objects\rp2040_example.axf" ".\rp2040_example.uf2" ERROR: A RAM binary should have an entry point at the beginning: 20000001 (not 20000181) ".\Objects\rp2040_example.axf" - 0 Error(s), 0 Warning(s).

RP2040_debug_in_sram.sct.txt

bgolab commented 3 months ago

rp2040_example.map (2).txt

GorgonMeducer commented 3 months ago

@bgolab I managed to replicate the same issue on myside, please add --entry=Reset_Handler to the Misc Controls in the linker tab as shown below:

image

Without this option:

Memory Map of the image

  Image Entry point : 0x200000c1

  Load Region LR_IROM1 (Base: 0x20000000, Size: 0x00005358, Max: 0x0003e000, ABSOLUTE)

    Execution Region ER_BINRAY_INFO (Exec base: 0x20000000, Load base: 0x20000000, Size: 0x00000000, Max: 0xffffffff, ABSOLUTE)

    **** No section assigned to this execution region ****

    Execution Region ER_RAM_VECTOR_TABLE (Exec base: 0x20000000, Load base: 0x20000000, Size: 0x00000000, Max: 0xffffffff, ABSOLUTE)

    **** No section assigned to this execution region ****

    Execution Region ER_FLASH (Exec base: 0x20000000, Load base: 0x20000000, Size: 0x00000858, Max: 0xffffffff, ABSOLUTE)

    Exec Addr    Load Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x20000000   0x20000000   0x000000c0   Data   RO          795    RESET               lto-llvm-f71e40.o
    0x200000c0   0x200000c0   0x00000008   Code   RO          268  * !!!main             c_p.l(__main.o)
    0x200000c8   0x200000c8   0x00000054   Code   RO          834    !!!scatter          c_p.l(__scatter.o)
    0x2000011c   0x2000011c   0x0000001a   Code   RO          838    !!handler_copy      c_p.l(__scatter_copy.o)
    0x20000136   0x20000136   0x00000002   PAD
    0x20000138   0x20000138   0x00000002   Code   RO          835    !!handler_null      c_p.l(__scatter.o)
    0x2000013a   0x2000013a   0x00000002   PAD
    0x2000013c   0x2000013c   0x0000001c   Code   RO          840    !!handler_zi        c_p.l(__scatter_zi.o)

With this option:

Memory Map of the image

  Image Entry point : 0x20000001

  Load Region LR_IROM1 (Base: 0x20000000, Size: 0x00005430, Max: 0x0003e000, ABSOLUTE)

    Execution Region ER_BINRAY_INFO (Exec base: 0x20000000, Load base: 0x20000000, Size: 0x0000002c, Max: 0xffffffff, ABSOLUTE)

    Exec Addr    Load Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x20000000   0x20000000   0x0000002c   Code   RO          751  * .text.Reset_Handler  lto-llvm-ed53d8.o

    Execution Region ER_RAM_VECTOR_TABLE (Exec base: 0x20000100, Load base: 0x20000100, Size: 0x00000000, Max: 0xffffffff, ABSOLUTE)

    **** No section assigned to this execution region ****

    Execution Region ER_FLASH (Exec base: 0x20000100, Load base: 0x20000100, Size: 0x00000858, Max: 0xffffffff, ABSOLUTE)

    Exec Addr    Load Addr    Size         Type   Attr      Idx    E Section Name        Object

    0x20000100   0x20000100   0x000000c0   Data   RO          795    RESET               lto-llvm-ed53d8.o
    0x200001c0   0x200001c0   0x00000008   Code   RO          268  * !!!main             c_p.l(__main.o)
    0x200001c8   0x200001c8   0x00000054   Code   RO          834    !!!scatter          c_p.l(__scatter.o)
    0x2000021c   0x2000021c   0x0000001a   Code   RO          838    !!handler_copy      c_p.l(__scatter_copy.o)
    0x20000236   0x20000236   0x00000002   PAD
    0x20000238   0x20000238   0x00000002   Code   RO          835    !!handler_null      c_p.l(__scatter.o)
    0x2000023a   0x2000023a   0x00000002   PAD
bgolab commented 3 months ago

Yes, the '--entry=Reset_Handler' magic setting helped. It looks like not everything is controlled by the sct.

The old-way of controlling linker settings in such simple scenario like this (just moving the code region to SRAM area) wasn't so bad;)

Thank you.

bgolab commented 3 months ago

UF2 verified by my script that the code is located in SRAM: rp2040_example.uf2.log

GorgonMeducer commented 3 months ago

@bgolab You mixed different things up.

The old-way of controlling linker settings in such simple scenario like this (just moving the code region to SRAM area) wasn't so bad;)

The Old way won't help.

This is because RP2040 BOOTROM only wants the Reset_Handler to be located at a specific location. This is different from STM32, which always read Reset_handler address from the vector table (RESET section in our case).

The so called old way or new way only affects how the STACK and HEAP are configured.

bgolab commented 3 months ago

Yes, I see. Got used to STM32;)

GorgonMeducer commented 3 months ago

Current solution, i.e. using --entry=Reset_Handler is just a workaround. PRi team needs a more elegant way to place Reset_Handler at 0x2000-0000

bgolab commented 3 months ago

It looks like the RP2 is not officially supported yet: https://www.keil.com/dd/

GorgonMeducer commented 3 months ago

@bgolab It is the legacy list... Please check here: https://www.keil.arm.com/packs/rp2xxx_dfp-raspberrypi/boards/