2025-07-19 1:54 AM
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.
2025-07-19 1:56 AM
So what debugging have you done to find what's going on ?
Have you tried the examples provided by CubeIDE?
2025-07-19 2:26 AM
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.
2025-07-19 2:50 AM
@TechyAry wrote:Not sure how to debug this issue.
For a start, is it ever reaching the line where you toggle the pin?
2025-07-19 2:59 AM
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.
2025-07-19 3:10 AM
@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?
2025-07-19 4:09 AM - edited 2025-07-19 4:10 AM
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.
2025-07-19 5:11 AM - edited 2025-07-19 5:20 AM
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.