Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8609

C/C++ • Re: DIY C++ GPIO library

$
0
0
Hello! Creating your own C++ libraries for the pico-sdk is an accessible process but requires some prior knowledge. To begin, it is essential to study the datasheet of the microcontroller you are using, especially the section that explains how the GPIO registers work and how they control the physical pins of the hardware. It is also crucial to consult the official pico-sdk documentation, which describes the internal structure of the libraries, the available peripherals, and how to interact with the hardware efficiently. Additionally, the official examples repository on GitHub is an excellent resource, offering practical code examples for GPIO, PWM, SPI, I2C, and other fundamental functionalities. Finally, it is essential to properly configure your development environment on your computer, with the pico-sdk installed, along with CMake, the GCC compiler for ARM, and a code editor such as VS Code, CLion, or any other of your choice. I also recommend reviewing the basic concepts of creating libraries in C++, as this knowledge will enable you to develop libraries for any type of device you need to use with the pico-sdk.

Examples: https://github.com/raspberrypi/pico-examples
Thanks kaillanecmartins, I just finished installing CLion and have sucesfully gone 3/4th s of the way to setting it up the pico sdk, however I keep getting error messages on my Mac when I try to build the blink file in the pico examples

these are not the warning messages but cmake seems to be skipping a lot of the files when I open the project in CLion

Code:

/Applications/CLion.app/Contents/bin/cmake/mac/aarch64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/Applications/CLion.app/Contents/bin/ninja/mac/aarch64/ninja -G Ninja -S /Users/joshuaimmanuel/pico/pico-examples -B /Users/joshuaimmanuel/pico/pico-examples/cmake-build-debugPICO_SDK_PATH is /Users/joshuaimmanuel/pico/pico-sdkTarget board (PICO_BOARD) is 'pico'.Using board configuration from /Users/joshuaimmanuel/pico/pico-sdk/src/boards/include/boards/pico.hPico Platform (PICO_PLATFORM) is 'rp2040'.Build type is DebugUsing regular optimized debug build (set PICO_DEOPTIMIZED_DEBUG=1 to de-optimize)TinyUSB available at /Users/joshuaimmanuel/pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.Compiling TinyUSB with CFG_TUSB_DEBUG=1BTstack available at /Users/joshuaimmanuel/pico/pico-sdk/lib/btstackcyw43-driver available at /Users/joshuaimmanuel/pico/pico-sdk/lib/cyw43-driverlwIP available at /Users/joshuaimmanuel/pico/pico-sdk/lib/lwipmbedtls available at /Users/joshuaimmanuel/pico/pico-sdk/lib/mbedtlsCMake Warning at /Users/joshuaimmanuel/pico/pico-sdk/tools/Findpicotool.cmake:30 (message):  No installed picotool with version 2.1.1 found - building from source  It is recommended to build and install picotool separately, or to set  PICOTOOL_FETCH_FROM_GIT_PATH to a common directory for all your SDK  projectsCall Stack (most recent call first):  /Users/joshuaimmanuel/pico/pico-sdk/tools/CMakeLists.txt:138 (find_package)  /Users/joshuaimmanuel/pico/pico-sdk/tools/CMakeLists.txt:493 (pico_init_picotool)  /Users/joshuaimmanuel/pico/pico-sdk/src/cmake/on_device.cmake:56 (picotool_postprocess_binary)  blink/CMakeLists.txt:13 (pico_add_extra_outputs)Downloading PicotoolOnly building blink_any for non W boards as PICO_CYW43_SUPPORTED is not setSkipping encrypted example which is unsupported on this platformSkipping hello_dcp example which is unsupported on this platformSkipping runtime_flash_permissions example which is unsupported on this platformSkipping dvi_out_hstx_encoder example which is unsupported on this platformSkipping spi_lcd example which is unsupported on this platformSkipping multicore_doorbell example which is unsupported on this platformSkipping hello_otp example which is unsupported on this platformSkipping boot_info example which is unsupported on this platformSkipping universal examples as PICO_RISCV_TOOLCHAIN_PATH and PICO_ARM_TOOLCHAIN_PATH are not definedSkipping TinyUSB dual examples, as TinyUSB hw/mcu/raspberry_pi/Pico-PIO-USB submodule unavailableSkipping SHA256 examples as pico_sha256 or pico_mbedtls unavailableSkipping FreeRTOS examples as FREERTOS_KERNEL_PATH not defined-- Configuring done (2.5s)-- Generating done (4.5s)-- Build files have been written to: /Users/joshuaimmanuel/pico/pico-examples/cmake-build-debug[Previous CMake output restored: 23/06/2025, 10:27]
These are the warning messages in CLion I was mentioning, it seems as if pico tool hasn't been built but I have no idea how to do this nor how to add it to path, I am hoping to get it to work with a raspberry pi pico2 :-

Code:

