2025-07-29 8:30 AM - edited 2025-07-29 8:32 AM
Hi ! I'm working on a STM32F429VET, with keil as an IDE.
My problem is the next, this code which is NOT reached (because it need a command from the terminal to be). Make my entire program crash in contact of loop, causing an IACCVIOL if i let this part of the code commented, works fine if i uncomment it. Anybody have encounter similiar behavior ? I dont get it at all.
void adc_measure(uint16_t channel, uint8_t *result)
{
measureInProgress = true;
adc_init(channel);
HAL_TIM_Base_Start_IT(&htim2);
// while (measure_pending_count < NB_MEASURES)
// {
//
// adc_read();
// __disable_irq(); // Prevent race condition
// measure_pending_count++;
// __enable_irq();
//
// }
HAL_ADC_Stop(&hadc1);
float measure = adc_compute_value(channel); // convert the value toward needed unit (mA or V)
//snprintf((char *)result, RESULT_PRECISION, "%f", measure);
}
2025-07-30 1:58 AM
@tfde wrote:It seems like the program go out of memory bound
That's a hypothesis - so the next step is to test that hypothesis.
As suggested earlier, you might set a breakpoint shortly before the fault occurs, then step and see what happens...
Or, if the "out of bounds" access is consistent, perhaps set a breakpoint (data or code) at the affected address...
@tfde wrote:i dont get how commenting a file change the issue of that.
As noted earlier, it's possible that the extra code changes the memory layout; it's then possible that a previously benign bug becomes a problem ...
Again, this is just speculation - it needs to be tested.
2025-07-30 2:18 AM - edited 2025-07-30 2:40 AM
adc_reset_value() is only called once. So measureCount, used as your array index, is not set to zero so it keeps increasing beyond the length of the buffer. This is a buffer overflow!
Edit: I see you are calling adc_init() every time you do a measurement instead of once. This is not the way you should use the ADC. You need to initialize your peripheral only once. Also avoid using global variables if possible. But at least this clears measureCount. The problem is elsewhere.
2025-07-30 2:23 AM
Keil welcome me with an error if try to put a bp close to where it crash
2025-07-30 2:25 AM
Hi! Maybe im overlooking something but, its call everytime i use adc_measure () so the value are reset everytime they need to be ?
2025-07-30 2:26 AM - edited 2025-07-31 1:16 AM
The entire code could use improvement:
2025-07-30 2:27 AM
@tfde wrote:I do really think its some kind of stack overflow but 1. i don't know how to prove that and 2. i dont know how to debug that.
Take a look at Keil's Application Note AN316, Determining the stack usage of applications...
2025-07-30 8:14 AM
Random failing, I'd double check the PLL settings, and FLASH WAIT STATES, and electrically the voltage observed on VCAP pins, and the amount of capacitance actually placed, ie 2u2 per pin or 4u7 in total