Pico-sdk studies

From Wiki at Neela Nurseries
Jump to: navigation, search

Device_tree_from_scratch   ::   Spi_device_tree_source_code   ::   Pico-sdk_studies


2022-08-15 Pico SDK Studies


^ Overview

As of 2023 April work on RPi Pico board in context of Zephyr RTOS 3.3.0 presents some challenges. This board utilizes the RP2040, a ARM Cortex M0+ dual-core processor. RPi Pico comes with its own Software Development Kit. Zephyr RTOS Project has pulled this SDK into its `modules` third party code collection. But not all or many features of Pico's SDK compile within a Zephyr 3.3.0 based app, and it is not yet clear which Kconfig symbols or other build time configurations are needed to correctly and fully integrate Pico SDK with Zephyr's sources.

Year 2022 notes taken on RPi Pico bring up efforts are now a bit out-dated with the 2023 early April release of Zephyr 3.3.0. These notes are left in place and marked with a left-hand color strip. Contributor Ted to review these.

A 2023 Q2 good starting point may well be one Andrei-Edward Popa's presentation on using Zephyr with RPi Pico board. Two links here to his works:

 


^ How To Program RPi Pico Board

One manner in which to program RPi Pico board is through its USB interface. The RPi Pico is typically powered via its USB port. The steps to flashing a program to the Pico board are in short:

(1) compile a Zephyr or other RPi Pico project which results in a "dot uf2" type file
(2) disconnect RPi Pico board's USB cable to power down board
(3) press and hold down Pico board's BOOTSEL button
(4) reconnect RPi Pico USB cable to computer where .uf2 image file resides
(5) copy the .uf2 image file to the directory which appears under your username's media directory

    ( typically `/media/${USERNAME}/RPI-RP2` )


On Ubuntu 20.04 LTS work stations, the USB sub-system or a part of it recognizes RPi Pico boards in boot select mode as an external media device. The Ubuntu driver side behavior is to create a directory having the path /media/${USERNAME}/RPI-RP2 or similar. This happens when an RPi Pico board is powered up via USB connected to the Ubuntu host, and the Pico board's boot select button is pressed and held closed. Most RPi tutorials talk about dragging and dropping the .uf2 image file to the media folder's icon on a graphical desktop. A shell based copy command, such as `cp -pv image.uf2 /media/${USERNAME}/RPI-RP2` does the same thing. Once the image copy action completes, the media directory `RPI-RP2` becomes unwriteable or unavailable.

The Pico board may need to be powered cycled once more for the latest image to start executing. ( Need to test this - TMH )


^ 2022 RPi Pico Notes - To Review

^ Zephyr Support for RPi Pico

And as of 2024-01-30, in Zephyr RTOS latest boards directory at github:


^ DMA driver details

2022-08-18

This section holds notes on RPi Pico SDK driver code for the RP2040 direct memory access unit. Goal here is to understand how Pico SDK structures its Application Programmers' Interface or API. We need to understand this in order to connect a Zephyr based application to code running on RP2040 and using its DMA. Likely we will need DMA when we enable and implement one or more SPI based peripherals, as SPI transmit and receive lines are often associated with a DMA controller to support high data transmission rates.

Search for . . .

