2024-01-02 08:00 PM - last edited on 2024-01-05 04:18 AM by SofLit
I think the bad LR address might be the problem, i.e. reffering to the non-exist address in disassembly, note that in disassembly window (number 2) there is no address 0x8000955 after 0x08000954, but it goes straight to 0x8000956 instead.
2024-01-03 09:05 AM
I don't see the ADC peripheral address anywhere in the list.
Perhaps compile with USE_FULL_ASSERT defined so the library code can sanity check some of the parameters and fields for you.
2024-01-03 11:38 PM
>Suggest if you have printf() working, that a) you print out the pointer "%p", b) dump out the structure, and c) the pointer for hadc->Instance
What i understood
a) i need to add printf("%p") in the end of the while(1) (please correct my printf code)
b) i dont know to do this and what structure mean... please bear with me
c) im not sure how to print out the hadc->Instance pointer
I hope you would help me what to do.. i didnt really find anything in google..
2024-01-03 11:41 PM
> Perhaps compile with USE_FULL_ASSERT defined so the library code can sanity check some of the parameters and fields for you.
to do that do i just add the "#define USE_FULL_ASSERT" in the main code?
2024-01-04 12:37 AM
Do immediately prior to you calling HAL_ADC_ConfigChannel()
printf("%p\n", &hadc);
printf("%p\n", hadc->Instance);
also dump(sizeof(hadc), (uint8_t*)&hadc);
write a dump(size_t size, uint8_t *buffer) function that prints out the bytes in memory
2024-01-05 08:07 PM
Hi, @Tesla DeLorean
Thank you for your advices i just got the time to do it today. So i have changed the ADC from STM32CUBEMX all over again following my old reference, and i changed the HardFault handler to the one which is more dense. I retrace the Hard Fault and find that the code faults exactly at this code here which i supposed is for changing the sampling time(?)
Heres the clearer code (its on the clear old sample time)
if (sConfig->Channel > ADC_CHANNEL_9)
{
/* Clear the old sample time */
hadc->Instance->SMPR1 &= ~ADC_SMPR1(ADC_SMPR1_SMP10, sConfig->Channel);
/* Set the new sample time */
hadc->Instance->SMPR1 |= ADC_SMPR1(sConfig->SamplingTime, sConfig->Channel);
}
else /* ADC_Channel include in ADC_Channel_[0..9] */
{
/* Clear the old sample time */
hadc->Instance->SMPR2 &= ~ADC_SMPR2(ADC_SMPR2_SMP0, sConfig->Channel);
/* Set the new sample time */
hadc->Instance->SMPR2 |= ADC_SMPR2(sConfig->SamplingTime, sConfig->Channel);
}
and here is the Hardfault printf output
[Hard Fault]
r0 = 200000D8, r1 = 20000FA8, r2 = 00000001, r3 = 00000007
r4 = 00000000, r5 = 4D575020, r6 = 40021000, sp = 20000F48
r12= 00000000, lr = 080038B3, pc = 08000AD6, psr= 81000200
bfar=4D575030, cfsr=00008200, hfsr=40000000, dfsr=00000003, afsr=00000000
00000309 080065E8 20000F90 20000F88 08005C7B 20000000 200002EC 00000000
200000DE 00000014 00000000 08002BD5 00000014 20000000 000003E8 40021000
000003E8 00000200 40000438 00000000 20000000 000003E8 40021000 080038B3
00000001 00000001 00000000 00000000 20000000 08006215 00000003 00000010
409A 6803 68DD 432A 60DA E010 2002 BD78(692E)EB02 0242 4093 439E 612E
===================================================================================
So now do i put the print %p and dump before that code line?
Thank you again.