2014-07-23 02:49 PM
Hi everybody,
I'm trying migrate a program from 28335 to stm32f407. I was using a structure to store some data, and passing the pointer to this structure to a function. Now I find that if I define the structure variable as global before main, it will always cause Hardfault exception. If I define it in main, a Hardfault exception will happen if I call the function that will use the structure variable in main. In both situation, the Hardfault exception happens once the main is entered, that is, after the startup file's jump instruction (BX) and the first { after main(void), before any statement in main. So am I using the structure wrong?Thank you!2014-07-23 02:55 PM
So am I using the structure wrong?
Apparently the processor thinks so... Present a concise example that demonstrates the problem.2014-07-23 02:59 PM
typedef struct
{ float Kp; float Ki; float Error_new; float Error_old; float PIout_new; float PIout_old; float Maxvalue; float Minvalue; float Ref; float Det;}PIdata;PIdata IL_ctrl;If I put these before main, a hardfault exception will happen once it enters main.2014-07-23 04:13 PM
So my wild guess would be that your unspecified tool chain is generating FPU instructions for the F4, and you don't have them enabled in your code.
You need to look at your defines, and the enabling code in SystemInit(), system_stm32f4xx.c/**
* @brief Setup the microcontroller system
* Initialize the Embedded Flash Interface, the PLL and update the
* SystemFrequency variable.
* @param None
* @retval None
*/
void SystemInit(void)
{
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL <<
10
*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
#endif
/* Reset the RCC clock configuration to the default reset state ------------*/
/* Set HSION bit */
RCC->CR |= (uint32_t)0x00000001;
...
2014-07-24 08:47 AM
Thank you! That works.
I didn't expect that they didn't enable FPU in the example code.I had a look at the disassembly, VPUSH is generated at the beginning of main when I use structure.