ted@localhost:~/projects/zephyr-based/workspace-rpi-pico-work/pico-sdk$ grep -nr NUM_DMA_CHANNELS ./*
./src/host/pico_platform/include/hardware/platform_defs.h:12:#define NUM_DMA_CHANNELS 12u
. . .
./src/rp2040/hardware_structs/include/hardware/structs/dma.h:106:    dma_channel_hw_t ch[NUM_DMA_CHANNELS]; // 12
./src/rp2040/hardware_structs/include/hardware/structs/dma.h:194:    } ch[NUM_DMA_CHANNELS];


So we have looked up a symbol which reflects that RP2040 DMA controller has twelve independent channels for memory to memory transfers. The Synopsys device bindings file however specifies that we must assign to node property "dma-cells" a fixed value of 1. Another good starting point to understand Pico SPI driver is in the "hello_dma" sample app. Before configuring any DMA attributes source file main.c first calls routine . . .


^ UART with DMA

Another instructive Pico sample app is the DMA control block sample which uses two DMA channels to transfer a series of data blocks.



^ Pico assert.h definitions

RPi Pico SDK assert() definition is included in a section of this nn wiki page, as this Pico header file is included by both RPi Pico DMA driver and RPi Pico SPI driver. It is likely included by other Pico drivers and modules. We also include mention of this definition as recent studies of Zephyr third party drivers reveal that various projects each provide their own definitions of the C assert() construct.

$ find . -name assert.h
./common/pico_base/include/pico/assert.h

The contents of Pico SDK assert.h file are:


#ifdef __cplusplus

#include <cassert>

extern "C" {
#else
#include <assert.h>
#endif

// PICO_CONFIG: PARAM_ASSERTIONS_ENABLE_ALL, Global assert enable, type=bool, default=0, group=pico_base
// PICO_CONFIG: PARAM_ASSERTIONS_DISABLE_ALL, Global assert disable, type=bool, default=0, group=pico_base

#ifndef PARAM_ASSERTIONS_ENABLE_ALL
#define PARAM_ASSERTIONS_ENABLE_ALL 0
#endif

#ifndef PARAM_ASSERTIONS_DISABLE_ALL
#define PARAM_ASSERTIONS_DISABLE_ALL 0
#endif

#define PARAM_ASSERTIONS_ENABLED(x) ((PARAM_ASSERTIONS_ENABLED_ ## x || PARAM_ASSERTIONS_ENABLE_ALL) && !PARAM_ASSERTIONS_DISABLE_ALL)

#define invalid_params_if(x, test) ({if (PARAM_ASSERTIONS_ENABLED(x)) assert(!(test));})
#define valid_params_if(x, test) ({if (PARAM_ASSERTIONS_ENABLED(x)) assert(test);})
#define hard_assert_if(x, test) ({if (PARAM_ASSERTIONS_ENABLED(x)) hard_assert(!(test));})

#ifdef NDEBUG
extern void hard_assertion_failure(void);
static inline void hard_assert(bool condition, ...) {
    if (!condition)
        hard_assertion_failure();
}
#else
#define hard_assert assert
#endif

#ifdef __cplusplus
}
#endif
#endif


z z z



/*
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

// ---------------------------------------
// THIS FILE IS AUTOGENERATED; DO NOT EDIT
// ---------------------------------------

#ifndef _PICO_VERSION_H
#define _PICO_VERSION_H

#define PICO_SDK_VERSION_MAJOR    ${PICO_SDK_VERSION_MAJOR}
#define PICO_SDK_VERSION_MINOR    ${PICO_SDK_VERSION_MINOR}
#define PICO_SDK_VERSION_REVISION ${PICO_SDK_VERSION_REVISION}
#define PICO_SDK_VERSION_STRING   "${PICO_SDK_VERSION_STRING}"

#endif


^ Study of DMA routine check_dma_channel_param()

The routine `check_dma_channel_param()` appears in file dma.c at line 24. In file dma.c references to this routine appear three three times and there is a conditionally compiled definition for it at line 97. There is a second place in Pico SDK where this routine is defined, in header file dma.h. The two definitions read as follows:

Excerpts 1 - check_dma_channel_param() definitions

rp2_common/hardware_dma/dma.c

rp2_common/hardware_dma/include/hardware/dma.h

 96 #if PARAM_ASSERTIONS_ENABLED(DMA)
 97 void check_dma_channel_param_impl(uint __unused channel) {
 98     valid_params_if(DMA, channel < NUM_DMA_CHANNELS);
 99 }
100 #endif
 49 static inline void check_dma_channel_param(__unused uint channel) {
 50 #if PARAM_ASSERTIONS_ENABLED(DMA)
 51     // this method is used a lot by inline functions so avoid code bloat by deferring to function
 52     extern void check_dma_channel_param_impl(uint channel);
 53     check_dma_channel_param_impl(channel);
 54 #endif
 55 }

The routine is defined in dma.c. An interesting feature of this definition is the use of an extern statement within the scope of the routine body. Perhaps the C compiler does not care whether an extern qualified expression is locally scoped or file scoped, in a sense that the compiler only needs to know that given routine is defined somewhere and will be known to the linker at link time.

The following routine-like macro plays a role in the definition of the above routine:


    ./src/common/pico_base/include/pico/assert.h:35:#define valid_params_if(x, test) ({if (PARAM_ASSERTIONS_ENABLED(x)) assert(test);})

and PARAM_ASSERTIONS_ENABLED(x) is defined,

    ./src/common/pico_base/include/pico/assert.h:32:#define PARAM_ASSERTIONS_ENABLED(x) ((PARAM_ASSERTIONS_ENABLED_ ## x || PARAM_ASSERTIONS_ENABLE_ALL) && !PARAM_ASSERTIONS_DISABLE_ALL)


Perhaps another DMA routine's implementation will be easier to track down:


200 /*! \brief Set the size of each DMA bus transfer in a channel configuration object
201  *  \ingroup channel_config
202  *
203  * Set the size of each bus transfer (byte/halfword/word). The read and write addresses
204  * advance by the specific amount (1/2/4 bytes) with each transfer.
205  *
206  * \param c Pointer to channel configuration object
207  * \param size See enum for possible values.
208  */
209 static inline void channel_config_set_transfer_data_size(dma_channel_config *c, enum dma_channel_transfer_size size) {
210     assert(size == DMA_SIZE_8 || size == DMA_SIZE_16 || size == DMA_SIZE_32);
211     c->ctrl = (c->ctrl & ~DMA_CH0_CTRL_TRIG_DATA_SIZE_BITS) | (((uint)size) << DMA_CH0_CTRL_TRIG_DATA_SIZE_LSB);
212 }