/Applications/CLion.app/Contents/bin/cmake/mac/aarch64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/Applications/CLion.app/Contents/bin/ninja/mac/aarch64/ninja -G Ninja -S /Users/joshuaimmanuel/pico/pico-examples -B /Users/joshuaimmanuel/pico/pico-examples/cmake-build-debugUsing PICO_SDK_PATH from environment ('/Users/joshuaimmanuel/pico/pico-sdk')PICO_SDK_PATH is /Users/joshuaimmanuel/pico/pico-sdkDefaulting platform (PICO_PLATFORM) to 'rp2040' since not specified.Defaulting target board (PICO_BOARD) to 'pico' since not specified.Using board configuration from /Users/joshuaimmanuel/pico/pico-sdk/src/boards/include/boards/pico.hPico Platform (PICO_PLATFORM) is 'rp2040'.Defaulting compiler (PICO_COMPILER) to 'pico_arm_cortex_m0plus_gcc' since not specified.Configuring toolchain based on PICO_COMPILER 'pico_arm_cortex_m0plus_gcc'Defaulting PICO_GCC_TRIPLE to 'arm-none-eabi'-- The C compiler identification is GNU 15.1.0-- The CXX compiler identification is GNU 15.1.0-- The ASM compiler identification is GNU-- Found assembler: /opt/homebrew/bin/arm-none-eabi-gcc-- Detecting C compiler ABI info-- Detecting C compiler ABI info - done-- Check for working C compiler: /opt/homebrew/bin/arm-none-eabi-gcc - 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: /opt/homebrew/bin/arm-none-eabi-g++ - skipped-- Detecting CXX compile features-- Detecting CXX compile features - doneBuild type is DebugUsing regular optimized debug build (set PICO_DEOPTIMIZED_DEBUG=1 to de-optimize)-- Found Python3: /opt/anaconda3/bin/python3.12 (found version "3.12.7") found components: InterpreterTinyUSB available at /Users/joshuaimmanuel/pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.Compiling TinyUSB with CFG_TUSB_DEBUG=1BTstack available at /Users/joshuaimmanuel/pico/pico-sdk/lib/btstackcyw43-driver available at /Users/joshuaimmanuel/pico/pico-sdk/lib/cyw43-driverlwIP available at /Users/joshuaimmanuel/pico/pico-sdk/lib/lwipmbedtls available at /Users/joshuaimmanuel/pico/pico-sdk/lib/mbedtlsCMake Warning at /Users/joshuaimmanuel/pico/pico-sdk/tools/Findpicotool.cmake:30 (message):  No installed picotool with version 2.1.1 found - building from source  It is recommended to build and install picotool separately, or to set  PICOTOOL_FETCH_FROM_GIT_PATH to a common directory for all your SDK  projectsCall Stack (most recent call first):  /Users/joshuaimmanuel/pico/pico-sdk/tools/CMakeLists.txt:138 (find_package)  /Users/joshuaimmanuel/pico/pico-sdk/tools/CMakeLists.txt:493 (pico_init_picotool)  /Users/joshuaimmanuel/pico/pico-sdk/src/cmake/on_device.cmake:56 (picotool_postprocess_binary)  blink/CMakeLists.txt:13 (pico_add_extra_outputs)Downloading PicotoolOnly building blink_any for non W boards as PICO_CYW43_SUPPORTED is not setSkipping encrypted example which is unsupported on this platformSkipping hello_dcp example which is unsupported on this platformSkipping runtime_flash_permissions example which is unsupported on this platformSkipping dvi_out_hstx_encoder example which is unsupported on this platformSkipping spi_lcd example which is unsupported on this platformSkipping multicore_doorbell example which is unsupported on this platformSkipping hello_otp example which is unsupported on this platformSkipping boot_info example which is unsupported on this platformSkipping universal examples as PICO_RISCV_TOOLCHAIN_PATH and PICO_ARM_TOOLCHAIN_PATH are not definedSkipping TinyUSB dual examples, as TinyUSB hw/mcu/raspberry_pi/Pico-PIO-USB submodule unavailableSkipping SHA256 examples as pico_sha256 or pico_mbedtls unavailableSkipping FreeRTOS examples as FREERTOS_KERNEL_PATH not defined-- Configuring done (2.6s)-- Generating done (2.1s)-- Build files have been written to: /Users/joshuaimmanuel/pico/pico-examples/cmake-build-debug[Finished]
especially this bit, how do I do what it says:-

Code:

CMake Warning at /Users/joshuaimmanuel/pico/pico-sdk/tools/Findpicotool.cmake:30 (message):  No installed picotool with version 2.1.1 found - building from source  It is recommended to build and install picotool separately, or to set  PICOTOOL_FETCH_FROM_GIT_PATH to a common directory for all your SDK  projects
Thanks AndyD It just so happens that I am also trying to do exactly what you said, to build a C++ GPIO library for the raspberry pi 4B too, so any advice or info with that regards is also very much appreciated :)

Statistics: Posted by Joraspberry — Mon Jun 23, 2025 11:13 am



Viewing all articles
Browse latest Browse all 8609

Trending Articles