genuinequality

Download free music MP3s on genuine quality, the world’s largest online music catalogue, powered by your scrobbles. Free listening, videos, photos, The world’s largest online music catalogue, powered by your scrobbles. Free listening, videos, photos, stats, charts, biographies and concerts. stats, charts, biographies and concerts.

Tuesday, October 4, 2022

[New post] Getting Started with the Raspberry Pi Pico C/C++ SDK and TinyUSB MIDI

Site logo image Kevin posted: "I've been meaning to take a proper look at the Raspberry Pi Pico C/C++ SDK for quite some time, but have been putting it off.  With good reason it would appear!  But I've finally got to the start of being able to build the Tiny USB test MIDI application m" Simple DIY Electronic Music Projects

Getting Started with the Raspberry Pi Pico C/C++ SDK and TinyUSB MIDI

Kevin

Oct 4

I've been meaning to take a proper look at the Raspberry Pi Pico C/C++ SDK for quite some time, but have been putting it off.  With good reason it would appear!  But I've finally got to the start of being able to build the Tiny USB test MIDI application myself and so have a good template for moving forward now.

This are the "notes to self" for what I had to do to get up and running, and most importantly, which parts of the documentation were key to getting it all working.

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

These are the key tutorials for the main concepts used in this project:

  • The C/C++ SDK
  • Getting Started with the Raspberry Pi Pico: C/C++ development with Raspberry Pi Pico and other RP2040 based microcontroller boards.
  • Raspberry Pi Pico C/C++ SDK: Libraries and tools for C/C++ development on RP2040 microcontrollers

If you are new to microcontrollers, see the Getting Started pages.

Parts list

  • Raspberry Pi Pico
  • Linux (Ubuntu) installation or virtual machine

Installation

All these instructions assume a Linux-based host.  I'm using Ubuntu in a virtual machine.  I followed the instructions in the Getting Started with the Raspberry Pi Pico guide.

Notes:

  • I didn't use the "pico_setup.sh" script described in Chapter 1 of the guide.
  • I followed the instructions in Chapter 2, which helps me understand a little more what is going on:
    • Get the SDK and the examples using GitHub.
    • Install the toolchain using apt.
  • Build the examples as described in Chapter 3, which helps to verify that everything is installed correctly:
    • Create a build directory.
    • set the PICO_SDK_PATH environment variable.
    • run cmake to create the build environment.
    • run make to perform the build.
  • I've then skipped chapter 4, 5, and 6 for now.  Console output and debugging will be important so I'll come back to those later, but I'm not fussed about using Visual Studio.
  • Now I'm ready to create a project with the environment set up ready to go.

First Tiny USB MIDI Project

There is an example Tiny USB project that builds a MIDI USB device, so I thought I'd start with that.  However there is an issue:

  • All of the Tiny USB examples have a slightly odd build configuration, being designed to be built from within Tiny USB which itself lives within the pico-sdk structure.
  • There are some Raspberry Pi Pico USB examples, but they don't transfer out of the "pico-examples" area and build as stand-alone projects.

So you have to follow the instructions in Chapter 7 of the guide to turn the Tiny USB MIDI example into a Raspberry Pi Pico example into a stand-alone "external" project.  This means doing the following:

  • Create a project area for your new project.  I have everything Pico installed in a pico area, so I've created a pico/src area for my own projects.
  • Copy the following files from pico/pico-sdk/lib/tinyusb/examples/device/midi_test/src:
    • main.c, tusb_config.h, usb_descriptors.c
  • Create a file CMakeLists.txt with the following in it:
cmake_minimum_required(VERSION 3.13) include(pico_sdk_import.cmake) project(picomiditest) pico_sdk_init() add_executable(picomiditest) target_sources(picomiditest PUBLIC     ${CMAKE_CURRENT_LIST_DIR}/main.c     ${CMAKE_CURRENT_LIST_DIR}/usb_descriptors.c )  # Make sure TinyUSB can find tusb_config.h target_include_directories(picomiditest PUBLIC ${CMAKE_CURRENT_LIST_DIR})  # In addition to pico_stdlib required for common PicoSDK functionality, add dependency on tinyusb_device # for TinyUSB device support and tinyusb_board for the additional board support library used by the example target_link_libraries(picomiditest PUBLIC pico_stdlib tinyusb_device tinyusb_board)  # Uncomment this line to enable fix for Errata RP2040-E5 (the fix requires use of GPIO 15) #target_compile_definitions(picomidirouter PUBLIC PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1)  pico_add_extra_outputs(picomiditest)

