Search code examples
embeddedstm32stm32f4discovery

How do I start up a minimal project with STM32CubeMX?


I'm attempting to learn embedded development, and I'm currently playing around with a STM32F407G board.

So far, I've been able to toggle the LEDs based on the User button press using the high level driver APIs provided by the CubeMX.

However, I now want to recreate the same functionality without any API help. Instead, using the base addresses and registers provided in the reference manual, I want to basically recreate the APIs.

Thus far, I've disabled all the peripherals using the GUI:

enter image description here

But I feel like there's a better way to do this. I'm not entirely sure what peripherals I definitely need to even debug the code on the board.

Essentially, I want enough start-up code so that I'm able to load (flash?) the code into the microcontroller, and debug main(). Everything else (such as toggling the LEDs, detecting the User button interrupt, etc) will be something I want to take care of.


Solution

  • You do not need to recreate the APIs. Jest program using the registers. I do it all the time in almost all of my projects (unless using some kind of HAL is my client requirement)

    You need to have:

    1. startup code with the vector table.
    2. CMSIS headers for the convenience.

    How to archive it using the CubeMx. It is actually quite easy.

    1. Create the project
    2. Import to your favorite IDE.
    3. In the project options delete the USE_HAL_DRIVER definition
    4. Exclude from the build (or delete) all the files from the /Driver/STMxxxxx_HAL_Driver
    5. Delete everything from the main.c file

    Add:

    #include "stm32f4xx.h" // CMSIS headers
    
    int main(void)
    {
    }
    

    and enjoy :)