STM32CubeG4 MCU Firmware Package

repository·master·Indexed 43 days ago

https://github.com/stmicroelectronics/stm32cubeg4

A comprehensive software platform for the STM32G4 series, providing HAL/LL drivers, middleware, and software projects. Includes the CMSIS (Cortex Microcontroller Software Interface Standard) components such as Core, Driver, DSP, NN, and RTOS, along with an experimental CMSIS-DSP Python wrapper for testing algorithms using numpy.

Tokens
204.2K
Snippets
141
Records
1K
Agent score
52%

What's inside STM32CubeG4

  1. Overview of the USB Mass Storage (MSC) Standalone Application

    master

    The USB MSC Standalone application demonstrates how to use the STM32G4xx USB Device peripheral to implement a Mass Storage Class (MSC) device. The STM32 MCU acts as a bridge between a PC Host and a storage medium (such as a microSD card) using Bulk Only Transfer (BOT) and SCSI transparent commands.

    When running, the device is enumerated by the PC Host as a removable drive, allowing standard read, write, and format operations.

    Key Technical Details:

    • USB Speed: Full Speed (FS).
    • Clocking: The FS USB module requires an internal 48-MHz clock generated from an internal PLL.
    • Storage: Uses a microSD card as the underlying media.
    • Hardware Target: Tested on STM32G474E-EVAL Rev B, but portable to other STM32G4xx devices.
  2. Overview of Open Bootloader IAP application

    master

    The Open Bootloader IAP (In-Application Programming) application demonstrates how to develop and use an IAP application using the OpenBootloader Middleware. It allows for firmware updates or memory operations via supported communication protocols.

    Core Functionality

    1. Initialization: The application initializes peripherals via HAL_Init(), configures the system clock (SYSCLK) to 40 MHz via SystemClock_Config(), and sets up memory interfaces (FLASH, RAM, Option bytes).
    2. Protocol Support: It configures and waits for communication on:
      • USART1
      • FDCAN1
    3. Command Execution: Once a connection is established, the application waits for commands sent by a host (e.g., STM32CubeProgrammer).

    Critical Safety Note

    Mass Erase Protection: If performing a Mass Erase operation, you must protect the OpenBootloader FLASH area. Failure to do so will result in the OpenBootloader itself being erased, rendering the application unusable.

  3. Overview of USB Device CDC Standalone Application

    master

    This application implements a USB Device Communication Class (CDC) following the PSTN sub-protocol on STM32G4xx devices. It functions as a USB-to-UART bridge (Virtual COM Port/VCP), allowing an STM32 MCU to exchange data between a PC host (via USB) and another device or host (via UART).

    Key Features

    • Full-Duplex Communication: UART receiving is handled via interrupts, while transmitting is handled via DMA, allowing simultaneous bidirectional data flow.
    • Endpoint Configuration:
      • Bulk IN: Transmits data from STM32 to PC. Data received over UART is stored in UserTxBufferFS. A timer callback checks this buffer and transmits data in response to IN tokens.
      • Bulk OUT: Receives data from PC to STM32. Data is saved in UserRxBufferFS and transmitted over UART using DMA. The endpoint is NAKed during transmission and prepared for the next packet in HAL_UART_TxCpltCallback().
      • Interrupt IN: Handles control requests (Set line/Get line) for serial-port parameters like bit rate, stop bits, parity, and data bits via CDC_Control_FS().
  4. Overview of the STM32CubeG4 MCU Firmware Package

    master

    The STM32CubeG4 package provides a comprehensive embedded software platform for the STM32G4 series. It includes:

    • CMSIS modules: Core and device modules for the ARM core.
    • STM32 HAL-LL drivers: Abstraction layers (Hardware Abstraction Layer and Low-Layer) for portability.
    • BSP drivers: Board Support Package drivers for specific evaluation, demonstration, or Nucleo boards.
    • Middleware libraries: RTOS, USB, FatFS, graphics, touch sensing, etc.
    • Software projects: Applications, demonstrations, and basic examples located in Projects/<Board_Name> directories.
  5. Overview of the USB DFU Standalone Application

    master

    The USB Device Firmware Upgrade (DFU) application provides a compliant implementation for programming embedded Flash memory via the USB peripheral. It supports two operating modes:

    1. DFU operating mode: Entered if the user forces it (by pressing the sw2 button) or if no valid code is found in the application area. A code is considered valid if the MSB of the initial Main Stack Pointer (MSP) value at the first address of the application area equals 0x2000.
    2. Run-time application mode: Normal application execution (e.g., toggling an LED).

    Memory Layout:

    • DFU area: [0x08000000 : USBD_DFU_APP_DEFAULT_ADD-1] (Read-only).
    • Application area: [USBD_DFU_APP_DEFAULT_ADD : Device's end address] (Read, Write, and Erase access).
  6. Overview of Buck Current Mode Software Example

    master

    This application implements a Buck converter to output a regulated 3.3Vdc voltage using two selectable embedded loads. The control loop operates in current mode, where the compensator is executed by the CPU. It utilizes the HRTIMER (High-Resolution Timer) IP for power supply control.

    Key Specifications:

    • Target Device: STM32G474RET6
    • Tested Hardware: B-G474E-DPOW1 board
    • Control Mode: Current mode in CCM (Continuous Conduction Mode)
    • Keywords: PSU, BUCK converter, Current mode, CCM, STM32 Digital Power, HRTIMER usage
  7. Overview of Buck Current Mode (CCM) Digital Power Application

    master

    This application implements a Buck converter that outputs a regulated 3.3Vdc voltage using two selectable embedded loads. The control loop operates in current mode (Continuous Conduction Mode - CCM) and utilizes the FMAC IP (Filter Mathematical Accelerator) to execute the compensator. The implementation relies on the HRTIMER (High-Resolution Timer) for precise timing.

    Key Components:

    • Control Loop: Current mode control.
    • Compensator: Executed via FMAC IP.
    • Hardware Target: STM32G474RET6 (tested on B-G474E-DPOW1 board).
  8. Overview of the HRTIM Dual Buck Example

    master

    This example demonstrates how to configure the High-Resolution Timer (HRTIM) to manage two buck converters using a single timer unit (Timer D). It utilizes both the STM32G4xx HRTIM HAL and LL APIs.

    Key Features

    • Dual Buck Control: Uses Timer D with outputs TD1 (PB14) and TD2 (PB15).
    • Dynamic Duty Cycle: The duty cycle for TD1 is continuously varied within an Interrupt Service Routine (ISR) triggered by a repetition event to simulate real-world converter management.
    • Fault Protection: FAULT2 is enabled on PA15 (active low). Triggering a fault (connecting PA15 to GND) stops the TD1 signal. The system can be re-armed using the user button.
    • ADC Integration: The ADC is configured to trigger conversions in the middle of the ON time of each converter (non-overlapping PWM signals) via input PA1.

    LED Status Indicators

    • Green LED: Blinks during normal operation.
    • Red LED: Blinks when a FAULT is triggered.
    • Orange LED: Indicates the occurrence and duration of the PWM refresh ISR.
  9. Overview of the USB-PD Consumer 1-port Example

    master

    This application demonstrates how to implement a simple USB Type-C Consumer (Sink) using an STM32G4 device. It initializes Type-C port 1 in sink mode with a single Power Data Object (PDO) at 5V.

    Key Features

    • Sink Mode: Configures the device to consume power.
    • Single PDO: Provides only 5V power capability.
    • Tracing: Supports message exchange tracing via the UCPD Cube Monitor on the associated Virtual COM Port (VCP).

    Hardware Requirements

    • Target MCU: STM32G474RET6
    • Recommended Board: STM32G474E-DISCOVERY

    Software Environment

    • RTOS: FreeRTOS
    • Stack: USB-PD Library (UCPD, DPM, VDM)
  10. Overview of Buck Voltage Mode (CCM) Digital Power Example

    master
    This application implements a Buck converter operating in Continuous Conduction Mode (CCM) to regulate an output voltage at 3.3Vdc. The control loop is executed in voltage mode, utilizing the HRTIMER and FMAC (Filter Math Accelerator) IPs for compensation. The application supports two selectable embedded loads for testing.
  11. Overview of the DFU Standalone Application

    master

    The DFU (Device Firmware Upgrade) Standalone application provides a compliant implementation for programming embedded Flash memory via the USB peripheral. It supports two operating modes:

    1. DFU Operating Mode: Entered if the user forces it (e.g., pressing the sw2 button) or if no valid application code is found in the application area. A code is considered valid if the MSB of the initial Main Stack Pointer (MSP) value at the application area's first address is 0x2000.
    2. Run-time Application Mode: Normal application execution (e.g., toggling an LED).

    Memory Layout:

    • DFU Area: [0x08000000 : USBD_DFU_APP_DEFAULT_ADD-1] (Read-only access).
    • Application Area: [USBD_DFU_APP_DEFAULT_ADD : Device's end address] (Read, Write, and Erase access).
  12. Understand the PWR_SLEEP Example behavior

    master

    The PWR_SLEEP example demonstrates how to enter Sleep mode and wake up the MCU using an interrupt.

    System Behavior:

    • Clock Speed: The system clock is configured to 150 MHz.
    • Sleep Entry: The system automatically enters SLEEP mode 5 seconds after start-up.
    • Wake-up Mechanism: An EXTI (External Interrupt) line is connected to the user button on pin PC.13. Pressing the button triggers a falling edge interrupt that wakes the system.
    • Post-Wakeup: After waking up, the system remains in RUN mode for 5 seconds before automatically re-entering SLEEP mode.

    Status Monitoring via LED2:

    • Toggling LED2: Indicates the system is in RUN mode.
    • LED2 Off: Indicates the system is in SLEEP mode.

    Hardware Configuration (NUCLEO-G431RB RevC):

    • LED2: Connected to pin PA.05.
    • User Button: Connected to pin PC.13 (EXTI line 13).