^ *

^ Pico SDK start up APIs

In studying hello_dma sample app, first Pico SDK call is to API stdio_init_all(). This appears to be defined in two places of the SDK . . .

Place 1:

Code excerpt, start up code from file [pico-sdk]/src/rp2_common/pico_stdio/stdio.c:

269 
270 void stdio_init_all(void) {
271     // todo add explicit custom, or registered although you can call stdio_enable_driver explicitly anyway
272     // These are well known ones
273 #if LIB_PICO_STDIO_UART
274     stdio_uart_init();
275 #endif
276 
277 #if LIB_PICO_STDIO_SEMIHOSTING
278     stdio_semihosting_init();
279 #endif
280 
281 #if LIB_PICO_STDIO_USB
282     stdio_usb_init();
283 #endif
284 }
285


Place 2:

[pico-sdk]/src/host/pico_stdio/include/pico/stdio.h"

  1 /*
  2  * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
  3  *
  4  * SPDX-License-Identifier: BSD-3-Clause
  5  */
  6 #ifndef _PICO_STDIO_H
  7 #define _PICO_STDIO_H
  8 
  9 typedef struct stdio_driver stdio_driver_t;
 10 
 11 #define STDIO_ERROR -1
 12 #define STDIO_NO_INPUT -2
 13 
 14 static inline void stdio_usb_init() {}
 15 void stdio_uart_init();
 16 static inline void stdio_init_all() { stdio_uart_init(); }
 17 static inline void stdio_filter_driver(stdio_driver_t *driver) {}
 18 static inline void stdio_set_translate_crlf(stdio_driver_t *driver, bool enabled) {}
 19 static inline bool stdio_usb_connected(void) { return true; }
 20 int getchar_timeout_us(uint32_t timeout_us);
 21 #define puts_raw puts
 22 #define putchar_raw putchar
 23 
 24 #endif

