Giter Club home page Giter Club logo

pico_template's Introduction

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

pico_template's People

Contributors

gorgonmeducer avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.