Skip to main content

Control RP2040 on Windows

Relation introduction between J4215 and 40-PIN GPIO

The Radxa X4 integrates an Intel N100 CPU and a RP2040 MCU, which communicate with each other via USB or UART. The 40-PIN interface serves as an I/O expansion port extending from the RP2040 microcontroller. The CPU exerts control over this interface through communication with the RP2040, which leverages the Pico SDK for efficient manipulation and operation of the 40-PIN interface.

Install necessary Tools

Set Environment Variables

  • Search for ‘Edit the system environment’ in the search bar.

  • Click "Environment Variables"

  • Add system or user variables

    • Add variables PICO_INSTALL_PATH and PICO-SDK_PATH
    pico install path pico sdk path
  • Ads PATH

    pico path env

Build

Open git bash, go to the pico-examples/build directory, and execute the following command to build the system

cmake -G "Ninja" ..

ninja
cmake ninja ninja build

Flash

Press the BOOTSEL key and a USB device will pop up. Copy the compiled .uf2 file to the USB device of RP2040 and wait until the USB device disappears, then the programme will start to execute.

Examples

RP2040 Control the 40-PIN

GPIO
1. Preparation
  • One Radxa X4
  • One LED
2. Connection
Radxa X4<-->LED
PIN_5<-->LED
PIN_1<-->VCC
PIN_9<-->GND
tip

Here PIN_5 corresponds to GPIO29 in the following code, please refer to GPIO Definition for details.

3. Test
  • Replace pico-examples/blink/blink.c with the following code

    blink.c

    #include "pico/stdlib.h"
    #define BLINK_PIN 29 // GPIO29

    int main() {

    gpio_init(BLINK_PIN);
    gpio_set_dir(BLINK_PIN, GPIO_OUT);

    while (true) {
    gpio_put(BLINK_PIN, 1);
    sleep_ms(250);
    gpio_put(BLINK_PIN, 0);
    sleep_ms(250);
    }
    }

  • Compile

    cd pico-examples/build/
    rm -rf *
    cmake -G "Ninja" ..
    ninja

    After successful compilation, a file named blink.uf2 will be created in the pico-examples/build/blink/ directory.

  • Flash

    • Reboot RP2040
    • Drag the blink.uf2 file into the RP2040, and when the RP2040 disappears, the LED will start blinking.