Ok, turns out there are supposed to be two definitions for this important API routine, as Pico SDK supports code development on hosts, processors other than the RP2040. The readme file [pico_sdk]/src/host/README.md explains this. Now we need to find another file which talks about a Pico SDK project setting to select RP2040 as the target MCU. This is the defaul, and it may help us resolve the compile time error we're getting as we start to include various headers of the Pico SDK in a Zephyr based exploratory app . . .

2022-08-20 excerpt - build errors during Pico SDK inclusion in Zephyr app:

. . .
 -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=/home/ted/projects/zephyr-based/workspace-rpi-pico-work/rpi-pico-zephyr-exploration=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/ted/projects/zephyr-based/workspace-rpi-pico-work/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/ted/projects/zephyr-based/workspace-rpi-pico-work=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MT CMakeFiles/app.dir/home/ted/projects/zephyr-based/workspace-rpi-pico-work/pico-sdk/src/rp2_common/pico_stdio/stdio.c.obj -MF CMakeFiles/app.dir/home/ted/projects/zephyr-based/workspace-rpi-pico-work/pico-sdk/src/rp2_common/pico_stdio/stdio.c.obj.d -o CMakeFiles/app.dir/home/ted/projects/zephyr-based/workspace-rpi-pico-work/pico-sdk/src/rp2_common/pico_stdio/stdio.c.obj -c /home/ted/projects/zephyr-based/workspace-rpi-pico-work/pico-sdk/src/rp2_common/pico_stdio/stdio.c
/home/ted/projects/zephyr-based/workspace-rpi-pico-work/pico-sdk/src/rp2_common/pico_stdio/stdio.c:261:18: error: expected declaration specifiers or '...' before numeric constant
  261 | int __printflike(1, 0) WRAPPER_FUNC(printf)(const char* format, ...)
      |                  ^
/home/ted/projects/zephyr-based/workspace-rpi-pico-work/pico-sdk/src/rp2_common/pico_stdio/stdio.c:261:21: error: expected declaration specifiers or '...' before numeric constant
  261 | int __printflike(1, 0) WRAPPER_FUNC(printf)(const char* format, ...)
      |                     ^
