AnsweredAssumed Answered

Strange MCU behaviour by passing pointer to stucture

Question asked by Tom on Mar 24, 2014
Latest reply on Mar 25, 2014 by Tom
Hi All,

I'm running some code on Discovery STM32L152 board.

I'm getting Hard Fault each time I initiate   structure fields in a function:

1.void pid_Init(float p_factor, float i_factor, float d_factor, pidData_t *pidPtr)
2.{
3.    pidPtr->lastProcessValue = 0;
4.    pidPtr->sumError = 0;
5.}

where:

typedef struct {
  int16_t lastProcessValue;
  int32_t sumError;
  float P_Factor;
  float I_Factor;
  float D_Factor;
  int16_t maxError;
  int32_t maxSumError;
} pidData_t;

I call the fuction by:

pid_Init(K_P,K_I,K_D,&pidData);

While debugging I noticed that:

The .map file shows that pidData is at address: 0x200034c0

when I step into line 3. of pid_Init I see that *pidPtr= 0x3fa99999 which is way beyond the actual pidData  address in SRAM.
In this situation pidPtr->lastProcessValue command of course causes Hard Fault.

How is it possible that the pidData  address passed to pid_Init is being set to some 0x3fa99999  value ???
I though about the stack size but it is  set to:


1./*----------Stack Configuration-----------------------------------------------*/ 
2.#define STACK_SIZE       0x00000500      /*!< Stack size (in Words)           */
3.__attribute__ ((section(".co_stack")))
4.unsigned long pulStack[STACK_SIZE];

and increasing its size brings nothing

Also I should have enough SRAM as the linker says:

1.Program Size:
2.    182488    10328    9192  202008   31518 DiscoveryCooCox.elf
3.      text     data     bss     dec     hex filename
4. 
5.BUILD SUCCESSFUL
6.Total time: 3 seconds

I've spent 2 days on that and already ran out of ideas and patience.
Can anyone help please?

Regards
Tom





Outcomes