Convert Figma logo to code with AI

STMicroelectronics logoSTM32CubeF4

STM32Cube MCU Full Package for the STM32F4 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))

1,003
448
1,003
10

Top Related Projects

1,434

CMSIS Version 5 Development Repository

11,965

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.

15,071

Espressif IoT Development Framework. Official development framework for Espressif SoCs.

4,743

Arm Mbed OS is a platform operating system designed for the internet of things

'Classic' FreeRTOS distribution. Started as Git clone of FreeRTOS SourceForge SVN repo. Submodules the kernel.

PX4 Autopilot Software

Quick Overview

STM32CubeF4 is a comprehensive software package provided by STMicroelectronics for STM32F4 series microcontrollers. It includes hardware abstraction layers (HAL), low-layer APIs, middleware components, and example projects to facilitate rapid development of applications on STM32F4 devices.

Pros

  • Extensive hardware abstraction layer (HAL) simplifies peripheral configuration and usage
  • Rich set of middleware components for various functionalities (USB, TCP/IP, file systems, etc.)
  • Includes numerous example projects demonstrating various features and peripherals
  • Regular updates and support from STMicroelectronics

Cons

  • Large package size can be overwhelming for beginners
  • Some users report occasional bugs or inconsistencies in HAL implementations
  • Learning curve can be steep for developers new to STM32 ecosystem
  • Documentation, while extensive, can be complex to navigate

Code Examples

  1. GPIO LED Blink:
HAL_Init();
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

while (1) {
    HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
    HAL_Delay(1000);
}
  1. ADC Reading:
ADC_HandleTypeDef hadc1;
uint16_t adc_value;

HAL_ADC_Init(&hadc1);
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 100);
adc_value = HAL_ADC_GetValue(&hadc1);
  1. UART Transmission:
UART_HandleTypeDef huart2;
uint8_t data[] = "Hello, STM32F4!";

HAL_UART_Init(&huart2);
HAL_UART_Transmit(&huart2, data, sizeof(data), 100);

Getting Started

  1. Download and install STM32CubeIDE from ST's website.
  2. Clone the STM32CubeF4 repository:
    git clone https://github.com/STMicroelectronics/STM32CubeF4.git
    
  3. Open STM32CubeIDE and create a new STM32 project.
  4. Select your specific STM32F4 device.
  5. Use the CubeMX graphical configurator to set up peripherals and generate initialization code.
  6. Write your application code using the HAL APIs and middleware components.
  7. Build and flash the project to your STM32F4 board.

Competitor Comparisons

1,434

CMSIS Version 5 Development Repository

Pros of CMSIS_5

  • Broader compatibility across ARM Cortex-M devices
  • More comprehensive set of software interfaces and libraries
  • Active community support and regular updates

Cons of CMSIS_5

  • Steeper learning curve for beginners
  • Less specific optimization for STM32F4 series microcontrollers
  • May require additional configuration for specific hardware features

Code Comparison

CMSIS_5 example (generic ARM Cortex-M):

#include "cmsis_os2.h"

void Thread_1(void *argument) {
  for (;;) {
    // Thread code
  }
}

STM32CubeF4 example (STM32F4-specific):

#include "stm32f4xx_hal.h"

void SystemClock_Config(void) {
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  // Clock configuration code
}

CMSIS_5 provides a more generic approach suitable for various ARM Cortex-M devices, while STM32CubeF4 offers tailored solutions for STM32F4 microcontrollers. The choice between them depends on the specific project requirements and target hardware.

11,965

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.

Pros of Zephyr

  • Multi-architecture support: Zephyr supports a wide range of architectures and hardware platforms, not limited to STM32
  • Rich feature set: Includes a comprehensive set of features like networking, file systems, and power management
  • Active community: Large and active open-source community contributing to the project

Cons of Zephyr

  • Steeper learning curve: More complex and requires more time to master compared to STM32CubeF4
  • Less STM32-specific optimization: May not be as optimized for STM32 devices as the dedicated STM32CubeF4 package

Code Comparison

