Page
1
MAKER INNOVAT IONS SER I ES RP2040 Assembly Language Programming Including the RP2350 and Raspberry Pi Pico 2 — Second Edition — Stephen Smith
Page
3
Jump start your path to discovery with the Apress Maker Innovations series! From the basics of electricity and components through to the most advanced options in robotics, Machine Learning, and even the metaverse, you’ll forge a path to building ingenious hardware and controlling it with cutting-edge software. All while gaining new skills and experience with common toolsets you can take to new projects or even into a whole new career. The Apress Maker Innovations series offers project-based learning with a strong foundation in theory and best practices. So you get hands- on experience while also learning the key concepts, terminology, and creative processes that professionals such as entrepreneurs, inventors, and engineers, use when developing and executing hardware projects. You can learn to design circuits, program AI, create IoT systems for your home or even city, or build immersive environments for the Metaverse. Each book provides the building blocks to bring your ideas to life, and so much more! Whether you’re a beginning hobbyist or a seasoned entrepreneur working out of your basement or garage, you’ll scale up your skillset to become a hardware design and engineering pro. And often using low-cost and open-source software such as Raspberry Pi, Arduino, PIC microcontroller, and Robot Operating System (ROS). Programmers and software engineers will also find opportunities to expand their skills, as many projects use popular languages and operating systems like Python and Linux. If you want to build a robot, set up a smart home, assemble a weather- ready meteorology system, create a brand-new circuit using breadboards and design software, or even build anything with LEGO, this series has all that and more! Written by creative and seasoned Makers, every book tackles both tested and leading-edge approaches and technologies, for bringing your visions and projects to life. More information about this series at https://link.springer.com/ bookseries/17311
Page
4
RP2040 Assembly Language Programming Including the RP2350 and Raspberry Pi Pico 2 Second Edition Stephen Smith
Page
5
RP2040 Assembly Language Programming: Including the RP2350 and Raspberry Pi Pico 2, Second Edition ISBN-13 (pbk): 979-8-8688-2201-8 ISBN-13 (electronic): 979-8-8688-2202-5 https://doi.org/10.1007/979-8-8688-2202-5 Copyright © 2026 by Stephen Smith This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Miriam Haidara Project Manager: Jessica Vakili Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a Delaware LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress. com/979-8-8688-2201-8. For more detailed information, please visit https://www.apress.com/ gp/services/source-code. If disposing of this product, please recycle the paper Stephen Smith Gibsons, BC, Canada
Page
6
This book is dedicated to my beloved wife and editor, Cathalynn Labonté-Smith.
Page
7
(This page has no text content)
Page
8
(This page has no text content)
Page
9
(This page has no text content)
Page
10
(This page has no text content)
Page
11
(This page has no text content)
Page
12
(This page has no text content)
Page
13
(This page has no text content)
Page
14
(This page has no text content)
Page
15
(This page has no text content)
Page
16
xvii Stephen Smith is the author of the Apress titles Raspberry Pi Assembly Language Programming and Programming with 64- Bit ARM Assembly Language. He is a retired software architect, located in Gibsons, BC, Canada. He’s been developing software since high school, or way too many years to record. He was the chief architect for the Sage 300 line of accounting products for 23 years. Since retiring he has pursued Artificial Intelligence; earned his Advanced HAM Radio License; enjoys mountain biking, hiking, and nature photography; and is a member of the Sunshine Coast Search and Rescue group. He continues to write his popular technology blog at smist08.wordpress.com and has written two science fiction novels in a series, Influence and Unification, available on Amazon.com. About the Author
Page
17
xix Stewart Watkiss is a keen maker, programmer, and author of Learn Electronics with Raspberry Pi. He studied at the University of Hull, where he earned a master’s degree in electronic engineering, and more recently at Georgia Institute of Technology, where he earned a master’s degree in computer science. Stewart also volunteers as a STEM ambassador, helping teach programming and physical computer to school children and at Raspberry Pi events. He has created a number of resources using Pygame Zero, which he makes available on his website (www.penguintutor.com). About the Technical Reviewer
Page
18
xxi No book is ever written in isolation. I want to especially thank my wife, Cathalynn Labonté-Smith, for her support, encouragement, and expert editing. I want to thank all the good folk at Apress who made the whole process easy and enjoyable. A special shout-out to Jessica Vakili, my coordinating editor, who kept the whole project moving quickly and smoothly. Thanks to Stewart Watkiss, my technical reviewer, who helped make this a far better book. Acknowledgments
Page
19
xxiii Introduction There is an explosion of DIY electronics projects, largely fueled by Arduino- based microcontrollers and Raspberry Pi computers. Electronics projects have never been easier to build, with hundreds of inexpensive modular components to choose from. People design robots, home monitoring and security systems, game devices, musical instruments, audio systems, and lots more. The Raspberry Pi Pico is the Raspberry Pi Foundation’s entry into the Arduino-style microcontroller market. A regular Raspberry Pi computer runs Linux and typically costs from $35 to $100 depending on memory and accessories. The Raspberry Pi Pico costs $4 and doesn’t run an operating system. To power the Raspberry Pi Pico, the Raspberry Pi Foundation designed a custom System on a Chip (SoC), called the RP2040, containing dual ARM Cortex-M0+ CPUs along with a raft of device controller components. This combination of a powerful CPU and ease of integration has made this a great choice for any DIY project. Further, Raspberry sells the RP2040 chips separately, and other companies such as Seeed Studio, Adafruit, and Pimoroni are selling their own versions of this microcontroller with extra built-in features like Bluetooth or Wi-Fi. The RP2040 chips can even be purchased for approximately $1 each to build your own board. At the basic level, how are these microcontrollers programmed? What provides the magical foundation for all the great projects that programmers build with them? Raspberry provides a Software Developer’s Kit (SDK) for C programmers as well as support for programming in MicroPython. This book answers these questions and delves into how these are programmed at the bare metal level and provides insight into the RP2040’s architecture.
Page
20
xxiv Assembly Language is the native, lowest-level way to program a computer. Each processing chip has its own Assembly Language. This book covers programming the ARM Cortex-M0+ 32-bit Processor. To learn how a computer works, learning Assembly Language is a great way to get into the nitty-gritty details. The popularity and low cost of microcontrollers like the Raspberry Pi Pico provide ideal platforms to learn advanced concepts in computing. Even though all these devices are low-powered and compact, they’re still sophisticated computers with a multi-core processor, programmable I/O processors, and integrated hardware controllers. Anything learned about these devices is directly relevant to any gadget with an ARM processor that by volume is the number one processor on the market today. In this book, how to program ARM Cortex-M0+ processors at the lowest level, operating as close to the hardware as possible, is covered. How to do the following will be learned: • Format instructions and combine them into programs, as well as the formats of operative binary data. • Program the built-in programmable I/O, division, and interpolation coprocessors. • Control the integrated hardware devices by reading and writing to the hardware control registers directly. • Interact with the RP2040 SDK. The simplest way to learn these tasks is with a Raspberry Pi Pico connected to a Raspberry Pi running the Raspberry Pi OS, a version of Linux. This provides all the tools needed to learn Assembly Language programming. All the software required for this book is open source and readily available on the Raspberry Pi. InTroduCTIon