An MDK template for Raspberry Pi Pico

Overview

Pico_Template (v1.0.0)

An MDK template for Raspberry Pi Pico

  • Compiler: Arm Compiler 6.15 and above (Using non-intrusive wrapper to support pico-sdk which is written in GCC)
  • It works as you wanted!
  • Compatible with CMSIS 5.7.0 and CMSIS 5.8.0
  • Verified with Arm Compiler 6.15 and above.
  • Provide users an option to use the stdio solution from pico-sdk (by default) or retarget the stdin/stdout to a user specified location directly. (See note in env_wrapper.c).
  • Support debug in MDK using J-Link
  • Add dedicated project configurations for:
    • [AC6-flash] Running code in Flash (XIP)
    • [AC6-RunInSRAM] Running code in SRAM (code is still stored in FLASH)
    • [AC6-DebugInSRAM] No Flash is used and only suitable for RAM based debug.

How to Use

1. Get the Pico_Template

I assume that you have the MDK installed on your PC. Please clone the Pico_Template with following command line:

mkdir pico-mdk
cd pico-mdk

git clone https://github.com/GorgonMeducer/Pico_Template .

git submodule update --remote --init

Instead of using git clone, if you download a release package, then you have to download the pico-sdk and perf_counter manually and put them into the corresponding folder:

submodules URL Directory
pico-sdk https://github.com/raspberrypi/pico-sdk ROOT\Pico-sdk\
perf_counter https://github.com/GorgonMeducer/perf_counter ROOT\project\mdk\perf_counter

2. Use the Template

The MDK project could be found in the path "ROOT\project\mdk". I assume you know how to use MDK for normal compilation.

2.1 How to set the Stack and Heap size

Usually, people want to adjust the size of stack and heap, and it is very easy in this template. Please find the file "RP2040.sct" in the same MDK project directory. Find the macro STACK_0_SIZE for stack and HEAP_0_SIZE for the heap.

#define STACK_0_SIZE        (1024*4)
#define STACK_1_SIZE        (1024*1)

#define HEAP_0_SIZE         (1024*32)
#define HEAP_1_SIZE         (1024*1)

NOTE:

  1. Please do NOT add "u" behind those constant values.
  2. The STACK_1_SIZE and HEAP_1_SIZE are not in use. You can set their value to reasonable smaller ones if you do want to reduce the RAM footprint.

2.2 How to retarget stdout/stdin

To take advantage of pico-sdk, this template uses bridges to retarget low level functions of stdout/stdin to _read and _write implemented by stdio.c inside pico-sdk.

/*----------------------------------------------------------------------------*
 * bridge the Arm Compiler's stdio and the pico-sdk's stdio                   *
 *----------------------------------------------------------------------------*/
__attribute__((weak))
int stdin_getchar(void)
{
    /*! \note If you don't want to use pico-sdk stdio, then you can implement 
     *!       function by yourself in other c source code. Your scanf will work
     *!       directly.
     *!       by default, we use this function to bridge the _read implemented 
     *!       in stdio.c of pico-sdk
     */
    
    int byte;
    _read(0, (char *)&byte, 1);
    return byte;
}

__attribute__((weak))
int stdout_putchar(int ch)
{
    /*! \note If you don't want to use pico-sdk stdio, then you can implement 
     *!       function by yourself in other c source code. Your printf will work
     *!       directly.
     *!       by default, we use this function to bridge the _write implemented 
     *!       in stdio.c of pico-sdk
     */
    
    return _write(1, (char *)&ch, 1);
}

Those bridge functions are decorated as "weak", hence if you want to retarget printf/scanf directly to a place where you can "see through" and/or you have total control, please implement those bridge functions (without delete the weak version) in one of your c source code, for example, sending chars to USART or storing them to a memory block directly.

NOTE: I try to provide you the freedom of choice, and I don't need you to digging deep inside scripts to gain such freedom.

Known issue

  • Debugger support is only available for J-Link.

  • Not all peripheral modules are added to the compilation. But I guess it is just a piece of cake for you : P

  • Please use the elf2uf2 tool in this template to convert the generated axf into uf2.

  • Might need more documents...

  • for Debug-In-SRAM feature, the correct sequence should be:

    • Load image to SRAM

    • configure the watchdog scratch registers with following content

      // - Scratch 4: 0xb007c0d3

      // - Scratch 5: Entry point ^ -0xb007c0d3

      // - Scratch 6: Stack pointer

      // - Scratch 7: Entry point

    • Issue a reset

You might also like...
A laser cut Dreamcast Pop'n Music controller and integrated memory card using the Raspberry Pi Pico's Programmable IO
A laser cut Dreamcast Pop'n Music controller and integrated memory card using the Raspberry Pi Pico's Programmable IO

Dreamcast Pop'n Music Controller Using Raspbery Pi Pico (RP2040) Intro This is a homebrew controller for playing the Pop'n Music games on the Sega Dre

Web Server based on the Raspberry Pico using an ESP8266 with AT firmware for WiFi
Web Server based on the Raspberry Pico using an ESP8266 with AT firmware for WiFi

PicoWebServer This program runs on a Raspberry Pico RP2040 to provide a web server when connected to an Espressif ESP8266. This allows the Pico to be

Raspberry Pi Pico Arduino core, for all RP2040 boards
Raspberry Pi Pico Arduino core, for all RP2040 boards

Arduino-Pico Raspberry Pi Pico Arduino core, for all RP2040 boards This is a port of the RP2040 (Raspberry Pi Pico processor) to the Arduino ecosystem

A programming environment for Lua for the Raspberry Pi Pico microcontroller

picolua A programming environment for Lua for the Raspberry Pi Pico microcontroller. Version 0.3, April 2021 What is this? picolua is a proof-of-conce

a little hobby raspberry pi pico emulator

PICO-EMU a little raspberry pi pico emulator note: we use the provided bootrom from raspberry pi at the repo: https://github.com/raspberrypi/pico-boot

Raspberry Pi Pico AutoHotkey Streamdeck / Keyboard with LEDs

Raspberry Pi Pico AutoHotkey Streamdeck / Keyboard with LEDs

A FAT filesystem with SPI driver for SD card on Raspberry Pi Pico
A FAT filesystem with SPI driver for SD card on Raspberry Pi Pico

no-OS-FatFS-SD-SPI-RPi-Pico Simple library for SD Cards on the Pico At the heart of this library is ChaN's FatFs - Generic FAT Filesystem Module. It a

Enable LoRaWAN communications on your Raspberry Pi Pico or any RP2040 based board. 📡

pico-lorawan Enable LoRaWAN communications on your Raspberry Pi Pico or any RP2040 based board using a Semtech SX1276 radio module. Based on the Semte

PACMAN for Raspberry Pi Pico (QVGA LCD)
PACMAN for Raspberry Pi Pico (QVGA LCD)

PACMAN for Raspberry Pi Pico ラズベリーPi PicoにQVGAの液晶を接続して動作する本格的なパックマンです。 小型スピーカーを接続して音声も鳴らせます。 とてもシンプルな回路なので、簡単に製作することができます。 液晶は240x320ドット、コントローラにILI934

Comments
  • Debugging with hardware debugger

    Debugging with hardware debugger

    I currently in possession of a ULINK2 debugger, do you have any idea on how to debug a pi pico with it? Right now i've got it to detect the arm core but every time i attempt to debug it says "invalid ROM table"

    opened by alexm622 2
Releases(v1.7.2)
  • v1.7.2(Dec 8, 2022)

  • v1.7.0(Jun 30, 2022)

  • v1.6.1(May 18, 2022)

  • v1.6.0(Feb 19, 2022)

  • v1.5.0a(Jan 4, 2022)

    • Add a dedicated configuration AC6-DebugInSRAM-printf
      • It retargets all printf output into the 'Debug (printf) Viewer' inside MDK via EventRecorder. Debug_printf_Viewer

      • Improve debug experience.

    • Other minor updates.
    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Nov 9, 2021)

  • v1.3.2(Sep 27, 2021)

    • Fixed the "cannot stop at main()" issue
    • Add the "Reset Pico" button to the "AC6-flash" and "AC6-RunInSRAM" configurations
    • Fixed a potential SP crash issue.
    • Find a workaround for a "crash after reset" issue in the "DebugInSRAM" configuration.
    • Other minor changes.
    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(Sep 27, 2021)

  • v1.2.2(Sep 19, 2021)

    • Fixed the 'RESET' issue found in the 'DebugInSRAM' configuration. Rather than using the normal reset, please click the button 'Reset Pico' instead (as shown below). Reset_Pico
    • Fixed an issue found in wrapper/real scheme.
    • Other minor changes.
    Source code(tar.gz)
    Source code(zip)
  • v1.1.1(Sep 18, 2021)

  • v1.0.0(Sep 9, 2021)

    This is an important milestone of Pico-Template with the following features:

    • Using Arm Compiler 6 that pico-sdk has NO official support.
      • To gain up to date performance and/or code size in code generation
      • Support Arm Compiler 6.15 and above
    • Use RTE to access the latest CMSIS-Packs
      • The latest CMSIS 5.8.0
      • Various middleware available in Pack-Installer
      • Support Retargeting printf via RTE
    • Ease to Use
      • Using MDK (old but familiar IDE)
      • No requirement on other tools, i.e. cmake, makefile, python etc.
      • Has a customised built-in elf2uf2 tool which has stage2-boot support
    • Support Debug inside MDK using J-Link
    • Support various memory layouts
      • Running code in external flash
      • Running code in SRAM (and the code is still stored in external flash)
      • Debug in SRAM
    Source code(tar.gz)
    Source code(zip)
  • v0.9.4(Jul 29, 2021)

    • Provide users an option to use the stdio solution from pico-sdk (by default) or retarget the stdin/stdout to a user specified location directly. (See note in env_wrapper.c).
    • Support debug in MDK using J-Link
    • Add dedicated project configurations for:
      • [AC6-flash] Running code in Flash (XIP)
      • [AC6-RunInSRAM] Running code in SRAM (code is still stored in FLASH)
      • [AC6-DebugInSRAM] No Flash is used and only suitable for RAM based debug.
    Source code(tar.gz)
    Source code(zip)
  • v0.9.2(Jul 17, 2021)

    • Improve compatibility with CMSIS 5.7.0 and CMSIS 5.8.0
    • Improve compatibility with Arm Compiler 6.15 and above
    • Add a few peripheral drivers to the project template
    • Other minor changes
    Source code(tar.gz)
    Source code(zip)
  • v0.9.0(Jul 16, 2021)

    • A workable MDK project template
    • Using the CMSIS coming from the RTE
    • No debug support
    • Automatically generate uf2 file after each compilation.
    • Add perf_counter
    Source code(tar.gz)
    Source code(zip)
