Wellys Dev

  • Home
  • Search/Topics
  • Writings
  • About
  • 2022-03-31
    Git: Beginning to Use It (ESP32)

    Where I discuss what to do once you’ve downloaded a repository from Github.

    Introduction

    I’ve advocated using the AVR_C (among others) repository to learn how to use C instead of the Arduino “C++” language. (I write C++ in quotes as while the language used is C++, there are some extensions which some people assume are part of the language, causing more confusion.) In this post, I want to start a short series on using Git as it is extremely helpful, once you begin to develop code. And it becomes mandatory, once you begin using someone’s git repository.

  • 2021

  • 2021-09-01
    Developing in C on the RP2040: First

    Where I explain the issues which impact developing C/C++ code on the RP2040.

    Sources

    • Guide: Getting Started with Pico
    • Raspberry Pi Pico Pinout
    • Pico SDK Documentation
    • GitHub: pico-sdk
    • GitHub: pico-examples

    Introduction

    There are three fundamental steps one must take to fully develop C/C++ code on the RP2040. Both the Raspberry Pi “Getting Started with Pico” known as the Guide from here on and this blog utilize this approach:

    1. Install the tool chain necessary to cross-compile C/C++ and link code for the RP2040 on the platform of choice.
    2. Test #1 using the Raspberry Pi Pico Github code using the pico-sdk and pico-examples.
    3. Advance the ability to debug by adding a hardware debugger in the form of the Picoprobe and gdb.

    For each of the platforms, there is a level of complexity to accomplish each step. Its important to understand that the tools that exist to accomplish cross-compiling and linking C/C++ for an embedded microcontroller are designed for Linux. Therefore, the closer a system “looks like Linux”, the easier it is to follow the three steps. This isn’t a problem. It is simply something to understand and account for. Specifically, the level of difficulty of the three steps in each operating system is:

  • 2021-08-31
    Developing in C on the RP2040: Windows

    Where I begin to develop code in C on the RP2040 in the Windows environment.

    Sources

    • Raspberry Pi Pico SDK: Raspberry Pi Pico SDK
    • Getting Started with Pico
    • Raspberry Pi Pico Pinout
    • Shawn Hymel on Digikey
    • Git Bash Tutorial

    Download Sources

    • GNU Arm Embedded Toolchain
    • MinGW Downloads
    • Python Downloads
    • CMake Downloads
    • Putty
    • Notepad++

    Introduction

    If you haven’t read it, please read Read This First… before you continue.

    As I have said before, I do not like to use VS Code, nor do I believe that it is a good tool for students beginning to learn how to develop embedded C. My approach will be to follow that of Shawn Hymel’s without the VSCode part as well as what has already been published via the Guide. In the place of VS Code, we will use Notepad++.

  • 2021-08-25
    Developing in C on the RP2040: New Project

    Where I demonstrate bringing up a new project in C on the PR2040 including embedding project information in the binary.

    Sources

    • Guide: Getting Started with Pico - Review Chapt 8 and Appendix B
    • Raspberry Pi Pico Pinout
    • GitHub: PicoTool

    Introduction

    You have played with the examples the Raspberry Foundation has thoughtfully provided. Now you want to create something on your own! I like the information provided by the Foundation as to how to create a project and how to add easily binary information to the binary code of project. This means you can build a project, write pin information to the binary and then pick up the board weeks(months?) later and determine what is on the board and how to use it.

  • 2021-08-22
    Debugging in C Code on the RP2040: Using gdb - Hints

    Where I provide hints on using gdb to debug code on the RP2040 (Pi Pico board).

    Sources

    • Raspberry Pi Pico SDK: Raspberry Pi Pico SDK
    • Raspberry Pi Pico Pinout
    • GDB Documentation
    • Guide to Faster, Less Frustrating Debugging - Norman Matloff
    • gdb Resources

    gdb Hints

    1. gdb recommended in its screen feedback to use “target extended-remote :3333” instead of the Guide’s “target remote localhost:3333”. I found that this seemed to solve some of these inconsistencies, so I updated my instructions. After a bit of reading “extended-remote” does seem to be the right instruction. Note: If using Bloom and avr-gdb, extended doesn’t serve a purpose, use target remote:1442.
    2. If you find your self executing a lengthy command quite a bit (such as “monitor reset init”), use “define” to create a shorter command for it. If you put it into the .gdbinit file (as I have), it will remember from session to session.
    3. gdb can be incredibly easy to use. Norman Matloff’s tutorial is great for illustrating the commands needed. I recommend reading and practicing with it, its well worth it!
    4. Start with using gdb to replace printf statements. Run code, have it stop by using a “breakpoint function name” or “breakpoint line number”, then use “print” or “display” to get the values of variables. This will work the same as inserting print statements, however, it doesn’t affect your code.
    5. It took me less time to learn gdb, and write these two tutorials than the time I spent attempting to debug Visual Studio Code. Your mileage may vary, however, a simple gdb/code editor setup is fast and easy to learn and use.
    6. If your code ends, you will see “exit(status=0)….”. To restart the program, simply issue a “mri” (a command from .gdbinit) which will reset the processor. Press “c” and the program will begin running again.
    7. gdb operates in at least two modes:
      • command, indicated by (gdb) prompt. This is where you will enter all of the commands to interact with gdb
      • execution, indicated by a lack of a (gdb) prompt. This means the program is running and hitting a breakpoint or watchpoint will return you back to command mode. Or you can hit Ctrl-C which will interrupt the process and put into command mode.
    8. Enter the command layout src or start by using gdb –tui and the window will divide into two horizontal windows. The top window will show 20 lines of source and the bottom window will continue to be the command window. This is a great way to view a breakpoint. For example, set a breakpoint on a function name, then “n(ext)” through the code to view execution. Once you have entered “n”, you can simply hit the return key and it will advance using the next command.
    9. Note found elsewhere, I’ll link to it when I find it: “remember to use -g only for the image you pass to gdb, not the firmware you load into the device (if it can grok elf). Also another very critical prerequisite for C programs is -O0 (which is usually default). But if you use -Os or something, you can get very unpredictable debugging results. This btw. makes debugging some code on avrs for example almost impossible, as they often rely on -Os to fit the image in there. But.. it is very possible and comfy to debug simple optimized C programs in assembly, if you know roughly what to expect. Use objdump -dS on the optimized .elf file with debugging info and you’ll roughly see what assembly code was produced for what C code.”
  • 2021-08-21
    Debugging in C Code on the RP2040: Using gdb - Setup

    Where I show a simple method of using gdb to debug code on the RP2040 (Pi Pico board).

    Sources

    • Raspberry Pi Pico SDK: Raspberry Pi Pico SDK
    • Raspberry Pi Pico Pinout
    • GDB Documentation
    • Guide to Faster, Less Frustrating Debugging - Norman Matloff
    • gdb Resources

    Setup .gdbinit

    The Guide recommends at the very least, add “target remote localhost:3333” to your .gdbinit file. To make our edit/compile/link/load round trip easy, I recommend the following for your .gdbinit:

  • 2021-08-20
    Developing in C on the RP2040: Linux

    Where I begin to develop code in C on the RP2040.

    Sources

    • Raspberry Pi Pico SDK: Raspberry Pi Pico SDK
    • Raspberry Pi Pico Pinout
    • Getting Started with Pico
    • Shawn Hymel on Digikey

    Introduction

    I like using Forth to develop code on embedded microcontrollers, however at times, I’ll have a project that requires a more supportive framework. In this case, C is a superior choice if I need the execution speed of Forth and the framework of microPython. This requires a significant investment in building the tools required and skills to use those tools, to develop in C.

  • 2021-03-20
    gdb Resources

    All of the resources found related to gdb (particularly, related to the RP2040) and how to use it.

    GNU gdb documentation

    • GDB: The GNU Project Debugger
    • Online User Manual: Debugging with GDB
    • PDF User Manual: Debugging with GDB

    gdb Tutorials

    • Guide to Faster, Less Frustrating Debugging
    • CSE 351: GDB (Gnu DeBugger)
    • Quick Guide to gdb: The GNU Debugger
    • Beej’s Quick Guide to GDB
    • gdb Debugger Tutorial
    • gdb Tutorial Site
    • Hackaday: LOCAL AND REMOTE DEBUGGING WITH GDB
    • Hackaday: BEGINNER’S LOOK AT ON-CHIP DEBUGGING
    • 8 gdb tricks you should know
    • Debugging Firmware with GDB
    • GDB — Basics
    • 10 Things You Can Only Do With gdb
    • GDB Tutorial: Some Cool Tips to Debug C/C++ Code
    • Advanced GDB Usage

    Cheat Sheets

    • YoLinux: GNU GDB Debugger Command Cheat Sheet

    Tools to enhance gdb

    • gdb-dashboard
    • pyrsp: simple wrapper around the GDB Remote serial protocol
    • gdbundle - GDB and LLDB’s Missing Plugin
    • Visual debugging using gdbgui

    AVR gdb

    • AVR-GDB Tutorial
    • avr-gdb Notes
    • man avarice

    AVR gdb Notes

    1. Check the version number on avr-gdb as of December 2021, it is 11.1. On Ubuntu, the latest version is 8.1 from 2018 which had quite a few bugs. Attempted to build it manually (which failed), so I spun up a Manjaro (Arch Linux) instance to get the latest. Crazy, I know.
    2. Start avarice in a separate window using, then launch gdb in another window:
      avarice -g -w -d -P atmega328p :3333 	# window 1
      avr-gdb -tui							# window 2
    3. If avarice crashes on startup, cycle power on both the debugger (Dragon) and the target (Uno)

    Pico (RP2040) gdb

    • Debugging the BBC micro:bit with pyOCD and GDB
    • Raspberry Pico: Simple Debugging with just one Device
    • Pico-debug
    • PicoReg: real-time diagnostics for the Pi Pico using SWD
  • 2021-03-01
    C: Developing in C on the RP2040

    A set of entries which comprise a course for learning how develop C programs for the RP2040.

    Entries

    1. Developing in C on the RP2040: Read First
    2. Developing in C on the RP2040: Linux
    3. Developing in C on the RP2040: macOS
    4. Developing in C on the RP2040: Windows
    5. Developing in C on the RP2040: Using gdb - Setup
    6. Developing in C on the RP2040: Using gdb - Hints
    7. Developing in C on the RP2040: New Project
    8. Developing in C on the RP2040: Using gdb - Deep Dive
    9. Developing in C on the RP2040: Exploring Blink
Page 2 of 2
Copyright © 2025 Lief Koepsel
  • Home
  • Search/Topics
  • Writings
  • About