STM32CubeF4:

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
HAL_Delay(1000);

Zephyr:

gpio_pin_set_dt(&led, 1);
k_msleep(1000);
gpio_pin_set_dt(&led, 0);
k_msleep(1000);

Both examples show LED blinking, but Zephyr uses its own GPIO and timing APIs, while STM32CubeF4 uses HAL functions specific to STM32 devices.

15,071

Espressif IoT Development Framework. Official development framework for Espressif SoCs.

Pros of esp-idf

  • More comprehensive and feature-rich ecosystem for IoT development
  • Better support for wireless connectivity (Wi-Fi, Bluetooth)
  • Active community and frequent updates

Cons of esp-idf

  • Steeper learning curve for beginners
  • Limited hardware options compared to STM32 ecosystem
  • Higher power consumption in some scenarios

Code Comparison

STM32CubeF4 example (GPIO initialization):

GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

esp-idf example (GPIO configuration):

gpio_config_t io_conf = {};
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = (1ULL<<GPIO_NUM_5);
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 0;
gpio_config(&io_conf);

Both frameworks provide abstraction layers for hardware configuration, but esp-idf tends to offer more high-level APIs for complex tasks like networking and power management. STM32CubeF4 provides finer-grained control over hardware peripherals, which can be advantageous for certain applications requiring precise timing or low-level optimizations.

4,743

Arm Mbed OS is a platform operating system designed for the internet of things

Pros of mbed-os

  • Supports a wider range of ARM-based microcontrollers from various manufacturers
  • Provides a higher-level abstraction layer, making it easier for beginners to start developing
  • Offers cloud-based development tools and online compiler options

Cons of mbed-os

  • May have slightly higher overhead and resource usage compared to STM32CubeF4
  • Less optimized for specific STM32 microcontrollers than STM32CubeF4
  • Potentially slower execution for some low-level operations

Code Comparison

mbed-os example (LED blink):

#include "mbed.h"

DigitalOut led(LED1);

int main() {
    while (1) {
        led = !led;
        wait(0.5);
    }
}

STM32CubeF4 example (LED blink):

#include "stm32f4xx_hal.h"

int main(void) {
    HAL_Init();
    __HAL_RCC_GPIOA_CLK_ENABLE();
    GPIO_InitTypeDef GPIO_InitStruct = {0};
    GPIO_InitStruct.Pin = GPIO_PIN_5;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    while (1) {
        HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
        HAL_Delay(500);
    }
}

'Classic' FreeRTOS distribution. Started as Git clone of FreeRTOS SourceForge SVN repo. Submodules the kernel.

Pros of FreeRTOS

  • Platform-independent RTOS, supporting a wide range of microcontrollers
  • Extensive documentation and community support
  • Lightweight and efficient, suitable for resource-constrained devices

Cons of FreeRTOS

  • Requires more manual configuration compared to STM32CubeF4's HAL
  • Less hardware-specific optimizations for STM32F4 devices
  • Steeper learning curve for beginners in embedded development

Code Comparison

FreeRTOS task creation:

void vTaskFunction(void *pvParameters) {
    for (;;) {
        // Task code here
    }
}

xTaskCreate(vTaskFunction, "TaskName", STACK_SIZE, NULL, PRIORITY, NULL);

STM32CubeF4 HAL GPIO initialization:

GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

Both repositories serve different purposes: FreeRTOS provides a real-time operating system, while STM32CubeF4 offers hardware abstraction layers and drivers specific to STM32F4 microcontrollers. FreeRTOS is more versatile across platforms, while STM32CubeF4 provides optimized support for STM32F4 devices.

PX4 Autopilot Software

Pros of PX4-Autopilot

  • Comprehensive autopilot solution for drones and other unmanned vehicles
  • Large, active community with frequent updates and contributions
  • Supports a wide range of hardware platforms and sensors

Cons of PX4-Autopilot

  • Steeper learning curve due to its complexity and extensive features
  • Requires more computational resources compared to simpler firmware solutions
  • May be overkill for basic projects or hobbyist use

Code Comparison

PX4-Autopilot (main flight control loop):

