element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi Projects
  • Products
  • Raspberry Pi
  • Raspberry Pi Projects
  • More
  • Cancel
Raspberry Pi Projects
Blog Lean C++ Stream library for Pico
  • Blog
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 17 Dec 2023 5:56 AM Date Created
  • Views 862 views
  • Likes 9 likes
  • Comments 1 comment
  • pico
  • raspberry_pi_projects
  • c++
Related
Recommended

Lean C++ Stream library for Pico

Jan Cumps
Jan Cumps
17 Dec 2023

A lean alternative for the C++ IOStream library, sized for embedded systems

The standard IOStream library works great on a Pico, but inflates the code size. In a 2022 CppCon talk "Modern C++ to Impress Your Embedded Dev Friends", Steve Bush presented a lightweight alternative: a FileStream that's perfectly sized for embedded use.

I ported it for Pico. It supports streaming to the Pico stdio supported COM ports: the Pico's USB, a PicoProbe's USB, or the Pico's UART0.

image

Usage example:

#include <stdio.h>
#include "pico/stdio.h"

#include "filestream.hpp"



namespace mcu
{
    FileStream debug(1);
}


int main(int, char** )
{
    stdio_init_all();

    mcu::debug << "Hello, world!\r\n";

    mcu::debug << mcu::FileStream::RadixEnum::Hexadecimal << 6 << "\r\n";

    while (true) continue;
}

To use it in your C++ project, you just add a few lines to your CMake file:

# add_subdirectory()
pico_add_subdirectory(lean_stream_io)

# ...

target_link_libraries(${CMAKE_PROJECT_NAME}
        pico_stdlib
        lean_stream_io
        )

# adjust to enable stdio via usb, or uart
pico_enable_stdio_usb(${CMAKE_PROJECT_NAME} 0)
pico_enable_stdio_uart(${CMAKE_PROJECT_NAME} 1)

Github repository, with example program: https://github.com/jancumps/pico-lean-stream-io

Steve Bush CppCon 2022 talk: Modern C++ to Impress Your Embedded Dev Friends

The code is Steve's original code written for the conference. I provided an implementation of the _write() function that uses the Pico.C SDK stdio functionality.

Steve Bush referenced material:

  • original github project for STM32L476RG Nucleo development board: 
    https://github.com/sgbush/cppcon2022/tree/release/code/sections/4_lean_stream_io
  • presentation used in the talk: https://github.com/CppCon/CppCon2022/blob/main/
  • video (the topic is discussed at minute 31): 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • Sign in to reply
  • DAB
    DAB over 1 year ago

    Nice update Jan.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube