cancel
Showing results for 
Search instead for 
Did you mean: 

My projects don't work after upgrading Cube IDE to 1.19.1

TechyAry
Associate III

I used Cude IDE version 1.18.1. successfully then upgraded and wrote the second project (timer). I'm using Nucelo-64 STM32 F411RE with clock rate 84Mhz.  
My new project is to use the TIM4 with the settings: PSC: 8399, CP: 10000 to toggle the LED per second. The LED doesn't turn on/off whatsoever. (My prior project - to use the user button - doesn't work either!)
My files: lib.hpp

 
#ifndef INC_LIB_HPP_
#define INC_LIB_HPP

#if __cplusplus
extern "C" {
#endif

void run();
void HAL_GPIO_EXTI_Callback(uint16_t);
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *);

#if __cplusplus
}
#endif
#endif

lib.cpp:

#include "main.h"
#include "lib.hpp"
#include <stdio.h>

auto pressed = 0u;
auto flag = false;

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
	if(GPIO_Pin == B1_Pin)
		flag = true;
	else flag = false;
}

 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	 HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin);
}

void run() {
	while (1) {
		if(flag){
			pressed++;
			flag = false;
			HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
		}

		else
			HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
	} // End of while (1)
}

main.c file is rather big hence attached below.

 

7 REPLIES 7
Andrew Neil
Super User

So what debugging have you done to find what's going on ?

Have you tried the examples provided by CubeIDE?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Not sure how to debug this issue.
I've already done projects for blinking the LED and playing with the user button, using the same IDE and MCU, successfully. 

I added the line below to the header:

extern TIM_HandleTypeDef htim4; 

Also modified the function in lib.cpp: 

 void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
	 if(htim == &htim4)
		 HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin);
}

I get no warnings/errors yet no expected result. 


@TechyAry wrote:

Not sure how to debug this issue.


For a start, is it ever reaching the line where you toggle the pin?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

Primary you dont show any error that is based upgrade. 

Secondary every sw can be fail, and for real upgrade is recommend test new versions before use ...

But your explained issue is based only on your bad code.


@TechyAry wrote:

I get no warnings/errors yet no expected result. 


Getting no errors/warnings simply tells you that the syntax is valid.

It's like spell-checking a document: it tells you that all the words are correctly spelled, but does not guarantee that they are the correct words, nor that the text actually makes any sense.

 


@TechyAry wrote:

no expected result. 


I think you need to check your expectations!

You seem to have both the timer and the EXTI toggling the same LED - how do you expect this to work?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

The problem is with 

else
  HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);

 in while(1) in run. Since flag is by default false, the else part will execute forever not letting the toggle function work properly. 

So the problem is actually with setting flag, then.

"flag" is a really poor name. If you gave it a more descriptive name - describing what you actually want it to do - that might help to show up the problem...

 

As it stands, flag only gets set when an EXTI interrupt occurs on B1_Pin

What did you actually want to happen?

 

As @MM..1 said, this is inherent in your code - this would not have changed with an upgrade to the IDE.

Edit to add:


@TechyAry wrote:

I used Cude IDE version 1.18.1. successfully then upgraded and wrote the second project (timer). 


So you had a working project on IDE v1.18.1

You upgraded to v1.19.1, and then wrote an entirely different project.

You attribute the fact that this 2nd, entirely different, project doesn't work to the change in IDE version!

That makes no sense at all! The problem is the new code - not the IDE version.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.