Owner
Gabriel Wang
A firmware programmer who likes to try crazy ideas in a constrained environment. A finite-state-machine programming hobbyist. A cat person.
Gabriel Wang
Breakout game for Raspberry Pi Pico with Pimoroni Pico Display pack

breakout_rpi_pico Breakout game for Raspberry Pi Pico with Pimoroni Pico Display pack Prebuilt binary (breakout.uf2) is here. To build your own binary

null 19 Oct 15, 2022
Pico-uart-bridge - Raspberry Pi Pico UART-USB bridge

Raspberry Pi Pico USB-UART Bridge This program bridges the Raspberry Pi Pico HW UARTs to two independent USB CDC serial devices in order to behave lik

Álvaro Fernández Rojas 156 Dec 23, 2022
Digital rain animation gif with glow squeezed into a raspberry pi pico and pimoroni pico-display

pico-display-matrix Digital rain animation gif with glow squeezed into a raspberry pi pico and pimoroni pico-display or how to actually use all Flash

null 32 Sep 10, 2022
Prueba del Raspberry PI PICO con un display Raspberry PI TFT 3.5"

Raspberry-PI-PICO-display-RPI35 Prueba del Raspberry PI PICO con un display Raspberry PI TFT 3.5" Con ayuda de la libreria https://github.com/khoih-pr

null 1 Nov 10, 2021
Raspberry Pi Pico (RP2040) and Micro-ROS (ROS 2) Integration

The Pico is an amazing microcontroller and I couldn't wait for ROS 2 support or Arduino Core, so here is my approach. Once the Arduino Core for RP2040 is out it will be easier to use micro_ros_arduino.

Darko Lukić 19 Jun 19, 2022
built-in CMSIS-DAP debugger tailored especially for the RP2040 “Raspberry Pi Pico”

RP2040 has two ARM Cortex-M0+ cores, and the second core normally remains dormant. pico-debug runs on one core in a RP2040 and provides a USB CMSIS-DAP interface to debug the other core. No hardware is added; it is as if there were a virtual debug pod built-in.

null 272 Dec 30, 2022
🦠 µnix is a UNIX-like operating system for the raspberry pi pico.

The µnix Operating System "µnix", "munix" or, "micro unix" aims to be a micro kernel based operating system targeting the Raspberry Pi Pico. "µnix" is

Sleepy Monax 57 Dec 11, 2022
Fractal rendering for Raspberry Pi Pico microcontroller

picofract Mandelbrot Set rendering demo for Raspberry Pi Pico microcontroller with Pico Display Pack. Building If you already have the Pimoroni SDK bu

null 22 Dec 7, 2022
Arduino API for the Raspberry Pico

Raspberry PI Pico - Arduino API On Friday I was receiving my Raspberry PI Pico and I had the opportunity to play around with it. Actually most of the

Phil Schatzmann 59 Jan 2, 2023
x86 emulator on Raspberry Pi Pico

picox86 x86 emulator on Raspberry Pi Pico https://user-images.githubusercontent.com/10139098/110543817-13299080-812b-11eb-9c88-674cdae919fc.mp4 PCB fr

null 39 Nov 9, 2022