cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f7 HardFault, unaligned memory access

troy1818
Senior
Posted on August 26, 2016 at 15:29

Hi,

Using STM32F756.

I have a weird problem. I get hard fault with unaligned address at random locations. Example:

#0  HardFault_Handler () at ./hw/irq/irq.c:84

#1  <signal handler called>

#2  0x0801d7a4 in cia_step (cc=0x4) at ./emucc/cia.c:694

#3  0x080178d8 in if_emu_cc_op_run (cycles=0x190) at ./emucc/emuccif.c:181

#4  0x0801759c in sm_run () at ./hw/sm/sm.c:474

#5  0x08016cc0 in main () at ./hw/main/main.c:294

692 void cia_step(uint32_t cc)

693 {

694   g_cycles_in_queue += cc;

695   uint32_t i; /* cia */

696   uint32_t j; /* a or b */

697 

698   if(g_cycles_in_queue >= MIN_QUEUE_SIZE)

 │0x801d794 <cia_step>            push   {r4, r7}

 │0x801d796 <cia_step+2>          sub    sp, #16

 │0x801d798 <cia_step+4>          add    r7, sp, #0

 │0x801d79a <cia_step+6>          str    r0, [r7, #4]

 │0x801d79c <cia_step+8>          ldr    r3, [pc, #504]  ; (0x801d998 <cia_step+516>)

 │0x801d79e <cia_step+10>         ldr    r2, [r3, #0]

 │0x801d7a0 <cia_step+12>         ldr    r3, [r7, #4]

 │0x801d7a2 <cia_step+14>         add    r3, r2

>│0x801d7a4 <cia_step+16>         ldr    r2, [pc, #496]  ; (0x801d998 <cia_step+516>)

 │0x801d7a6 <cia_step+18>         str    r3, [r2, #0]

 │0x801d7a8 <cia_step+20>         ldr    r3, [pc, #492]  ; (0x801d998 <cia_step+516>)

 │0x801d7aa <cia_step+22>         ldr    r3, [r3, #0]

 │0x801d7ac <cia_step+24>         cmp    r3, #31

 │0x801d7ae <cia_step+26>         bls.w  0x801d98c <cia_step+504>

 │0x801d7b2 <cia_step+30>         ldr    r3, [pc, #484]  ; (0x801d998 <cia_step+516>)

 │0x801d7b4 <cia_step+32>         ldr    r3, [r3, #0]

(gdb) print *(SCB_Type *)(0xE000E000 + 0x0D00)

$6 = {CPUID = 0x410fc271, ICSR = 0x440f803, VTOR = 0x8000000, AIRCR = 0xfa050300, SCR = 0x0, CCR = 0x70200, 

  SHPR = '\000' <repeats 11 times>, ''\020'', SHCSR = 0x10000, CFSR = 0x1000000, HFSR = 0x40000000, DFSR = 0xb, MMFAR = 0x0, BFAR = 0x0, 

  AFSR = 0x0, ID_PFR = {0x30, 0x200}, ID_DFR = 0x100000, ID_AFR = 0x0, ID_MFR = {0x110030, 0x0, 0x1000000, 0x0}, ID_ISAR = {0x1101110, 

    0x2112000, 0x20232231, 0x1111131, 0x1310132}, RESERVED0 = {0x0}, CLIDR = 0x9000003, CTR = 0x8303c003, CCSIDR = 0xf003e019, CSSELR = 0x0, 

  CPACR = 0x0, RESERVED3 = {0x0, 0x800, 0x5, 0x0, 0x60000000, 0x1303002d, 0x60000000, 0x1303002d, 0x60000000, 0x1303002d, 0x60000000, 

    0x1303002d, 0x0 <repeats 13 times>, 0x30003, 0x0, 0x0, 0x1, 0x0 <repeats 64 times>}, STIR = 0x0, RESERVED4 = {0x0 <repeats 12 times>, 

    0xc0000000, 0xfffffff8, 0x0}, MVFR0 = 0x10110021, MVFR1 = 0x11000011, MVFR2 = 0x40, RESERVED5 = {0x0}, ICIALLU = 0x0, RESERVED6 = {0x0}, 

  ICIMVAU = 0x0, DCIMVAC = 0x0, DCISW = 0x0, DCCMVAU = 0x0, DCCMVAC = 0x0, DCCSW = 0x0, DCCIMVAC = 0x0, DCCISW = 0x0, RESERVED7 = {0x0, 0x0, 

    0x0, 0x0, 0x0, 0x0}, ITCMCR = 0x73, DTCMCR = 0x3b, AHBPCR = 0x9, CACR = 0x2, AHBSCR = 0x800, RESERVED8 = {0x0}, ABFSR = 0x0}

(gdb) 

So according to usage fault register I get hardfault because of unaligned memory access. This does not make any sense, since the exact same function has been executing without problems a million times before and flash has not been changed. Also it happens on different locations in the code.

According to this -> 

http://www.keil.com/support/docs/3777.htm

this seems to be a known problem, but I already got their ''solution'' in place and I still get the problem.

Anyone got any clue about how to fix this ?
2 REPLIES 2
Amel NASRI
ST Employee
Posted on August 26, 2016 at 16:03

Hi rygelxvi,

1- Are you in the same conditions as the ones described in the mentioned link (SDRAM used...)?

2- Once appeared, is the issue still faced systematically or are you facing it randomly?

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

troy1818
Senior
Posted on August 27, 2016 at 11:09

Hi Mayla, thanks for answering !

1. Now when I read it again, perhaps not.

2. It happens at random.

I think I have found a solution to my problem, I changed the flash latency from 4 to 5. Now the problem is at least less frequent, perhaps completely gone.