ENGLISH

RP2040 Assembly Language Programming: ARM Cortex-M0+ on the Raspberry Pi Pico

Book information

Publisher
Apress
Year
2021
ISBN
148427752X, 9781484277522
Language
english
Format
PDF
Filesize
4 MB (3890006 bytes)
Edition
1
Pages
330\330
Time added
2021-10-28 09:22:33

Description

Learn to program the Raspberry Pi Pico’s dual ARM Cortex M0+ CPUs in Assembly Language. The Pico contains a customer System on a Chip (SoC) called the RP2040, making it the Foundation’s first entry into the low-cost microcontroller market. The RP2040 contains a wealth of coprocessors for performing arithmetic as well as performing specialized I/O functionality. This book will show you how these CPUs work from a low level, easy-to-learn perspective. There are eight new Programmable I/O (PIO) coprocessors that have their own specialized Assembly Language supporting a wide variety of interface protocols. You'll explore these protocols and write programs or functions in Assembly Language and interface to all the various bundled hardware interfaces. Then go beyond working on your own board and projects to contribute to the official RP2040 SDK. Finally, you'll take your DIY hardware projects to the next level of performance and functionality with more advanced programming skills. What You'll Learn • Read and understand the Assembly Language code that is part of the Pico’s SDK • Integrate Assembly Language and C code together into one program • Interface to available options for DIY electronics and IoT projects Who This Book Is For Makers who have already worked with microcontrollers, such as the Arduino or Pico, programming in C or Python. Those interested in going deeper and learning how these devices work at a lower level, by learning Assembly Language. Table of Contents About the Author About the Technical Reviewer Acknowledgments Introduction Chapter 1: How to Set Up the Development Environment About the Raspberry Pi Pico About the Host Computer How to Solder and Wire How to Install Software A Simple Program to Ensure Things Are Working Create Some Helper Script Files Summary Chapter 2: Our First Assembly Language Program 10 Reasons to Use Assembly Language Computers and Numbers ARM Assembly Instructions CPU Registers ARM Instruction Format RP2040 Memory About the GCC Assembler Hello World Our First Assembly Language File About the Starting Comment Where to Start Assembly Instructions Data Program Logic Reverse Engineering Our Program Summary Exercises Chapter 3: How to Build and Debug Programs CMake GNU Make Print Statements GDB Preparing to Debug Beginning GDB Summary Exercises Chapter 4: How to Load and Add About Negative Numbers About Two’s Complement About Raspberry Pi OS Calculator About One’s Complement Big- vs. Little-Endian About Bi-Endian Pros of Little-Endian Cons of Little-Endian How to Shift and Rotate Registers About Carry Flag Basics of Shifting and Rotating Logical Shift Left Logical Shift Right Arithmetic Shift Right Rotate Right Rotate Right Extend How to Use MOV Move Immediate Moving Data from One Register to Another Using Register MOV ADD/ADC Add with Carry SUB/SBC Shifting and Rotating Loading All 32 Bits of a Register MOV/ADD/Shift Example Summary Exercises Chapter 5: How to Control Program Flow Unconditional Branch About the CPSR Branch on Condition About the CMP Instruction Loops FOR Loops While Loops If/Then/Else Logical Operators AND EOR ORR BIC MVN TST Design Patterns Converting Integers to ASCII Using Expressions in Immediate Constants Storing a Register to Memory Why Not Print in Decimal? Performance of Branch Instructions Summary Exercises Chapter 6: Thanks for the Memories How to Define Memory Contents How to Align Data How to Load a Register How to Load a Register with an Address How to Build the Address Directly PC Relative Addressing How to Load Data from Memory Optimizing Small Read-Only Data Access Indexing Through Memory How to Store a Register How to Convert to Uppercase How to Load and Store Multiple Registers Summary Exercises Chapter 7: How to Call Functions and Use the Stack About Stacks on the RP2040 How to Branch with Link About Nesting Function Calls About Function Parameters and Return Values How to Manage the Registers Summary of the Function Call Algorithm More on the Branch Instructions About the X Factor Uppercase Revisited About Stack Frames Stack Frame Example How to Define Symbols How to Create Macros About Include Directive How to Define a Macro About Labels Why Macros? Summary Exercises Chapter 8: Interacting with C and the SDK How to Wire Flashing LEDs How to Flash LEDs with the SDK How to Call Assembly Routines from C How to Embed Assembly Code Inside C Code Summary Exercises Chapter 9: How to Program the Built-in Hardware About the RP2040 Memory Map About C Header Files About the Raspberry Pi Pico Pins How to Set a Pin Function About Hardware Registers and Concurrency About Programming the Pads How to Initialize SIO How to Turn a Pin On/Off The Complete Program Summary Exercises Chapter 10: How to Initialize and Interact with Programmable I/O About PIO Architecture About the PIO Instructions Flashing the LEDs with PIO PIO Instruction Details and Examples JMP WAIT IN OUT PUSH PULL MOV IRQ SET About Controlling Timing About the Clock Divider About the Delay Operand About Side-Set More Configurable Options Summary Exercises Chapter 11: How to Set and Catch Interrupts Overview of the RP2040’s Interrupts About the RP2040’s Interrupts About the Interrupt Vector Table About Saving Processor State About Interrupt Priorities Flashing LEDs with Timer Interrupts About the RP2040 Alarm Timer Setting the Interrupt Handler and Enabling IRQ0 The Complete Program About the SVCall Interrupt Using the SDK Summary Exercises Chapter 12: Multiplication, Division, and Floating Point Multiplication Division About Division and Interrupts Interpolation Adding an Array of Integers Interpolating Between Numbers Floating Point About the Structure of the Boot ROM Sample Floating-Point Program Some Notes on C and printf Summary Exercises Chapter 13: Multiprocessing About Saving Power About Interprocessor Mailboxes How to Run Code on the Second CPU A Multiprocessing Example About Fibonacci Numbers About Factorials The Complete Program About Spinlocks Regulating Access to a Memory Table A Word on the SDK Summary Exercises Chapter 14: How to Connect Pico to IoT About the RP2040’s Built-in Temperature Sensor About Home-Brewed Communication Protocol About the Server Side of the Protocol About the RP2040’s UART Mastering Math Routines Viewing the Main Program About IoT, Wi-Fi, Bluetooth, and Serial Communications Summary Exercises Appendix A: ASCII Character Set Appendix B: Assembler Directives Appendix C: Binary Formats Integers Floating Point Addresses Appendix D: The ARM Instruction Set Answers to Exercises Chapter 2 Chapter 4 Chapter 6 Chapter 9 Chapter 10 Index

Similar books