### Change Directory to Example Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-internal-libs/README.md Navigate to the example project directory before running PlatformIO commands. ```shell # Change directory to example $ cd platform-ststm32/examples/arduino-internal-libs ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-mxchip-azureiot/README.md Use these commands to navigate to an example project, build the firmware, upload it to the target device, and clean build files. ```shell # Change directory to example $ cd platform-ststm32/examples/arduino-mxchip-azureiot ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/stm32cube-hal-wifi-client/README.md Use these commands to navigate to an example project, build the firmware, upload it to the target device, and clean build artifacts. ```shell # Change directory to example $ cd platform-ststm32/examples/stm32cube-hal-wifi-client ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### Build PlatformIO Project Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/spl-blink/README.md Use this command to compile your PlatformIO project. Ensure you are in the project's example directory. ```shell cd platform-ststm32/examples/spl-blink pio run ``` -------------------------------- ### Arduino Framework Blink Example Source: https://context7.com/platformio/platform-ststm32/llms.txt Configure multiple boards for the Arduino framework and implement a standard blink application. ```ini ; platformio.ini [env:bluepill_f103c8] platform = ststm32 framework = arduino board = bluepill_f103c8 [env:nucleo_f401re] platform = ststm32 framework = arduino board = nucleo_f401re [env:disco_f407vg] platform = ststm32 framework = arduino board = disco_f407vg upload_protocol = dfu ``` ```cpp // src/main.cpp - Arduino Blink Example #include void setup() { pinMode(LED_BUILTIN, OUTPUT); Serial.begin(115200); Serial.println("STM32 Arduino Blink Started"); } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); } ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/libopencm3-usb-cdcacm/README.md Use these commands to navigate to an example project, build the firmware, upload it to the target device, and clean generated build files. ```shell # Change directory to example $ cd platform-ststm32/examples/libopencm3-usb-cdcacm ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/libopencm3-1bitsy/README.md Use these commands to navigate to an example project, build the firmware, upload it to the target device, and clean generated build files. ```shell # Change directory to example $ cd platform-ststm32/examples/libopencm3-1bitsy ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/mbed-rtos-serial/README.md Use these commands to navigate to an example project, build the firmware, upload it to the target device, clean build files, or target specific environments. ```shell # Change directory to example $ cd platform-ststm32/examples/mbed-rtos-serial ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Build specific environment $ pio run -e disco_f769ni ``` ```shell # Upload firmware for the specific environment $ pio run -e disco_f769ni --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/stm32cube-ll-blink/README.md Use these commands to manage PlatformIO projects. Ensure you are in the project's example directory before running. ```shell # Change directory to example $ cd platform-ststm32/examples/stm32cube-ll-blink ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Build specific environment $ pio run -e nucleo_f401re ``` ```shell # Upload firmware for the specific environment $ pio run -e nucleo_f401re --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### PlatformIO Project Build and Upload Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-blink/README.md Use these commands to navigate to your project directory, build the firmware, upload it to the target device, or clean build files. Ensure you are in the project's example directory before running. ```shell # Change directory to example $ cd platform-ststm32/examples/arduino-blink ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Build specific environment $ pio run -e maple ``` ```shell # Upload firmware for the specific environment $ pio run -e maple --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### Blink LED with libopencm3 Source: https://context7.com/platformio/platform-ststm32/llms.txt A basic blink example using libopencm3, handling peripheral setup for different STM32 series. ```c // src/main.c - libopencm3 Blink Example #include #include #ifdef STM32F4 #define RCCLEDPORT (RCC_GPIOD) #define LEDPORT (GPIOD) #define LEDPIN (GPIO12) #elif STM32F1 #define RCCLEDPORT (RCC_GPIOC) #define LEDPORT (GPIOC) #define LEDPIN (GPIO13) #define GPIO_MODE_OUTPUT GPIO_MODE_OUTPUT_2_MHZ #define GPIO_PUPD_NONE GPIO_CNF_OUTPUT_PUSHPULL #endif static void gpio_setup(void) { rcc_periph_clock_enable(RCCLEDPORT); #ifdef STM32F1 gpio_set_mode(LEDPORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LEDPIN); #else gpio_mode_setup(LEDPORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LEDPIN); #endif } int main(void) { int i; gpio_setup(); while (1) { gpio_toggle(LEDPORT, LEDPIN); for (i = 0; i < 1000000; i++) { __asm__("nop"); } } return 0; } ``` -------------------------------- ### PlatformIO Project Management Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/mbed-rtos-custom-target/README.md Use these commands to manage PlatformIO projects. Navigate to your example directory before running. ```shell # Change directory to example $ cd platform-ststm32/examples/mbed-rtos-custom-target ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### Blink LED with SPL Source: https://context7.com/platformio/platform-ststm32/llms.txt A basic blink example using the legacy Standard Peripheral Library. ```c // src/main.c - SPL Blink Example #ifdef STM32F4 #include #include #define LEDPORT (GPIOD) #define LEDPIN (GPIO_Pin_12) #define ENABLE_GPIO_CLOCK (RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE)) #elif STM32F3 #include #include #define LEDPORT (GPIOE) #define LEDPIN (GPIO_Pin_8) #define ENABLE_GPIO_CLOCK (RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE)) #endif void simple_delay(uint32_t us) { while (us--) { asm volatile ("nop"); } } int main(void) { GPIO_InitTypeDef gpio; RCC_DeInit(); ENABLE_GPIO_CLOCK; gpio.GPIO_Pin = LEDPIN; gpio.GPIO_Mode = GPIO_Mode_OUT; gpio.GPIO_OType = GPIO_OType_PP; GPIO_Init(LEDPORT, &gpio); for (;;) { GPIO_SetBits(LEDPORT, LEDPIN); simple_delay(100000); GPIO_ResetBits(LEDPORT, LEDPIN); simple_delay(100000); } return 0; } ``` -------------------------------- ### PlatformIO Project Build and Upload Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/cmsis-blink/README.md Use these commands to build, upload firmware, and clean build files for your PlatformIO projects. Ensure you are in the project's example directory before running. ```shell # Change directory to example $ cd platform-ststm32/examples/cmsis-blink ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Build specific environment $ pio run -e disco_f407vg ``` ```shell # Upload firmware for the specific environment $ pio run -e disco_f407vg --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### Mbed OS Baremetal Blink Example Source: https://context7.com/platformio/platform-ststm32/llms.txt A basic Mbed OS application that blinks the onboard LED. Demonstrates the use of DigitalOut and thread_sleep_for. ```cpp // src/main.cpp - Mbed OS Baremetal Blink #include "mbed.h" #define WAIT_TIME_MS 500 DigitalOut led1(LED1); int main() { printf("Mbed OS %d.%d.%d blinky running\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); while (true) { led1 = !led1; thread_sleep_for(WAIT_TIME_MS); } } ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/mbed-rtos-ethernet-tls/README.md Common commands for managing PlatformIO projects, including building, uploading, and cleaning. Ensure you are in the example directory before running. ```shell # Change directory to example $ cd platform-ststm32/examples/mbed-rtos-ethernet-tls ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### Mbed OS Event Queue System Source: https://context7.com/platformio/platform-ststm32/llms.txt Example demonstrating Mbed OS event queues for scheduling callbacks with precise timing control. Uses EventQueue and Thread. ```cpp // src/main.cpp - Mbed EventQueue Example #include "mbed.h" EventQueue queue; void handler(int count); Event event(&queue, handler); void handler(int count) { printf("Event = %d\n", count); } void post_events(void) { event.post(1); event.post(2); event.post(3); } int main() { Thread event_thread; // Configure timing: 100ms start delay, 200ms period event.delay(100); event.period(200); event_thread.start(callback(post_events)); // Dispatch for 400ms - processes 2 event cycles queue.dispatch(400); event_thread.join(); } ``` -------------------------------- ### Blink LED with Zephyr RTOS Source: https://context7.com/platformio/platform-ststm32/llms.txt A basic blink example using the Zephyr RTOS GPIO driver API. ```c // src/main.c - Zephyr Blink Example #include #include #include #define SLEEP_TIME_MS 1000 #define LED0_NODE DT_ALIAS(led0) static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios); int main(void) { int ret; bool led_state = true; if (!gpio_is_ready_dt(&led)) { return 0; } ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE); if (ret < 0) { return 0; } while (1) { ret = gpio_pin_toggle_dt(&led); if (ret < 0) { return 0; } led_state = !led_state; printf("LED state: %s\n", led_state ? "ON" : "OFF"); k_msleep(SLEEP_TIME_MS); } return 0; } ``` -------------------------------- ### PlatformIO Project Management Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-mxchip-wifiscan/README.md Navigate to your PlatformIO project directory and use these commands to manage the build process. Ensure you have PlatformIO Core installed and the project is set up. ```shell # Change directory to example $ cd platform-ststm32/examples/arduino-mxchip-wifiscan ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### Mbed OS USB HID Device (Mouse/Keyboard) Source: https://context7.com/platformio/platform-ststm32/llms.txt Implement USB Human Interface Devices like keyboards and mice using Mbed OS. This example demonstrates mouse movement, media control, and keyboard output. ```cpp // src/main.cpp - USB Mouse Keyboard Example #include "mbed.h" #include "USBMouseKeyboard.h" USBMouseKeyboard key_mouse; int main(void) { int16_t x = 0; int16_t y = 0; int32_t radius = 70; int32_t angle = 0; while (1) { // Move mouse in circle x = cos((double)angle * 3.14 / 50.0) * radius; y = sin((double)angle * 3.14 / 50.0) * radius; // Media key control key_mouse.media_control(KEY_VOLUME_DOWN); // Keyboard output key_mouse.printf("Hello World from Mbed\r\n"); // Mouse movement key_mouse.move(x, y); // Modifier keys key_mouse.key_code(KEY_CAPS_LOCK); ThisThread::sleep_for(50); key_mouse.media_control(KEY_VOLUME_UP); key_mouse.key_code(KEY_NUM_LOCK); ThisThread::sleep_for(50); angle += 10; key_mouse.key_code(KEY_SCROLL_LOCK); ThisThread::sleep_for(50); } } ``` -------------------------------- ### Build and Manage PlatformIO Projects Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-mbed-doom/README.md Commands to navigate to a project directory, build the firmware, upload it to the device, and clean build artifacts. ```shell # Change directory to example $ cd platform-nordicnrf52/examples/arduino-mbed-doom # Build project $ pio run # Upload firmware $ pio run --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/libopencm3-blink/README.md Use these commands to navigate to your project directory, build the project, upload firmware, and clean build files. Specify environments for targeted builds and uploads. ```shell # Change directory to example $ cd platform-ststm32/examples/libopencm3-blink ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Build specific environment $ pio run -e disco_f407vg ``` ```shell # Upload firmware for the specific environment $ pio run -e disco_f407vg --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### Build and Manage PlatformIO Projects Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/mbed-rtos-filesystem/README.md Use these commands to navigate to a project directory and perform standard build, upload, and clean operations. ```shell # Change directory to example $ cd platform-ststm32/examples/mbed-rtos-filesystem # Build project $ pio run # Upload firmware $ pio run --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Build and Manage PlatformIO Projects Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-mxchip-filesystem/README.md Use these commands to navigate to a project directory, compile the code, upload it to the target device, or clean build artifacts. ```shell # Change directory to example $ cd platform-ststm32/examples/arduino-mxchip-filesystem # Build project $ pio run # Upload firmware $ pio run --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Build and Manage PlatformIO Projects Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-mbed-rpc/README.md Use these commands to navigate to a project directory and perform build, upload, or clean operations. ```shell # Change directory to example $ cd platform-nordicnrf52/examples/arduino-mbed-rpc # Build project $ pio run # Upload firmware $ pio run --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Build Project with PlatformIO Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-internal-libs/README.md Execute this command to compile your PlatformIO project. Ensure you are in the project directory. ```shell # Build project $ pio run ``` -------------------------------- ### Configure Standard Peripheral Library (SPL) Source: https://context7.com/platformio/platform-ststm32/llms.txt Set the framework to spl in the platformio.ini file for legacy STM32 support. ```ini ; platformio.ini [env:disco_f407vg] platform = ststm32 framework = spl board = disco_f407vg [env:disco_f303vc] platform = ststm32 framework = spl board = disco_f303vc ``` -------------------------------- ### Build and Manage STM32 Projects via CLI Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/stm32cube-hal-iap/README.md Use these commands to navigate to a project directory and perform standard build, upload, and clean operations. ```shell # Change directory to example $ cd platform-ststm32/examples/stm32cube-hal-iap # Build project $ pio run # Upload firmware $ pio run --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Build and Manage STM32 Projects via CLI Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/stm32cube-hal-extmem-boot/README.md Use these commands to navigate to a project directory and execute build, upload, or clean tasks. ```shell # Change directory to example $ cd platform-ststm32/examples/stm32cube-hal-extmem-boot # Build project $ pio run # Upload firmware $ pio run --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Build and Manage STM32 Projects via CLI Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/stm32cube-hal-lcd/README.md Use these commands to navigate to a project directory and execute build, upload, or clean tasks. ```shell # Change directory to example $ cd platform-ststm32/examples/stm32cube-hal-lcd # Build project $ pio run # Upload firmware $ pio run --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Build and Manage STM32 Projects via CLI Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/stm32cube-hal-usb-device-dfu/README.md Use these commands to navigate to a project directory and execute build, upload, or clean operations. ```shell # Change directory to example $ cd platform-ststm32/examples/stm32cube-hal-usb-device-dfu # Build project $ pio run # Upload firmware $ pio run --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Build and Upload PlatformIO Projects Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/mbed-rtos-blink-baremetal/README.md Use these commands to manage the build lifecycle, including compiling, uploading, and cleaning project environments. ```shell # Change directory to example $ cd platform-ststm32/examples/mbed-blink-baremetal # Build project $ pio run # Upload firmware $ pio run --target upload # Build specific environment $ pio run -e nucleo_f401re # Upload firmware for the specific environment $ pio run -e nucleo_f401re --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Build and Upload Commands for PlatformIO Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/zephyr-cpp-synchronization/README.md Use these shell commands to navigate to a project directory, build the firmware, upload it to the target board, or clean build artifacts. ```shell # Change directory to example $ cd platform-ststm32/examples/zephyr-cpp-synchronization # Build project $ pio run # Upload firmware $ pio run --target upload # Build specific environment $ pio run -e nucleo_f756zg # Upload firmware for the specific environment $ pio run -e nucleo_f756zg --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Build and Upload PlatformIO Projects Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-external-libs/README.md Use these commands to navigate to a project directory and execute build, upload, or clean operations via the PlatformIO CLI. ```shell # Change directory to example $ cd platform-ststm32/examples/arduino-external-libs # Build project $ pio run # Upload firmware $ pio run --target upload # Build specific environment $ pio run -e maple # Upload firmware for the specific environment $ pio run -e maple --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Upload Firmware with PlatformIO Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-internal-libs/README.md Use this command to upload the compiled firmware to your target device. Requires a successful build first. ```shell # Upload firmware $ pio run --target upload ``` -------------------------------- ### Configure libopencm3 Framework Source: https://context7.com/platformio/platform-ststm32/llms.txt Set the framework to libopencm3 in the platformio.ini file for specific STM32 boards. ```ini ; platformio.ini [env:nucleo_f401re] platform = ststm32 framework = libopencm3 board = nucleo_f401re [env:nucleo_f103rb] platform = ststm32 framework = libopencm3 board = nucleo_f103rb ``` -------------------------------- ### Build and Upload Commands for ST STM32 Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/zephyr-blink/README.md Use these commands to navigate to a project directory, build the firmware, upload it to the target device, or clean build artifacts. ```shell # Change directory to example $ cd platform-ststm32/examples/zephyr-blink # Build project $ pio run # Upload firmware $ pio run --target upload # Build specific environment $ pio run -e blackpill_f103c8 # Upload firmware for the specific environment $ pio run -e blackpill_f103c8 --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Configure PlatformIO Environment Source: https://context7.com/platformio/platform-ststm32/llms.txt Define the platform, board, and framework in the platformio.ini file. Use the stable release or a specific GitHub repository for development versions. ```ini ; Basic platformio.ini configuration [env:stable] platform = ststm32 board = bluepill_f103c8 framework = arduino ; Use development version from GitHub [env:development] platform = https://github.com/platformio/platform-ststm32.git board = nucleo_f401re framework = stm32cube ``` -------------------------------- ### Configure Upload Protocols Source: https://context7.com/platformio/platform-ststm32/llms.txt Set the upload_protocol in platformio.ini to define the hardware interface used for flashing the firmware. ```ini ; platformio.ini - Upload Protocol Examples ; ST-Link (default for Nucleo boards) [env:nucleo_stlink] platform = ststm32 framework = arduino board = nucleo_f401re upload_protocol = stlink ; DFU USB Bootloader [env:bluepill_dfu] platform = ststm32 framework = arduino board = bluepill_f103c8_128k upload_protocol = dfu ; J-Link [env:custom_jlink] platform = ststm32 framework = arduino board = genericSTM32F103C8 upload_protocol = jlink ; Black Magic Probe [env:blackmagic] platform = ststm32 framework = arduino board = bluepill_f103c8 upload_protocol = blackmagic upload_port = /dev/ttyACM0 ``` -------------------------------- ### PlatformIO Project Build and Upload Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/zephyr-subsys-usb-hid-mouse/README.md Use these commands to build, upload, and clean your PlatformIO projects. Specify environments for targeted operations. ```shell # Change directory to example $ cd platform-ststm32/examples/zephyr-subsys-usb-hid-mouse ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Build specific environment $ pio run -e disco_f407vg ``` ```shell # Upload firmware for the specific environment $ pio run -e disco_f407vg --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### Configure STM32 CMake Build Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/mbed-rtos-custom-target/src/TARGET_STM32L452xE/CMakeLists.txt Sets up the library interface, source files, and linker scripts based on the selected Mbed toolchain. ```cmake # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 add_subdirectory(TARGET_NUCLEO_L452RE_P EXCLUDE_FROM_ALL) if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") set(STARTUP_FILE TOOLCHAIN_GCC_ARM/startup_stm32l452xx.S) set(LINKER_FILE TOOLCHAIN_GCC_ARM/stm32l452xe.ld) elseif(${MBED_TOOLCHAIN} STREQUAL "ARM") set(STARTUP_FILE TOOLCHAIN_ARM/startup_stm32l452xx.S) set(LINKER_FILE TOOLCHAIN_ARM/stm32l452xe.sct) endif() add_library(mbed-stm32l452xe INTERFACE) target_sources(mbed-stm32l452xe INTERFACE system_clock.c ${STARTUP_FILE} ) target_include_directories(mbed-stm32l452xe INTERFACE . ) mbed_set_linker_script(mbed-stm32l452xe ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE}) target_link_libraries(mbed-stm32l452xe INTERFACE mbed-stm32l4) ``` -------------------------------- ### Build and Manage STSTM32 Projects via CLI Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/zephyr-net-https-client/README.md Use these commands to navigate to a project directory and execute build, upload, or clean operations. ```shell # Change directory to example $ cd platform-ststm32/examples/zephyr-net-https-client # Build project $ pio run # Upload firmware $ pio run --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Upload Firmware for Specific Environment Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-internal-libs/README.md Upload firmware to the target device for a specified environment. This command combines environment selection and the upload target. ```shell # Upload firmware for the specific environment $ pio run -e maple --target upload ``` -------------------------------- ### Build Specific Environment with PlatformIO Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-internal-libs/README.md Compile a project for a particular environment, specified by its name (e.g., 'maple'). ```shell # Build specific environment $ pio run -e maple ``` -------------------------------- ### PlatformIO Project Management Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-mxchip-sensors/README.md Use these commands in the terminal to manage your PlatformIO projects. Navigate to your project directory first. 'pio run' builds the project, '--target upload' flashes the firmware, and '--target clean' removes build files. ```shell # Change directory to example $ cd platform-ststm32/examples/arduino-mxchip-sensors # Build project $ pio run # Upload firmware $ pio run --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Build Specific PlatformIO Environment Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/spl-blink/README.md Compiles the project for a designated environment, such as a specific development board. Replace 'disco_f407vg' with your target environment ID. ```shell pio run -e disco_f407vg ``` -------------------------------- ### Configure Development STM32 Platform Source: https://github.com/platformio/platform-ststm32/blob/develop/README.md Use this configuration in platformio.ini to target the latest development version directly from the GitHub repository. ```ini [env:development] platform = https://github.com/platformio/platform-ststm32.git board = ... ... ``` -------------------------------- ### Upload Firmware for Specific Environment Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/spl-blink/README.md Uploads firmware to a specific environment on your STM32 board. Ensure the environment name is correct. ```shell pio run -e disco_f407vg --target upload ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/mbed-rtos-events/README.md Use these commands to manage your PlatformIO projects. Navigate to your project directory and execute commands for building, uploading, cleaning, and targeting specific environments. ```shell # Change directory to example $ cd platform-ststm32/examples/mbed-rtos-events ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Build specific environment $ pio run -e nucleo_f091rc ``` ```shell # Upload firmware for the specific environment $ pio run -e nucleo_f091rc --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/mbed-rtos-mesh-minimal/README.md Use these commands to manage PlatformIO projects. Ensure you are in the project directory before executing. ```shell # Change directory to example $ cd platform-ststm32/examples/mbed-rtos-mesh-minimal ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Build specific environment $ pio run -e nucleo_f072rb ``` ```shell # Upload firmware for the specific environment $ pio run -e nucleo_f072rb --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### Select Arduino Core Variants Source: https://context7.com/platformio/platform-ststm32/llms.txt Configure board_build.core to switch between different Arduino core implementations like Maple or specific series-based cores. ```ini ; platformio.ini ; Official STM32duino Core (default) [env:official_core] platform = ststm32 framework = arduino board = nucleo_f401re ; Maple Core (legacy LeafLabs compatibility) [env:maple_core] platform = ststm32 framework = arduino board = maple board_build.core = maple ; STM32L0 Specific Core [env:stm32l0_core] platform = ststm32 framework = arduino board = disco_l072cz_lrwan1 board_build.core = stm32l0 ; Arduino Mbed Core (for Portenta, Giga, etc.) [env:giga_r1] platform = ststm32 framework = arduino board = giga_r1_m7 ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/stm32cube-hal-blink/README.md Use these commands to manage your PlatformIO STM32 projects. Navigate to your project directory and execute the desired command. ```shell # Change directory to example $ cd platform-ststm32/examples/stm32cube-hal-blink ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Build specific environment $ pio run -e nucleo_f401re ``` ```shell # Upload firmware for the specific environment $ pio run -e nucleo_f401re --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### Configure CMake for Zephyr Project Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/zephyr-drivers-can/zephyr/CMakeLists.txt Initializes the project environment and includes all C source files from the src directory. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(babbling) FILE(GLOB app_sources ../src/*.c) target_sources(app PRIVATE ${app_sources}) ``` -------------------------------- ### Upload Firmware to STM32 Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/spl-blink/README.md Uploads the compiled firmware to your STM32 board. This command requires a previously built project. ```shell pio run --target upload ``` -------------------------------- ### Define STM32 Board Hardware and Build Settings Source: https://context7.com/platformio/platform-ststm32/llms.txt JSON board definitions specify hardware capabilities, build flags, and debug configurations for specific STM32 microcontrollers. ```json // boards/bluepill_f103c8.json { "build": { "core": "stm32", "cpu": "cortex-m3", "extra_flags": "-DSTM32F1 -DSTM32F103xB", "f_cpu": "72000000L", "mcu": "stm32f103c8t6", "product_line": "STM32F103xB", "variant": "STM32F1xx/F103C8T_F103CB(T-U)" }, "debug": { "default_tools": ["stlink"], "jlink_device": "STM32F103C8", "openocd_target": "stm32f1x", "svd_path": "STM32F103xx.svd" }, "frameworks": ["arduino", "cmsis", "libopencm3", "stm32cube", "zephyr"], "name": "BluePill F103C8", "upload": { "maximum_ram_size": 20480, "maximum_size": 65536, "protocol": "stlink", "protocols": ["jlink", "cmsis-dap", "stlink", "blackmagic", "mbed", "dfu"] }, "vendor": "Generic" } ``` ```json // boards/nucleo_f401re.json { "build": { "core": "stm32", "cpu": "cortex-m4", "extra_flags": "-DSTM32F4 -DSTM32F401xE", "f_cpu": "84000000L", "mcu": "stm32f401ret6", "product_line": "STM32F401xE" }, "debug": { "default_tools": ["stlink"], "onboard_tools": ["stlink"], "openocd_board": "st_nucleo_f4", "svd_path": "STM32F401xE.svd" }, "frameworks": ["arduino", "mbed", "cmsis", "spl", "stm32cube", "libopencm3", "zephyr"], "name": "ST Nucleo F401RE", "upload": { "maximum_ram_size": 98304, "maximum_size": 524288, "protocol": "stlink" }, "vendor": "ST" } ``` -------------------------------- ### Configure Debugging Tools Source: https://context7.com/platformio/platform-ststm32/llms.txt Define debug_tool and associated build flags in platformio.ini to enable GDB-based debugging. ```ini ; platformio.ini - Debug Configuration [env:debug_stlink] platform = ststm32 framework = arduino board = nucleo_f401re debug_tool = stlink debug_build_flags = -O0 -g -ggdb [env:debug_jlink] platform = ststm32 framework = stm32cube board = disco_f407vg debug_tool = jlink debug_speed = 4000 [env:debug_cmsis_dap] platform = ststm32 framework = arduino board = nucleo_f401re debug_tool = cmsis-dap ``` -------------------------------- ### CMakeLists.txt for Zephyr Project Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/zephyr-cpp-synchronization/zephyr/CMakeLists.txt This CMakeLists.txt file configures a Zephyr-based project for STM32. It specifies the minimum CMake version, finds the Zephyr package, sets the project name, and includes the main C++ source file. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(cpp_synchronization) target_sources(app PRIVATE ../src/main.cpp) ``` -------------------------------- ### Configure Zephyr RTOS Framework Source: https://context7.com/platformio/platform-ststm32/llms.txt Set the framework to zephyr in the platformio.ini file for specific STM32 boards. ```ini ; platformio.ini [env:blackpill_f103c8] platform = ststm32 framework = zephyr board = blackpill_f103c8 [env:nucleo_g474re] platform = ststm32 framework = zephyr board = nucleo_g474re ``` -------------------------------- ### Mbed OS PlatformIO Configuration Source: https://context7.com/platformio/platform-ststm32/llms.txt Configure PlatformIO for Mbed OS development on STM32 boards. Specify the platform, framework, and target board. ```ini ; platformio.ini [env:nucleo_f401re] platform = ststm32 framework = mbed board = nucleo_f401re [env:nucleo_f103rb] platform = ststm32 framework = mbed board = nucleo_f103rb ``` -------------------------------- ### STM32Cube HAL Framework Blink Source: https://context7.com/platformio/platform-ststm32/llms.txt Configure build flags for different STM32 families and implement a hardware-abstracted blink application. ```ini ; platformio.ini [env:nucleo_f401re] platform = ststm32 framework = stm32cube board = nucleo_f401re build_flags = -DF4 [env:nucleo_f103rb] platform = ststm32 framework = stm32cube board = nucleo_f103rb build_flags = -DF1 [env:nucleo_h743zi] platform = ststm32 framework = stm32cube board = nucleo_h743zi build_flags = -DH7 ``` ```c // src/main.c - STM32Cube HAL Blink Example #ifdef F4 #include "stm32f4xx_hal.h" #elif F1 #include "stm32f1xx_hal.h" #elif H7 #include "stm32h7xx_hal.h" #endif #define LED_PIN GPIO_PIN_5 #define LED_GPIO_PORT GPIOA #define LED_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE() int main(void) { HAL_Init(); LED_GPIO_CLK_ENABLE(); GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.Pin = LED_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct); while (1) { HAL_GPIO_TogglePin(LED_GPIO_PORT, LED_PIN); HAL_Delay(1000); } } void SysTick_Handler(void) { HAL_IncTick(); } void NMI_Handler(void) {} void HardFault_Handler(void) { while (1) {} } void MemManage_Handler(void) { while (1) {} } void BusFault_Handler(void) { while (1) {} } void UsageFault_Handler(void) { while (1) {} } void SVC_Handler(void) {} void DebugMon_Handler(void) {} void PendSV_Handler(void) {} ``` -------------------------------- ### Add External Library Dependencies Source: https://context7.com/platformio/platform-ststm32/llms.txt Include external libraries from the PlatformIO Registry using the lib_deps directive. ```ini ; platformio.ini [env] lib_deps = sparkfun/Sparkfun BMP180 [env:bluepill_f103c8] platform = ststm32 framework = arduino board = bluepill_f103c8 [env:nucleo_f401re] platform = ststm32 board = nucleo_f401re framework = arduino ``` -------------------------------- ### Configure Stable STM32 Platform Source: https://github.com/platformio/platform-ststm32/blob/develop/README.md Use this configuration in platformio.ini to target the stable release of the ST STM32 platform. ```ini [env:stable] platform = ststm32 board = ... ... ``` -------------------------------- ### CMake Configuration for Zephyr HID Mouse Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/zephyr-subsys-usb-hid-mouse/zephyr/CMakeLists.txt This CMakeLists.txt file configures a Zephyr RTOS project for building a USB HID mouse. It finds the Zephyr package, sets the project name, includes common USB sample logic, and discovers application source files. ```cmake SPDX-License-Identifier: Apache-2.0 cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(hid-mouse) include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake) FILE(GLOB app_sources ../src/*.c) target_sources(app PRIVATE ${app_sources}) ``` -------------------------------- ### CMakeLists.txt for PlatformIO ststm32 Project Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/zephyr-blink/zephyr/CMakeLists.txt This CMakeLists.txt file configures a PlatformIO project for the ststm32 platform. It specifies the minimum required CMake version, finds the Zephyr build system, and defines the project name and source files. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(blinky) target_sources(app PRIVATE ../src/main.c) ``` -------------------------------- ### Configure CMake for Zephyr Project Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/zephyr-net-https-client/zephyr/CMakeLists.txt Sets up the project requirements, includes source files, and generates an include file from a certificate for the Zephyr build system. ```cmake cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(http_client) FILE(GLOB app_sources ../src/*.c) target_sources(app PRIVATE ${app_sources}) set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/) generate_inc_file_for_target( app ../src/https-cert.der ${gen_dir}/https-cert.der.inc ) ``` -------------------------------- ### Configure Build Flags in platformio.ini Source: https://context7.com/platformio/platform-ststm32/llms.txt Use build flags to define preprocessor macros and compiler optimizations for specific environments. ```ini ; platformio.ini [env:custom_build] platform = ststm32 framework = arduino board = bluepill_f103c8 build_flags = -DPIO_FRAMEWORK_ARDUINO_ENABLE_MASS_STORAGE_HID -DSERIAL_UART_INSTANCE=1 -DPIN_SERIAL_RX=PA10 -DPIN_SERIAL_TX=PA9 -Os [env:custom_flash_storage] platform = ststm32 framework = arduino board = econode_l082cz build_flags = -DPIO_FRAMEWORK_ARDUINO_FS_SFLASH ``` -------------------------------- ### Mbed OS TCP/TLS Socket Networking Source: https://context7.com/platformio/platform-ststm32/llms.txt Demonstrates network connectivity using Mbed OS sockets, including resolving hostnames, connecting to a server, and sending/receiving HTTP requests. Supports optional TLS. ```cpp // src/main.cpp - Mbed Socket Demo #include "mbed.h" class SocketDemo { static constexpr size_t REMOTE_PORT = 80; static constexpr size_t MAX_MESSAGE_RECEIVED_LENGTH = 100; public: SocketDemo() : _net(NetworkInterface::get_default_instance()) {} void run() { if (!_net) { printf("Error! No network interface found.\r\n"); return; } printf("Connecting to the network...\r\n"); nsapi_size_or_error_t result = _net->connect(); if (result != 0) { printf("Error! connect() returned: %d\r\n", result); return; } // Print network info SocketAddress addr; _net->get_ip_address(&addr); printf("IP: %s\r\n", addr.get_ip_address()); // Open socket result = _socket.open(_net); if (result != 0) { printf("Error! socket.open() returned: %d\r\n", result); return; } // Resolve hostname const char hostname[] = "ifconfig.io"; result = _net->gethostbyname(hostname, &addr); if (result != 0) { printf("Error! gethostbyname() returned: %d\r\n", result); return; } addr.set_port(REMOTE_PORT); // Connect and send HTTP request result = _socket.connect(addr); if (result != 0) { printf("Error! socket.connect() returned: %d\r\n", result); return; } const char request[] = "GET / HTTP/1.1\r\nHost: ifconfig.io\r\nConnection: close\r\n\r\n"; _socket.send(request, strlen(request)); // Receive response char buffer[MAX_MESSAGE_RECEIVED_LENGTH]; int received = _socket.recv(buffer, sizeof(buffer) - 1); if (received > 0) { buffer[received] = '\0'; printf("Response: %s\r\n", buffer); } printf("Demo complete\r\n"); } private: NetworkInterface *_net; TCPSocket _socket; }; int main() { printf("Starting socket demo\r\n"); SocketDemo demo; demo.run(); return 0; } ``` -------------------------------- ### Clean Project Build Files Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/arduino-internal-libs/README.md Remove all generated build files for the project. This is useful for performing a clean build from scratch. ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### Clean PlatformIO Build Files Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/spl-blink/README.md Removes all generated build files for the project, allowing for a fresh compilation. This is useful for resolving build issues. ```shell pio run --target clean ``` -------------------------------- ### Define CMake Interface Library for Nucleo-L452RE-P Source: https://github.com/platformio/platform-ststm32/blob/develop/examples/mbed-rtos-custom-target/src/TARGET_STM32L452xE/TARGET_NUCLEO_L452RE_P/CMakeLists.txt Configures the interface library, including source files, include paths, and required link libraries for the STM32 target. ```cmake # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 add_library(mbed-nucleo-l452re-p INTERFACE) target_sources(mbed-nucleo-l452re-p INTERFACE PeripheralPins.c ) target_include_directories(mbed-nucleo-l452re-p INTERFACE . ) target_link_libraries(mbed-nucleo-l452re-p INTERFACE mbed-stm32l452xe) ``` -------------------------------- ### Set STM32Cube BSP Variant Source: https://context7.com/platformio/platform-ststm32/llms.txt Use board_build.stm32cube.variant to specify a custom Board Support Package for STM32Cube projects. ```ini ; platformio.ini [env:nucleo_f207zg] platform = ststm32 framework = stm32cube board = nucleo_f207zg board_build.stm32cube.variant = STM32F2xx_Nucleo_144 ```