STM32 C++ Page

From bibbleWiki
Revision as of 22:40, 5 February 2025 by Iwiseman (talk | contribs) (Blinky on Steriods)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

This page is to capture information relating to C++ and STM32

Blinky

This was a journey to build a blinky for STM32 using this new knowledge of how to build a HAL. Luckily there is always out there. Many thanks for AFontaine79. Lots of experience with this but near to none on arm so the example https://github.com/AFontaine79/stm-blinky put me on by way.
Really this is to provide the framework for making an ARM binary. I include the STM32 propriety software and the ARM headers to make this all work. So I need the CMSIS directory which comes with CubeMX and the cortex headers which come with the ARM SDK. In the end the project looked like this, where HAL is where my own hal files are.

An where is my blinky

#include "stm32F302xx.h"
#include "stm32F302_gpio.h"

void delay(void) {
    for(uint32_t i=0; i<5000/2;i++);
}

int main(void) {
    GPIO_Handle_t GpioLed;

    GpioLed.pGPIOx = GPIOB;
    GpioLed.GPIO_PinConfig.GPIO_PinNumber = GPIO_PIN_NO_13;
    GpioLed.GPIO_PinConfig.GPIO_PinMode = GPIO_MODE_OUTPUT;
    GpioLed.GPIO_PinConfig.GPIO_PinSpeed = GPIO_SPEED_LOW;
    GpioLed.GPIO_PinConfig.GPIO_PinOPType = GPIO_OP_TYPE_PP;
    GpioLed.GPIO_PinConfig.GPIO_PinPuPdControl = GPIO_PIN_NO_PUPD;

    GPIO_PeriClockControl(GPIOB, ENABLE);

    GPIO_Init(&GpioLed);

    while (1) {
        // GPIO_WriteToOutputPin(GPIOB, GPIO_PIN_NO_13, GPIO_PIN_SET);
        GPIO_ToggleOutputPin(GPIOB, GPIO_PIN_NO_13);
        delay();
        //GPIO_WriteToOutputPin(GPIOB, GPIO_PIN_NO_13, GPIO_PIN_RESET);
    }
    {
        /* code */
    }
    
    return 0;
}