PicoCPP / RPI-pico-FreeRTOS

HomePage
112 stars 17 forks source link

Cannot build #2

Closed bengtb closed 3 years ago

bengtb commented 3 years ago

I cloned this repo and did a git submodule update --init --recursive in the newly created directory.

After creating a build directory and running cmake -S . -B build I change directory to the build directory.

When building using make I get these errors:

...
[ 11%] Built target ELF2UF2Build
[ 12%] Building C object CMakeFiles/FreeRTOS.dir/FreeRTOS-Kernel/portable/GCC/ARM_CM0/port.c.obj
/var/folders/xn/phhzddzj1tj1j8zyn3tbbj500000gn/T//ccB15ulA.s: Assembler messages:
/var/folders/xn/phhzddzj1tj1j8zyn3tbbj500000gn/T//ccB15ulA.s:69: Error: cannot honor width suffix -- `mov r4,#128'
/var/folders/xn/phhzddzj1tj1j8zyn3tbbj500000gn/T//ccB15ulA.s:70: Error: lo register required -- `sub r3,r0,#4'
/var/folders/xn/phhzddzj1tj1j8zyn3tbbj500000gn/T//ccB15ulA.s:71: Error: cannot honor width suffix -- `lsl r4,r4,#17'
/var/folders/xn/phhzddzj1tj1j8zyn3tbbj500000gn/T//ccB15ulA.s:73: Error: lo register required -- `sub r3,r3,#4'
/var/folders/xn/phhzddzj1tj1j8zyn3tbbj500000gn/T//ccB15ulA.s:76: Error: lo register required -- `sub r3,r3,#4'
/var/folders/xn/phhzddzj1tj1j8zyn3tbbj500000gn/T//ccB15ulA.s:78: Error: lo register required -- `sub r3,r3,#20'
/var/folders/xn/phhzddzj1tj1j8zyn3tbbj500000gn/T//ccB15ulA.s:79: Error: lo register required -- `sub r0,r0,#64'
/var/folders/xn/phhzddzj1tj1j8zyn3tbbj500000gn/T//ccB15ulA.s:112: Error: cannot honor width suffix -- `mov r2,#128'
...

What did I do wrong?

PicoCPP commented 3 years ago

That's a classical compiling arm cortex m code with a desktop compiler error message I think.

Have you installed arm-none-eabi-gcc? Can you manually specify the compiler for cmake on the command line?

Raspberry pi Foundation have a pdf for getting started with development that lists the toolchain instructions which might be handy to follow.

There are also some toolchain files in the Pico SDK somewhere that you could try loading use -DCMAKE_TOOLCHAIN_FILE

bengtb commented 3 years ago

arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 227977]

I'll try doing this on my Raspberry Pi 4 instead of my Mac that has much more software installed. I'll be back.

bengtb commented 3 years ago

On the Raspberry Pi 4 it built without a problem. Though it will not blink. Does this look OK:

$ arm-none-eabi-gcc --version arm-none-eabi-gcc (15:7-2018-q2-6) 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907] Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ arm-none-eabi-size hello_world.elf text data bss dec hex filename 25228 24 52572 77824 13000 hello_world.elf $ arm-none-eabi-objdump -h hello_world.elf

hello_world.elf: file format elf32-littlearm

Sections: Idx Name Size VMA LMA File off Algn 0 .boot2 00000100 10000000 10000000 00010000 20 CONTENTS, ALLOC, LOAD, READONLY, DATA 1 .text 00005710 10000100 10000100 00010100 24 CONTENTS, ALLOC, LOAD, READONLY, CODE 2 .rodata 000000d4 10005810 10005810 00015810 22 CONTENTS, ALLOC, LOAD, READONLY, DATA 3 .binary_info 00000018 100058e4 100058e4 000158e4 22 CONTENTS, ALLOC, LOAD, DATA 4 .ram_vector_table 000000c0 20000000 20000000 00020a68 22 CONTENTS 5 .data 000009a8 200000c0 100058fc 000200c0 24 CONTENTS, ALLOC, LOAD, CODE 6 .uninitialized_data 00000000 20000a68 20000a68 00020b28 20 CONTENTS 7 .scratch_x 00000000 20040000 20040000 00020b28 20 CONTENTS 8 .scratch_y 00000000 20041000 20041000 00020b28 20 CONTENTS 9 .bss 0000cd5c 20000a68 20000a68 00020a68 22 ALLOC 10 .heap 00000800 2000d7c4 2000d7c4 00020b28 22 CONTENTS, READONLY 11 .stack_dummy 00000800 20041000 20041000 00021340 25 CONTENTS, READONLY 12 .ARM.attributes 00000028 00000000 00000000 00021b40 20 CONTENTS, READONLY 13 .comment 000000ae 00000000 00000000 00021b68 20 CONTENTS, READONLY 14 .debug_line 00000ef4 00000000 00000000 00021c16 20 CONTENTS, READONLY, DEBUGGING 15 .debug_info 000065f9 00000000 00000000 00022b0a 20 CONTENTS, READONLY, DEBUGGING 16 .debug_abbrev 0000151f 00000000 00000000 00029103 20 CONTENTS, READONLY, DEBUGGING 17 .debug_aranges 00000158 00000000 00000000 0002a628 23 CONTENTS, READONLY, DEBUGGING 18 .debug_str 00000ac7 00000000 00000000 0002a780 20 CONTENTS, READONLY, DEBUGGING 19 .debug_loc 0000170e 00000000 00000000 0002b247 20 CONTENTS, READONLY, DEBUGGING 20 .debug_frame 000001f0 00000000 00000000 0002c958 22 CONTENTS, READONLY, DEBUGGING 21 .debug_ranges 00000070 00000000 00000000 0002cb48 20 CONTENTS, READONLY, DEBUGGING

Any idea what the next step in the analysis could be?

Thanks in advance /Bengt

PicoCPP commented 3 years ago

I'd halt the MCU and see what its trying to do whilst running or you can upload your elf file and I will take a look to see if it hard faults anywhere.

bengtb commented 3 years ago

I did verify that the downloaded file on the pico is the same as the uf2 and elf ones using picotool.

Now I have soldered the wires and run it under the debugger. It does crash:

(gdb) c
Continuing.
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00000178 msp: 0x20041f00

Thread 1 hit Breakpoint 4, isr_hardfault () at /home/pi/Desktop/RPI-pico-FreeRTOS/pico-sdk/src/rp2_common/pico_standard_link/crt0.S:92
92  decl_isr_bkpt isr_hardfault

This is the backtrace:

(gdb) bt
#0  isr_hardfault () at /home/pi/Desktop/RPI-pico-FreeRTOS/pico-sdk/src/rp2_common/pico_standard_link/crt0.S:92
#1  <signal handler called>
#2  0x2000d2c0 in uxTimerTaskStack.4274 ()
#3  0x2000cff0 in ucHeap ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

I have attached the .elf-file.

Thank you for your patience.

hello_world.elf.zip

PicoCPP commented 3 years ago

No Problem, I have found an issue . It crashes in release mode when configSUPPORT_STATIC_ALLOCATION 1 is enabled. I have pushed a patch config to Bugfix/HardFaultsUnderReleaseMode

PicoCPP commented 3 years ago

I have also made another commit and found the source of the problem I believe. It seems like on Cortex M0, the FreeRTOS interrupt functions must be called directly from the vector table.

bengtb commented 3 years ago

I checked out the Bugfix/HardFaultsUnderReleaseMode branch and built it. I haven't had time to experiment anything yet, but it does build and blink.

Thank you!