cancel
Showing results for 
Search instead for 
Did you mean: 

Setting up a STM32CubeIDE project - Is there a correct way ?

ambinabhi
Associate II

HI Community,

I am working on developing applications on my STM32 IoT Discovery Kit. So far am able to compile examples/demos and they are working perfectly fine on STM32CubeIDE. However i want to setup my own project hereafter, I am facing lot of problems when i generate new STM32 project by targeting my board on CubeMX and working on generated codes.

  1. The code don't work exactly with CubeMX generated projects. I face problems in transmitting on UART or getting SPI interrupt for Wifi setup or someother way, but it works perfectly fine with example code
  2. The example/template doesn't have .ioc file. Is that how they are supposed to be ?
  3. I even copied code from examples and put it my project(CubeMX generated), but somewhere the HAL files don't match and functionality breaks down although project compiles properly.

Whats the correct way to start a new project on STM32CubeIDE ? All the example code refer different folder structure on x-cube-cld-gen libraries. Are we supposed to just build on example projects ?

3 REPLIES 3
Andrew Neil
Evangelist III

@ambinabhi wrote:
  1. The code don't work exactly with CubeMX generated projects. I face problems in transmitting on UART or getting SPI interrupt for Wifi setup or some other way, but it works perfectly fine with example code

Then you need to debug your code to see what's going wrong.

When you have an example that does work, compare your code to that - see where they differ.

Use the debugger to step through the example code, then use the debugger to step through your code - see what's different.

 


@ambinabhi wrote:

2. The example/template doesn't have .ioc file. Is that how they are supposed to be ?


Indeed - not all examples have .ioc files:

https://community.st.com/t5/stm32-mcus-products/some-example-projects-don-t-use-ioc-file/m-p/698330

 


@ambinabhi wrote:

3. I even copied code from examples and put it my project(CubeMX generated), but somewhere the HAL files don't match and functionality breaks down although project compiles properly.


This is not specific to STM32CubeIDE or ST - when taking any code from one project to another, you're going to have to spend some time checking dependencies, etc.

This is just an everyday part of software development.

 


@ambinabhi wrote:

Whats the correct way to start a new project on STM32CubeIDE ? All the example code refer different folder structure on x-cube-cld-gen libraries.


That's entirely up to you. STM32CubeIDE does not constrain you to any particular folder structure - use whatever works for you.

https://community.st.com/t5/stm32cubeide-mcus/project-organisation-in-cubeide-how-to-go-about-libraries/m-p/734773/highlight/true#M31820

Of course, any time you bring in any 3rd-party code it will have its own internal structure - so you're always going to work out how to accommodate that in your own project

 


@ambinabhi wrote:

Are we supposed to just build on example projects ?


That can certainly be a valid approach.

Starting from a working base can be a lot easier than trying to create a working base from scratch ...

Pavel A.
Evangelist III

> Are we supposed to just build on example projects ?

Short answer - yes. Developer or team with suitable experience and background will be able to get a working example (call it prototype) themselves, in a way that Andrew described (start from anything working, compare sources, debug).

For developer or team without experience the best option is to find a consultant  -who will make a working prototype, set up the tools, find documentation and bring other goodies.

 

Karl Yamashita
Lead III

When generating code that you want to interrupt like for UART or SPI, you have to enable NVIC. You didn't mention that you have enable them. Attach your project so we can see if you've initialized peripherals correctly..

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.