void MulticopterAttitudeControl::control_attitude()
{
    // Calculate attitude error
    Vector3f attitude_error = _attitude_setpoint - _attitude;

    // Update PID controllers
    _rate_setpoint = _attitude_pid.update(attitude_error, _angular_velocity);

    // Apply rate controller
    _torque_sp = _rate_pid.update(_rate_setpoint - _angular_velocity);
}

STM32CubeF4 (basic LED toggle):

void LED_Toggle(void)
{
    HAL_GPIO_TogglePin(LED_GPIO_PORT, LED_PIN);
}

The code snippets highlight the difference in complexity and focus between the two projects. PX4-Autopilot deals with advanced flight control algorithms, while STM32CubeF4 provides low-level hardware abstraction for basic microcontroller operations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

STM32CubeF4 MCU Firmware Package

latest tag

[!IMPORTANT] This repository has been created using the git submodule command. Please refer to the "How to use" section for more details.

Overview

STM32Cube is an STMicroelectronics original initiative to ease developers' life by reducing efforts, time and cost.

STM32Cube covers the overall STM32 products portfolio. It includes a comprehensive embedded software platform delivered for each STM32 series.

  • The CMSIS modules (core and device) corresponding to the ARM(tm) core implemented in this STM32 product.
  • The STM32 HAL-LL drivers, an abstraction layer offering a set of APIs ensuring maximized portability across the STM32 portfolio.
  • The BSP drivers of each evaluation, demonstration or nucleo board provided for this STM32 series.
  • A consistent set of middleware libraries such as RTOS, USB, FatFS, graphics, touch sensing library...
  • A full set of software projects (basic examples, applications, and demonstrations) for each board provided for this STM32 series.

The STM32CubeF4 MCU Package projects are directly running on the STM32F4 series boards. You can find in each Projects/Board name directories a set of software projects (Applications/Demonstration/Examples).

[!NOTE]

Some middleware libraries and projects are unavailable in this repository

In this repository, the middleware libraries listed below along with this list of projects (demos, applications, and examples) using them, are not available as they (the middleware libraries) are subject to some restrictive license terms requiring the user's approval via a "click thru" procedure.

  • ./Middlewares/ST/STM32_Audio
  • ./Middlewares/ST/STemWin
  • ./Middlewares/ST/TouchGFX

If needed, they can be found inside the full firmware package available on our website st.com and downloadable from here. You will be prompted to login or to register in case you have no account.

Release note

Details about the content of this release are available in the release note here.

How to use

This repository has been created using the git submodule command. Please check the instructions below for proper use. Please check also the notes at the end of this section for further information.

  1. To clone this repository along with the linked submodules, option --recursive has to be specified as shown below.
git clone --recursive https://github.com/STMicroelectronics/STM32CubeF4.git
  1. To get the latest updates, in case this repository is already on your local machine, issue the following two commands (with this repository as the current working directory).
git pull
git submodule update --init --recursive
  1. To use the same firmware version as the one available on st.com, issue the command below after specifying the targeted vX.Y.Z version. This should be done after the command(s) indicated in instruction (1) or in instruction (2) above have been successfully executed.
git checkout vX.Y.Z # Specify the targeted vX.Y.Z version
  1. To avoid going through the above instructions and directly clone the same firmware version as the one available on st.com, issue the command below after specifying the targeted vX.Y.Z version.
git clone --recursive  --depth 1 --branch vX.Y.Z https://github.com/STMicroelectronics/STM32CubeF4.git

[!NOTE]

  • The latest version of this firmware available on GitHub may be ahead of the one available on st.com or via STM32CubeMX. This is due to the rolling release process deployed on GitHub. Please refer to this post for more details.
  • Option --depth 1 specified in instruction (4) above is not mandatory. It may be useful to skip downloading all previous commits up to the one corresponding to the targeted version.
  • If GitHub "Download ZIP" option is used instead of the git clone command, then the different submodules have to be collected and added manually.

Boards available

Troubleshooting

Please refer to the CONTRIBUTING.md guide.