RP2040: the Raspberry Pi microcontroller for machine learning

RP2040

Raspberry Pi Foundation has been launching more than just its SBC boards, with some interesting hardware add-ons. Maybe one that is not as well known as the Raspberry Pi, it is important to treat the RP2040 chip, an interesting device for makers who are interested in AI and machine learning.

In this article we will discuss this in depth. perfect complement to the famous SBC.

What is the RP2040?

Raspberry Pi Ltd designed a circuit called RP2040, which was presented in January 2021 as part of the new Raspberry Pi Pico SBC board that this entity launched on the market. This RP2040 chip is nothing more than a 32-bit microcontroller chip with a dual core ARM Cortex-M0+.

The ARM Cortex-M0+ is a CPU core specially designed for applications in embedded systems and microcontrollers. Its 32-bit architecture provides improved performance compared to 8-bit or 16-bit architectures. In addition, it stands out for being a low-power processor, which makes it ideal for battery-powered devices and other applications that require energy efficiency.

This core uses Thumb-2 instruction extensions, a combination of 16-bit and 32-bit instructions that improves code density and performance in memory-constrained applications. With a three-stage pipeline, it achieves efficient execution of instructions, maintaining a balance between performance and power consumption.

The ARM Cortex-M0+ incorporates a efficient interrupt handler to manage real-time events and tasks effectively. Designed to offer reasonable performance at a competitive cost, this core is commonly found implemented in microcontrollers used in a variety of embedded devices, from control systems to home appliances and medical devices.

It thus became the first microcontroller designed by Raspberry Pi, although the IP core was completely designed by Arm. Its low cost allowed it to be integrated into the Raspberry Pi Pico SBC, with a price of only approximately $4, since the IC cost only $1.

This RP2040 chip can be programmed to operate using various programming languages. One of them can be the ARM assembler, another C, C++, Free PASCAL, Rust, Go, MicroPython, CircuitPython, Ada, etc. Furthermore, which is where it draws the most attention, it is powerful enough to run TensorFlow Lite for AI applications.

TensorFlow Lite is a lightweight and efficient version of TensorFlow, a popular machine learning framework developed by Google. Designed specifically for mobile devices, embedded systems, and resource-constrained environments, TensorFlow Lite enables you to run machine learning models on platforms with memory and computing power constraints. Provides tools for converting models trained on standard TensorFlow to a mobile-friendly format, making it easier to deploy AI applications on smartphones, microcontrollers, and other devices with limited computational capabilities. TensorFlow Lite is a versatile solution for deploying machine learning models on Edge and IoT devices, enabling fast and efficient inferences locally, without depending on cloud connections.

Continuing with the topic of RP2040, it must be said that this chip has been integrated into several SBC boards from various manufacturers, such as Adafruit, Arduino, SparkFun, Pimoroni, etc. On the Raspberry Pi, it provides important features at a low price. For example, it has been used for the Raspberry Pi Pico and Pico W, Arduino Nano RP2040, Pimoroni Tiny RP2040, Adafruit Micro, SparkFun Pro Micro, etc.

RP2040 Specifications

As for the RP2040 technical specifications, we can find the following:

  • Chip manufactured with a 40 nm node or process in the TSMC foundry.
  • Packaged in 7x7mm QFN type with 56 contacts and for surface mounting or SMD.
  • ARM Cortex-M0+ dual-core CPU at 133 Mhz, with overclocking support. Each core has a peripheral integer divisor and two interpolators.
  • It implements a fast SRAM memory of 264 KB capacity, with 6 independent banks, four of 64 KB and two of 4 KB.
  • It does not have flash memory or internal EEPROM, therefore, after the reset or shutdown, the boot-loader is lost and will be loaded through the external firmware.
  • QSPI bus controller, supporting up to 16 MB of external flash memory.
  • DMA or direct memory access controller.
  • AHB crossbar, fully connected.
  • LDO (Low-Dropout Regulator) integrated on-chip and programmable to generate the core voltage.
  • Dual PLLs integrated into the chip to generate the core clocks and also the USB frequency.
  • 30 GPIO with 4 as optional use of analog inputs.
  • Peripheral support with controllers: 2x UARTs, 2x SPI, 2x I2C, 16x PWM, USB 1.1, PHY and 8 PIO or programmable output pins for machine states.

Uses or applications

The RP2040 chip has become the cornerstone of numerous projects and products due to its versatility and outstanding capabilities. Has found applications on a variety of devices and embedded systems, opening a range of possibilities for different users.

One of its common uses is in the field of development of electronics projects, being particularly appreciated by enthusiasts and professionals for creating custom devices thanks to its low cost and processing capacity. Additionally, it has had a significant impact on computer science education, being used in educational settings to teach programming and hardware concepts, providing students with a practical introduction to computer science.

In the field of automation and control, the RP2040 has been integrated into systems such as smart home devices and industrial automation projects, interacting with sensors and actuators to control and monitor environments. It has also found applications in robotics, serving as the brains of robots and autonomous vehicles, with the added ability to run TensorFlow Lite for machine learning implementations.

The versatility of the RP2040 is highlighted in the development of rapid prototyping, facilitating the rapid creation of new products and technologies. Its usefulness extends to the Internet of Things (IoT), where it is used in devices connected to the network to collect data and send information to the cloud, thanks to its compact size and energy efficiency.

In addition, the RP2040 is integrated into collaborative and open source projects, fostering the community of open hardware. From entertainment applications to interactive art projects, the RP2040 has become a popular choice in the hobby and creative entertainment arena.