pidd
Posts: 2096
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK
Contact: Website

[RESOLVED] Don't Panic - Pico C-SDK Hardware Uart

Mon Apr 12, 2021 12:06 pm

I'm messing around using the Pico for Midi (music instrument) interfacing, most of my programs only use the hardware UART and no other IO at all.

Instead of using pico/stdlib.h and pico_stdlib (which work fine), I tried using hardware/uart.h and hardware_uart

Went through the usual rigmarole of dependency after dependency and ended up with a few more than I guessed.

Code: Select all

target_link_libraries(midithru hardware_uart hardware_resets hardware_clocks hardware_timer hardware_irq hardware_gpio pico_binary_info)

cmake is fine, the make builds are fine but make fails at the linking stage, the first error is to do with panic.

Code: Select all

[ 94%] Linking C executable midithru.elf
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: CMakeFiles/midithru.dir/home/pi/pico/pico-sdk/src/rp2_common/hardware_claim/claim.c.obj: in function `hw_claim_or_assert':
claim.c:(.text+0xb0): undefined reference to `panic'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: CMakeFiles/midithru.dir/home/pi/pico/pico-sdk/src/rp2_common/hardware_claim/claim.c.obj: in function `hw_claim_unused_from_range':
claim.c:(.text+0x14c): undefined reference to `panic'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: CMakeFiles/midithru.dir/home/pi/pico/pico-sdk/src/rp2_common/hardware_irq/irq.c.obj: in function `irq_set_exclusive_handler':
irq.c:(.text+0xa6): undefined reference to `hard_assertion_failure'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: irq.c:(.text+0xcc): undefined reference to `__unhandled_user_irq'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: CMakeFiles/midithru.dir/home/pi/pico/pico-sdk/src/rp2_common/hardware_irq/irq.c.obj: in function `irq_get_exclusive_handler':
irq.c:(.text+0x118): undefined reference to `__unhandled_user_irq'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: CMakeFiles/midithru.dir/home/pi/pico/pico-sdk/src/rp2_common/hardware_irq/irq.c.obj: in function `irq_add_shared_handler':
irq.c:(.text+0x17c): undefined reference to `hard_assertion_failure'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: irq.c:(.text+0x25c): undefined reference to `hard_assertion_failure'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: irq.c:(.text+0x2cc): undefined reference to `__unhandled_user_irq'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: CMakeFiles/midithru.dir/home/pi/pico/pico-sdk/src/rp2_common/hardware_irq/irq.c.obj: in function `irq_remove_handler':
irq.c:(.text+0x36a): undefined reference to `__get_current_exception'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: irq.c:(.text+0x378): undefined reference to `hard_assertion_failure'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: irq.c:(.text+0x474): undefined reference to `__unhandled_user_irq'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: CMakeFiles/midithru.dir/home/pi/pico/pico-sdk/src/rp2_common/hardware_irq/irq.c.obj: in function `irq_add_tail_to_free_list':
irq.c:(.text+0x4cc): undefined reference to `__get_current_exception'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: irq.c:(.text+0x56c): undefined reference to `__unhandled_user_irq'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libc.a(lib_a-exit.o): in function `exit':
/tmp/building/package/build/arm-none-eabi/thumb/v6-m/newlib/libc/stdlib/../../../../../../../newlib/libc/stdlib/exit.c:64: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libc.a(lib_a-sbrkr.o): in function `_sbrk_r':
/tmp/building/package/build/arm-none-eabi/thumb/v6-m/newlib/libc/reent/../../../../../../../newlib/libc/reent/sbrkr.c:51: undefined reference to `_sbrk'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libc.a(lib_a-writer.o): in function `_write_r':
/tmp/building/package/build/arm-none-eabi/thumb/v6-m/newlib/libc/reent/../../../../../../../newlib/libc/reent/writer.c:49: undefined reference to `_write'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libc.a(lib_a-closer.o): in function `_close_r':
/tmp/building/package/build/arm-none-eabi/thumb/v6-m/newlib/libc/reent/../../../../../../../newlib/libc/reent/closer.c:47: undefined reference to `_close'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libc.a(lib_a-fstatr.o): in function `_fstat_r':
/tmp/building/package/build/arm-none-eabi/thumb/v6-m/newlib/libc/reent/../../../../../../../newlib/libc/reent/fstatr.c:55: undefined reference to `_fstat'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libc.a(lib_a-isattyr.o): in function `_isatty_r':
/tmp/building/package/build/arm-none-eabi/thumb/v6-m/newlib/libc/reent/../../../../../../../newlib/libc/reent/isattyr.c:52: undefined reference to `_isatty'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libc.a(lib_a-lseekr.o): in function `_lseek_r':
/tmp/building/package/build/arm-none-eabi/thumb/v6-m/newlib/libc/reent/../../../../../../../newlib/libc/reent/lseekr.c:49: undefined reference to `_lseek'
/usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/7.3.1/../../../arm-none-eabi/lib/thumb/v6-m/libc.a(lib_a-readr.o): in function `_read_r':
/tmp/building/package/build/arm-none-eabi/thumb/v6-m/newlib/libc/reent/../../../../../../../newlib/libc/reent/readr.c:49: undefined reference to `_read'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/midithru.dir/build.make:406: midithru.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:1468: CMakeFiles/midithru.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Any ideas why?

Cmake

Code: Select all

cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(midithru C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
pico_sdk_init()
add_executable(midithru midithru.c)
pico_add_extra_outputs(midithru)
target_link_libraries(midithru hardware_uart hardware_resets hardware_clocks hardware_timer hardware_irq hardware_gpio pico_binary_info)

midithru.c (bare-boned to debug)

Code: Select all

#include "hardware/uart.h"

#define UART_ID uart0
#define BAUD_RATE 31250
#define UART_TX_PIN 0
#define UART_RX_PIN 1

int main() {
      uart_init(UART_ID, BAUD_RATE);  
}
Last edited by pidd on Mon Apr 12, 2021 3:40 pm, edited 1 time in total.

dave j
Posts: 133
Joined: Mon Mar 05, 2012 2:19 pm

Re: Don't Panic - Pico C-SDK Hardware Uart

Mon Apr 12, 2021 3:05 pm

You can track down the problem by searching in the SDK for the things reported as undefined references. When I searched for __unhandled_user_irq, I found it in src/rp2_common/pico_standard_link/crt0.S. This implies you need to replace pico_stdlib in your target link libraries with something else.

Searching for pico_standard_link in the C/C++ SDK document describes it in section 2.3.2. Runtime Support (pico_runtime, pico_standard_link). The description includes this tip:
Both pico_runtime and pico_standard_link are included with pico_stdlib
It looks like you'll need to include both pico_runtime and pico_standard_link in your list of target link libraries.

pidd
Posts: 2096
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK
Contact: Website

Re: [RESOLVED] Don't Panic - Pico C-SDK Hardware Uart

Mon Apr 12, 2021 3:30 pm

dave j wrote:
Mon Apr 12, 2021 3:05 pm
You can track down the problem by searching in the SDK for the things reported as undefined references. When I searched for __unhandled_user_irq, I found it in src/rp2_common/pico_standard_link/crt0.S. This implies you need to replace pico_stdlib in your target link libraries with something else.

Searching for pico_standard_link in the C/C++ SDK document describes it in section 2.3.2. Runtime Support (pico_runtime, pico_standard_link). The description includes this tip:
Both pico_runtime and pico_standard_link are included with pico_stdlib
It looks like you'll need to include both pico_runtime and pico_standard_link in your list of target link libraries.
Thanks, I assumed everything would have popped up as unresolved dependencies at the build stage which is why I threw my hands up in the air instead of looking at the detail.

I'd already had a bit of a battle because I found out I have a number of versions of pico_sdk_import.cmake and the one I'd chosen to copy wasn't playing nicely.

Its looking like I might as well stick with pico_stdlib instead of trying to do the proper thing.

pidd
Posts: 2096
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK
Contact: Website

Re: [RESOLVED] Don't Panic - Pico C-SDK Hardware Uart

Mon Apr 12, 2021 4:16 pm

To follow up on this, I needed pico_standard_link in Cmake.

The saving of using specific libraries instead of pico_stdlib meant my uf2 file went from 16k to 6k in size in this instance.

If I used pico_runtime instead of pico_standard_link it increases to 33k which is weird as it shouldn't be bigger than using pico_stdlib? Maybe I messed up, I have pico's coming out my ears.

According to the docs I may/should need both pico_standard_link and pico_runtime? I'll see what happens when I connect some hardware later.

kilograham
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 640
Joined: Fri Apr 12, 2019 11:00 am
Location: austin tx

Re: [RESOLVED] Don't Panic - Pico C-SDK Hardware Uart

Mon Apr 12, 2021 10:57 pm

Note that `pico_stdlib` is a really good choice for most people unless you really need to save those bytes (note you are talking half the saving you mention because a UF2 size is double the in flash size). There are a bunch of build defines to limit/remove functionality which is perhaps better in many cases, in that in your case you may not have intended for example to remove support for fast division using the hardware divider, which takes minimal space.

Certainly just because you only want to use UART isn't a big reason, because if you neither call printf explicitly or add USB explicitly, you aren't getting a lot of extra code.

pidd
Posts: 2096
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK
Contact: Website

Re: [RESOLVED] Don't Panic - Pico C-SDK Hardware Uart

Tue Apr 13, 2021 12:28 am

kilograham wrote:
Mon Apr 12, 2021 10:57 pm
Note that `pico_stdlib` is a really good choice for most people unless you really need to save those bytes (note you are talking half the saving you mention because a UF2 size is double the in flash size). There are a bunch of build defines to limit/remove functionality which is perhaps better in many cases, in that in your case you may not have intended for example to remove support for fast division using the hardware divider, which takes minimal space.

Certainly just because you only want to use UART isn't a big reason, because if you neither call printf explicitly or add USB explicitly, you aren't getting a lot of extra code.
Maybe!

For the simplistic programs I'm doing at the moment I will keep doing things the hard way, I'll learn more, at some point I may have to concede.

kilograham
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 640
Joined: Fri Apr 12, 2019 11:00 am
Location: austin tx

Re: [RESOLVED] Don't Panic - Pico C-SDK Hardware Uart

Tue Apr 13, 2021 3:06 am

cool.... yeah i mean the reason they are separate, is so you can do exactly what you are doing, so carry on!

Return to “SDK”