cancel
Showing results for 
Search instead for 
Did you mean: 

How to import or use code in STM32CubeIDE when project exists for different MCU

G0MGX
Associate

I would like to be able to utilise code like this: https://github.com/ciastkolog/BMP280_STM32 on my Nucleo-L476RG. Is there an easy way to create a project and then import the source code or change the MCU type in the existing project?

Everything I try results in a new project with an MCU type I dont have.

I'm very new so please excuse my muppetry.

4 REPLIES 4
TDK
Guru

>Is there an easy way to create a project and then import the source code

Yep. Start with a project that works and just copy files over to it. Looks like the library you linked has only two real library files (bmp280.c/bmp280.h).

> or change the MCU type in the existing project?

This will vary in complexity depending on how different the two targets are. Are you trying to port the example for the STM32F0DISCO board onto your Nucleo-L476RG? If so, the linker script will the different. The CMSIS, HAL libraries, and startup code will differ as well. You'd have to update all of these. Probably some #defines as well

It's probably easier to take an existing project which runs on your board as the skeleton and move the core source/include files into that project.

If you feel a post has answered your question, please click "Accept as Solution".
TDK
Guru

> Everything I try results in a new project with an MCU type I dont have.

Why? Start up STM32CubeMX, chose the MCU you have, configure it, and hit generate code.

If you feel a post has answered your question, please click "Accept as Solution".

0693W000000WENDQA4.png

Thanks for the help.

I must be very stupid. I've copied a working project, then copied the two files into the new project. Compiling fails for a number of reasons but mainly due to the #include "stm32f0xx_hal.h" in the bmp280.h file, which is clearly irrelevant.

I can't find how to re-generate code.

I think I'll go back to Arduino.... :(

TDK
Guru

> Compiling fails for a number of reasons but mainly due to the #include "stm32f0xx_hal.h" in the bmp280.h file, which is clearly irrelevant.

Your chip has a "stm32l4xx.h" file instead that you should include. You're going to run into issues when porting code. Just need to tackle them one at a time.

Arduino definitely has a lower entry bar.

If this is your first project, maybe it'd be easier to look at examples in the STM32CubeL4 repository until you can get those up and running in the environment.

If you feel a post has answered your question, please click "Accept as Solution".