cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE only running code from one project

dj-b
Visitor

Hello all, I am currently working with the STM32CubeIDE. I wrote a program that didn't end up working but concluded the code was fine after reviewing it. I tried copy and pasting the code into a different project within the IDE, and it works just fine. Does anyone know why this might be?

The code does not work when pasted into existing projects, or new projects, except for the one particular existing project. There are no error codes thrown when it doesn't work; it builds and downloads to the board just fine but then doesn't run.

The program is attached.

3 REPLIES 3
Pavel A.
Evangelist III

It is a perfect puzzle : ) Not possible to tell is you code fine or not. It may be fine under certain conditions and not fine under other conditions  - so called 'contract'. Consider that even a broken watch shows the correct time twice in a day. Debugger is your friend.

 

 


@dj-b wrote:

The code does not work when pasted into existing projects, or new projects, except for the one particular existing project. 


Sounds like it depends on something that is in that one particular project, and missing from all the others.

You're going to have to do some debugging to investigate what's going on.

Debugging is a key skill in development: You need to get beyond just throwing your hands up and saying, "it doesn't work" - that tells nothing.

Think about:

  • What, exactly, do you expect that it should do?
  • What, exactly, does it actually do?
  • Think about what could account for the difference.

As you have a case where it works, and others where it doesn't, Carefully compare & contrast what happens in the working case to what happens in the non-working cases.

Some debugging tips:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/tac-p/706966/highlight/true#M49


@dj-b wrote:

The code does not work when pasted into existing projects, or new projects, except for the one particular existing project. .


Just taking random chunks of code and arbitrarily dumping into other random code is unlikely to give good results!

As @Pavel A. suggests, your need to understand the code you're copying, and the context it comes from, and the context it's going into - and those all have to match.

 


@dj-b wrote:

There are no error codes thrown when it doesn't work


Do you mean when you build it (compiler & linker errors), or while it's running?

At build time, the compiler (and linker) are really just like running a spell-check in a wordprocessor: it can tell you that all of your words are correctly spelled, but that doesn't mean that they are the correct words, or that they make any sense in the way you've used them.

So the absence of build errors is not a guarantee that your code will actually run as you wanted.

At run time, error messages will only be produced if you have written code to detect the errors and report them.

 

PS:

You've titled this, "STM32CubeIDE only running code from one project"

It's important to understand that STM32CubeIDE (and other similar IDEs) does not actually run your code at all.

The IDE helps you to write your code, build it, and download it to the target - but it doesn't actually run the code.

The code runs in the Target STM32 microcontroller.