This is based on the CMakeLists.txt file from the pico/pico-examples/usb/device/dev_hid_composite/CMakeLists.txt file, but with the extra entries needed, as described in Chapter 7 of the guide, to make it build outside of the pico-examples area.  Basically this means the "include(pico_sdk_import.cmake)" and "pico_sdk_init()" lines.  Without these, nothing will build.  Everywhere you see "picomiditest", I'm assuming that is the name of the project directory, the project itself and your build output.  I think they might need to all match, but I'm not sure.

Note copy over the pico_sdk_import.cmake file from pico/pico-sdk/external/ and finally create a build directory.

Your project area should now look something like this:

pico/src/picomiditest/      +--- build      +--- CMakeLists.txt      +--- main.c      +--- pico_sdk_import.cmake      +--- tusb_config.h      +--- usb_descriptors.c

Now the following steps are required.

  1. Create the build environment using cmake.
  2. Build the application.
  3. Plug in a Pico with the boot button pressed.
  4. Copy the resulting picomiditest.uf2 file over to a Raspberry Pi Pico.
$ cd pico/src/picomiditest $ export PICO_SDK_PATH=../../pico-sdk $ cd build $ cmake .. $ make $ cp picomiditest.uf2 /media/RPI_RP2/ $

If all goes well the Pico will come up blinking the LED and if you fire up a MIDI application you should see a Tiny USB device and if you connect to it as a MIDI input you should start receiving MIDI note messages.

Closing Thoughts

I had an initial go at this a number of weeks back, but got stuck trying to setup the CMakeLists.txt file to allow the build system to find all the bits and pieces.  The crucial missing bit of information for me was the fact that the examples won't build outside of the examples area due to extra layers of make information.

As I was attempting to work my way through the Getting Started Guide but with my own application, nothing was working.  What I hadn't realised was that the information I needed I hadn't got to yet. I hadn't noticed that Chapter 7 was dedicated to "Creating your own project".

Just a small note in the example CMakeList.txt files that they are not "stand alone" would have probably been all I needed.  Oh well, now I know and hopefully this blog may help someone else getting going too.

Having spent some time searching online, I've not found anything other than "you're on your own" messages and posts in response to trying to build Tiny USB examples on the Pico.  Whilst frustrating to get there, in the end all the information you'll need is around and actually it isn't too bad!

This is now a good baseline from which I can start building some custom applications.  My starting point will be something for my Pico MIDI Router.

Kevin

Comment
Like
Tip icon image You can also reply to this email to leave a comment.

Unsubscribe to no longer receive posts from Simple DIY Electronic Music Projects.
Change your email settings at manage subscriptions.

Trouble clicking? Copy and paste this URL into your browser:
https://diyelectromusic.wordpress.com/2022/10/04/getting-started-with-the-raspberry-pi-pico-c-c-sdk-and-tinyusb-midi/

Powered by WordPress.com
Download on the App Store Get it on Google Play
Posted by BigPalaceNews at 12:09 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Search This Blog

About Me

BigPalaceNews
View my complete profile

Blog Archive

  • September (70)
  • August (116)
  • July (96)
  • June (100)
  • May (105)
  • April (95)
  • March (131)
  • February (111)
  • January (104)
  • December (98)
  • November (87)
  • October (126)
  • September (104)
  • August (97)
  • July (112)
  • June (113)
  • May (132)
  • April (162)
  • March (150)
  • February (342)
  • January (232)
  • December (260)
  • November (149)
  • October (179)
  • September (371)
  • August (379)
  • July (360)
  • June (385)
  • May (391)
  • April (395)
  • March (419)
  • February (356)
  • January (437)
  • December (438)
  • November (400)
  • October (472)
  • September (460)
  • August (461)
  • July (469)
  • June (451)
  • May (464)
  • April (506)
  • March (483)
  • February (420)
  • January (258)
  • December (197)
  • November (145)
  • October (117)
  • September (150)
  • August (132)
  • July (133)
  • June (117)
  • May (190)
  • January (48)
Powered by Blogger.