cancel
Showing results for 
Search instead for 
Did you mean: 

hardfault handler when executing same code but in diferent place

ionutF
Associate III
Posted on November 11, 2016 at 18:44

I ran into a new error for me:

It seems there may be something related with code placement I have the next code which fires the Hard Fault interrupt at the instruction

TIM_TimeBaseStructure.TIM_Prescaler = (u16)((a.SYSCLK_Frequency/1000000)-1);

// hard fault entered here

int
main(
void
)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f0xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f0xx.c file
*/
u8 i=0;
adc_config();
__disable_irq();
gpio_config();
tim_config();
FLASH_Unlock(); 
//Unlock the Flash Program Erase controller
EE_Init();
while
(1){}
}
void
tim_config(
void
)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
//ADC timer configuration
/* TIM3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
// SystemCoreClockUpdate();
RCC_ClocksTypeDef a;
RCC_GetClocksFreq(&a);
/* Time base configuration */
//clock de 1MHz
/////////timer display
TIM_DeInit(TIM14);
/* TIM14 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14, ENABLE);
TIM_TimeBaseStructure.TIM_Period = DisplayRefreshPeriod-1;
TIM_TimeBaseStructure.TIM_Prescaler = (u16)((a.SYSCLK_Frequency/1000000)-1);
// hard fault entered here
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV4;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_RepetitionCounter=0;
//other cod 
}

And I have taken the code from tim_config() which caused the Hard Fault and put it in the main loop. This time no Hard Fault Interrupt is fired The code:

int
main(
void
)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f0xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f0xx.c file
*/
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
RCC_ClocksTypeDef a;
RCC_GetClocksFreq(&a);
TIM_DeInit(TIM14);
TIM_TimeBaseStructure.TIM_Period = DisplayRefreshPeriod-1;
TIM_TimeBaseStructure.TIM_Prescaler = (u16)((a.SYSCLK_Frequency/1000000)-1);
//1MHz clock
u8 i=0;
adc_config();
__disable_irq();
gpio_config();
while
(1){}
}

Why such behaviour? If i replace the

a.SYSCLK_Frequency with its value (8000000) it works

The last asm instruction before hard fault isbl 0x8001b54 <__udivsi3>
1 REPLY 1
ionutF
Associate III
Posted on November 11, 2016 at 19:10

I think i found the cause.

The EE_Init() function I suppose it was erasing from my flash memory were it supposed  not to,

I modified the EEPROM_START_ADDRESS constant to 0x08008000 , meaning after 32kB of flash. The initial value was 0x08002000 (after 8 kB of flash)