/home/ted/projects/zephyr-based/workspace-rpi-pico-work/pico-sdk/src/rp2_common/pico_stdio/stdio.c:227:13: warning: 'stdio_buffered_printer' defined but not used [-Wunused-function]
  227 | static void stdio_buffered_printer(char c, void *arg) {
      |             ^~~~~~~~~~~~~~~~~~~~~~
[23/151] Building C object zephyr/CMakeFiles/zephyr.dir/subsys/logging/log_list.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /home/ted/projects/zephyr-based/workspace-rpi-pico-work/rpi-pico-zephyr-exploration/build
ted@localhost:~/projects/zephyr-based/workspace-rpi-pico-work/rpi-pico-zephyr-exploration$


. . . Ah easy, that readme file which describes pico-sdk's default MCU or "platform" is the primary pico-sdk README.md file. The pico-sdk project setting to note is 'PICO_PLATFORM=rp2040'.


^ Pico rp2_common headers versus host headers

Pico SDK "host" header files are designed to support running RPi Pico projects on non-rpi hardware. This would be useful if an app is too large to fit in an RPi Pico, or if for some reason an RPi Pico board is not available during all development times.


^ *

^ RPi Pico exploration project paths -06-txt

zztop
/home/ted/projects/zephyr-based/workspace-rpi-pico-work/rpi-pico-zephyr-exploration
/home/ted/projects/zephyr-based/workspace-rpi-pico-work/rpi-pico-zephyr-exploration/src
/home/ted/projects/zephyr-based/workspace-rpi-pico-work/rpi-pico-zephyr-exploration/boards
/
/home/ted/projects/zephyr-based/workspace-rpi-pico-work/pico-sdk
/home/ted/projects/zephyr-based/workspace-rpi-pico-work/pico-sdk/src/rp2_common
/home/ted/projects/zephyr-based/workspace-rpi-pico-work/pico-sdk/src/rp2_common/pico_stdio
/home/ted/reference/rpi-pico-sdk/src/host/pico_stdio/include/pico


^ RPi Pico SDK code in Zephyr modules

Zephyr modules directory contains hal_rpi_pico references, see file [workspace]/modules/hal/rpi_pico/zephyr/module.yaml. What do stanzas cmake-ext and kconfig-ext mean? How possible that we do not find actual source files on the github Zephyr RTOS Project repository for RPi Pico SDK sources, but that these sources appear to be downloaded into the local Zephyr modules dir?

  1 name: hal_rpi_pico
  2 build:
  3   cmake-ext: True
  4   kconfig-ext: True

Ok, finding that in 2021 December Yonatan Schachter made a pull request to Zephyr RTOS Project to have RPi Pico SDK sources brought into Hardware Abstraction Layer (hal) module of Zephyr. Pull request and developer comments at:

   *  https://github.com/zephyrproject-rtos/zephyr/issues/40817

A useful search of Zephyr's forked pico-sdk source tree:

  $ [zephyr-workspace-for-rpi]/modules$ grep -nr PICO_WEAK_FUNCTION_DEF[^_] ./*


^ hello_dma Build Messages

Pico sample application "hello_dma" build messages using pico build framework or method: first create a dir named 'build' at top directory of pico-examples project. From within this directory named 'build' execute `cmake ..`. This creates many new files and directories for all example projects, including GNU makefiles per project which permit building the sample apps into .uf2 format binaries. Messages from building hello_dma:

ted@localhost:~/reference/pico-examples/build$ ls
adc     cmake           cmake_install.cmake  elf2uf2    gpio         interp     picoboard  pio     reset  system  usb
blink   CMakeCache.txt  divider              flash      hello_world  Makefile   pico-sdk   pioasm  rtc    timer   watchdog
clocks  CMakeFiles      dma                  generated  i2c          multicore  pico_w     pwm     spi    uart
ted@localhost:~/reference/pico-examples/build$ cd dma
ted@localhost:~/reference/pico-examples/build/dma$ ls
channel_irq  CMakeFiles  cmake_install.cmake  control_blocks  hello_dma  Makefile
ted@localhost:~/reference/pico-examples/build/dma$ cd hello_dma/
ted@localhost:~/reference/pico-examples/build/dma/hello_dma$ ls
CMakeFiles  cmake_install.cmake  Makefile
ted@localhost:~/reference/pico-examples/build/dma/hello_dma$ vi Makefile 
ted@localhost:~/reference/pico-examples/build/dma/hello_dma$ ls
CMakeFiles  cmake_install.cmake  Makefile
ted@localhost:~/reference/pico-examples/build/dma/hello_dma$ make
[  0%] Creating directories for 'ELF2UF2Build'
[  0%] No download step for 'ELF2UF2Build'
[  0%] No update step for 'ELF2UF2Build'
[  0%] No patch step for 'ELF2UF2Build'
[  0%] Performing configure step for 'ELF2UF2Build'
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ted/reference/pico-examples/build/elf2uf2
[  0%] Performing build step for 'ELF2UF2Build'
[ 50%] Building CXX object CMakeFiles/elf2uf2.dir/main.cpp.o
[100%] Linking CXX executable elf2uf2
[100%] Built target elf2uf2
[  0%] No install step for 'ELF2UF2Build'
[  0%] Completed 'ELF2UF2Build'
[  0%] Built target ELF2UF2Build
Scanning dependencies of target bs2_default
[  0%] Building ASM object pico-sdk/src/rp2_common/boot_stage2/CMakeFiles/bs2_default.dir/compile_time_choice.S.obj
[  0%] Linking ASM executable bs2_default.elf
[  0%] Built target bs2_default
[  0%] Generating bs2_default.bin
[  0%] Generating bs2_default_padded_checksummed.S
[  0%] Built target bs2_default_padded_checksummed_asm
Scanning dependencies of target hello_dma
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/hello_dma.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_stdlib/stdlib.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_gpio/gpio.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_claim/claim.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_platform/platform.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_sync/sync.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_irq/irq.c.obj
[  0%] Building ASM object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_irq/irq_handler_chain.S.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/common/pico_sync/sem.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/common/pico_sync/lock_core.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/common/pico_time/time.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/common/pico_time/timeout_helper.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_timer/timer.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/common/pico_util/datetime.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/common/pico_util/pheap.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/common/pico_util/queue.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/common/pico_sync/mutex.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/common/pico_sync/critical_section.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_uart/uart.c.obj
[  0%] Building ASM object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_divider/divider.S.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_runtime/runtime.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_clocks/clocks.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_pll/pll.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_vreg/vreg.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_watchdog/watchdog.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_xosc/xosc.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_printf/printf.c.obj
[  0%] Building ASM object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_bit_ops/bit_ops_aeabi.S.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_bootrom/bootrom.c.obj
[  0%] Building ASM object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_divider/divider.S.obj
[  0%] Building ASM object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_double/double_aeabi.S.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_double/double_init_rom.c.obj
[  0%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_double/double_math.c.obj
[  0%] Building ASM object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_double/double_v1_rom_shim.S.obj
[  0%] Building ASM object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_int64_ops/pico_int64_ops_aeabi.S.obj
[100%] Building ASM object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_float/float_aeabi.S.obj
[100%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_float/float_init_rom.c.obj
[100%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_float/float_math.c.obj
[100%] Building ASM object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_float/float_v1_rom_shim.S.obj
[100%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_malloc/pico_malloc.c.obj
[100%] Building ASM object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_mem_ops/mem_ops_aeabi.S.obj
[100%] Building ASM object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_standard_link/crt0.S.obj
[100%] Building CXX object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_standard_link/new_delete.cpp.obj
[100%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_standard_link/binary_info.c.obj
[100%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_stdio/stdio.c.obj
[100%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/pico_stdio_uart/stdio_uart.c.obj
[100%] Building C object dma/hello_dma/CMakeFiles/hello_dma.dir/home/ted/reference/pico-sdk/src/rp2_common/hardware_dma/dma.c.obj
[100%] Linking CXX executable hello_dma.elf
[100%] Built target hello_dma
ted@localhost:~/reference/pico-examples/build/dma/hello_dma$ ls
CMakeFiles  cmake_install.cmake  hello_dma.bin  hello_dma.dis  hello_dma.elf  hello_dma.elf.map  hello_dma.hex  hello_dma.uf2  Makefile
ted@localhost:~/reference/pico-examples/build/dma/hello_dma$


When attempting to build a Zephyr 3.1.0 based app which references pico-sdk hello_dma calls to RP2040 DMA driver API, get build time error message where symbol in [rpi-pico-sdk]/src/host/pico_platform/platform_base.c does not seem to expand. Symbol is referenced early in this file on line xx:

Excerpt from https://github.com/zephyrproject-rtos/hal_rpi_pico/blob/zephyr/src/host/pico_platform/platform_base.c:

/*
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
#include <stdarg.h>
#include <stdio.h>

#include "pico.h"

PICO_WEAK_FUNCTION_DEF(tight_loop_contents)

void PICO_WEAK_FUNCTION_IMPL_NAME(tight_loop_contents)() {

}

void __noreturn panic_unsupported() {
    panic("not supported");
}

void hard_assertion_failure(void) {
    panic("Hard assert");
}

void panic(const char *fmt, ...) {
    va_list args;

    puts("*** PANIC ***\n");
    if (fmt) {
        va_start(args, fmt);
        vprintf(fmt, args);
        va_end(args);
    }

    puts("\n");

    __breakpoint();
}

Symbol PICO_WEAK_FUNCTION_DEF does not seem to expand. We need this source file in order to have pico-sdk's expected definition of panic macro or function.

Now on 2022-08-25 Thursday, having added a CMakeLists.txt include statement 'include(../pico-sdk/pico_sdk_init.cmake)' to our RPi explorations project, in effort to make pico-sdk a proper sub-module of our Zephyr based app, build messages now are:

workspace-for-rpi/rpi-pico-zephyr-exploration$ west build -b rpi_pico
[0/1] Re-running CMake...
Loading Zephyr default modules (Zephyr base (cached)).
-- Application: /home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration
-- Found Python3: /usr/bin/python3.8 (found suitable exact version "3.8.10") found components: Interpreter 
-- Cache files will be written to: /home/ted/.cache/zephyr
-- Zephyr version: 3.1.0-rc1 (/home/ted/projects-sandbox/workspace-for-rpi/zephyr)
-- Found west (found suitable version "0.12.0", minimum required is "0.7.1")
-- Board: rpi_pico
-- Found dtc: /usr/bin/dtc (found suitable version "1.5.0", minimum required is "1.4.6")
-- Found toolchain: gnuarmemb (/opt/gcc-arm-none-eabi-10.3-2021.10)
-- Found BOARD.dts: /home/ted/projects-sandbox/workspace-for-rpi/zephyr/boards/arm/rpi_pico/rpi_pico.dts
-- Found devicetree overlay: /home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/boards/rpi_pico.overlay
-- Generated zephyr.dts: /home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: /home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr/include/generated/devicetree_unfixed.h
-- Generated device_extern.h: /home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr/include/generated/device_extern.h
-- Including generated dts.cmake file: /home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr/dts.cmake
/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr/zephyr.dts:61.34-66.5: Warning (simple_bus_reg): /soc/peripheral-clk: missing or empty reg/ranges property
/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr/zephyr.dts:67.26-72.5: Warning (simple_bus_reg): /soc/system-clk: missing or empty reg/ranges property
/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr/zephyr.dts:82.36-113.5: Warning (unique_unit_address_if_enabled): /soc/pin-controller@40014000: duplicate unit-address (also used in node /soc/gpio@40014000)
Parsing /home/ted/projects-sandbox/workspace-for-rpi/zephyr/Kconfig
Loaded configuration '/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr/.config'
No change to configuration in '/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr/.config'
No change to Kconfig header in '/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr/include/generated/autoconf.h'
CMake Warning at /home/ted/projects-sandbox/workspace-for-rpi/zephyr/CMakeLists.txt:820 (message):
  No SOURCES given to Zephyr library: drivers__led_strip

  Excluding target from build.


CMake Warning at /home/ted/projects-sandbox/workspace-for-rpi/zephyr/CMakeLists.txt:1840 (message):
  

        The CMake build type was set to 'Release', but the optimization flag was set to '-Os'.
        This may be intentional and the warning can be turned off by setting the CMake variable 'NO_BUILD_TYPE_WARNING'


PICO_SDK_PATH is /home/ted/projects-sandbox/workspace-for-rpi/pico-sdk
PICO platform is rp2040.
Build type is Release
PICO target board is pico.
Using board configuration from /home/ted/projects-sandbox/workspace-for-rpi/pico-sdk/src/boards/include/boards/pico.h
-- Found Python3: /usr/bin/python3.8 (found version "3.8.10") found components: Interpreter 
CMake Warning at /home/ted/projects-sandbox/workspace-for-rpi/pico-sdk/src/rp2_common/tinyusb/CMakeLists.txt:10 (message):
  TinyUSB submodule has not been initialized; USB support will be unavailable

  hint: try 'git submodule update --init' from your SDK directory
  (/home/ted/projects-sandbox/workspace-for-rpi/pico-sdk).


PICO platform is rp2040.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build
[1/154] Performing build step for 'second_stage_bootloader'
ninja: no work to do.
[20/152] Building C object CMakeFiles/app.dir/src/thread-hello-dma.c.obj
/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/src/thread-hello-dma.c: In function 'thread_hello_dma__entry_point':
/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/src/thread-hello-dma.c:97:9: warning: unused variable 'chan' [-Wunused-variable]
   97 |     int chan = dma_claim_unused_channel(true);
      |         ^~~~
[27/152] Building C object CMakeFiles/app.dir/src/thread-led.c.obj
/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/src/thread-led.c:44:2: warning: #warning --- --- --- macro evaluating 'led0' dts alias returns true --- --- --- [-Wcpp]
   44 | #warning --- --- --- macro evaluating 'led0' dts alias returns true --- --- ---
      |  ^~~~~~~
/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/src/thread-led.c:59:2: warning: #warning --- --- --- macro evaluating 'led1' dts alias returns true --- --- --- [-Wcpp]
   59 | #warning --- --- --- macro evaluating 'led1' dts alias returns true --- --- ---
      |  ^~~~~~~
/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/src/thread-led.c: In function 'thread_led__entry_point':
/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/src/thread-led.c:124:14: warning: unused variable 'rstatus' [-Wunused-variable]
  124 |     uint32_t rstatus = ROUTINE_OK;
      |              ^~~~~~~
[142/152] Linking C executable zephyr/zephyr_pre0.elf
FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr/zephyr_pre0.map 
: && ccache /opt/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc -O3 -DNDEBUG  zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -fuse-ld=bfd  -Wl,-T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a  zephyr/lib/libc/minimal/liblib__libc__minimal.a  zephyr/lib/posix/liblib__posix.a  zephyr/soc/arm/rpi_pico/rp2/libsoc__arm__rpi_pico__rp2.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/timer/libdrivers__timer.a  zephyr/drivers/pinctrl/libdrivers__pinctrl.a  zephyr/drivers/reset/libdrivers__reset.a  modules/hal_rpi_pico/libmodules__hal_rpi_pico.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  -L"/opt/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/thumb/v6-m/nofp"  -L/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  -no-pie  -mcpu=cortex-m0plus  -mthumb  -mabi=aapcs  -mfp16-format=ieee  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn && cd /home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build/zephyr && /usr/bin/cmake -E echo
/opt/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.bfd: app/libapp.a(thread-hello-dma.c.obj): in function `thread_hello_dma__entry_point':
/home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/src/thread-hello-dma.c:97: undefined reference to `dma_claim_unused_channel'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /home/ted/projects-sandbox/workspace-for-rpi/rpi-pico-zephyr-exploration/build

So we're back to square one, needing to pound include one and likely many pico-sdk header files. Can we do so simply by amending CMakeLists.txt with additional 'zephyr_directory_add()' directives?



^ Where Defined PICO_WEAK_FUNCTION_DEF

PICO_WEAK_FUNCTION_DEF defined in file:

[zephyr]/modules/hal/rpi_pico/src/host/pico_platform/include/pico/platform.h


*   *   *   *   *   *   *   *   *   *   *   *   *   *   *   *

^ Reference

Hmm, would be nice to have mark up which supports HTML style ordered lists, with non-indented comments interleaved between list items - TMH  

  1. pico-sdk/src/rp2_common/README.md . . . document explains convention of Pico library routines which names of form hardware_ and pico_.
  2. pico_pre_load_platform.cmake . . . `cmake` file demonstrates cmake's ability to select variable from among `cmake` internal variables and environment variables.
  3. https://iosoft.blog/2021/10/26/pico-adc-dma/
  4. https://forums.raspberrypi.com/viewtopic.php?t=315944 . . . REVIEW this and next link, may solve __printflike() build errors - TMH
  5. https://forums.raspberrypi.com/viewtopic.php?t=315944#p1890253
  6. -
  7. https://forums.raspberrypi.com/viewtopic.php?t=302082 . . . with pico-examples must run a build at top level of pico-sdk project
  8. https://forums.raspberrypi.com/viewtopic.php?t=316408 . . . how to set PICO_SDK_PATH in Linux environment
  9. https://www.electromaker.io/blog/article/getting-started-with-the-raspberry-pi-pico-w-cc-sdk . . . Ian Buckley of Electromaker tutorial "Getting Started with Rpi Pico"