AnsweredAssumed Answered

STM32 HardFault_Handle

Question asked by flodin.rickard.001 on Aug 7, 2014
Latest reply on Aug 11, 2014 by flodin.rickard.001
I have a problem in STMF103C8T7 and I can't find the solution.

The STM32 reads corrupt data in array and when reaching a certain memory adress it crashes.

The array look like this:
typedef struct
int32_t v1;
int32_t v2;
uint32_t v3;
short v4;

#define DATA_LENGTH 850
V_Data data[DATA_LENGTH];

Reading index 670 to 696 results in corrupt data. When writing to index 697 HardFault Exception occures. Variables after the array can be read witthout problems

The .map file looks like:
0x20001268 other variable
0x2000126c data array
0x2000478c other variable, can be ead and written
0x20004790 other variable, can be ead and written
0x20004858 other variable, can be ead and written
0x2000485c other variable, can be ead and written

The corrupt data starts at
0x2000126c + 670 * 16 = 15436 => 0x20003C4C

The crash address is at
0x2000126c + 697 * 16 = 15868 => 0x20003DFC

The STM32 has 20 kB SRAM and SRAM starts at adress 0x20000000 with size 0x00005000.

I have put protection around pointeras and arrays which could access the data array.Since Hardfault exception occurs I suspects that there is something wrong in the memory mapping.

Heap and stack are located on:

.heap 0x20004a04 0x0
0x20004a04 __end__ = .
0x20004a04 _end = __end__
0x20004a04 end = __end__
0x20004a04 __HeapLimit = .

.co_stack 0x20004a04 0x404 load address 0x0801377c
0x20004a08 . = ALIGN (0x8)
*fill* 0x20004a04 0x4 
*(.co_stack .co_stack.*)
.co_stack 0x20004a08 0x400 ..\obj\startup_stm32f10x_md.o
0x20004a08 pulStack
0x20005000 __StackTop = (ORIGIN (ram) + 0x5000)
0x20004bfc __StackLimit = (__StackTop - SIZEOF (.co_stack))
0x20005000 PROVIDE (__stack, __StackTop)
0x00000001 ASSERT ((__StackLimit >= __HeapLimit), region ram overflowed with stack)

I am using GCC 4.8.2 and CooCox 1.7.6