This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

HardFault when relocating vector table and code above 0x80010000

Hi there!

I have a strange problem after relocating a portion of software
to another part of the flash memory.

First of all a little description of my configuration.
I have got two separate programs installed in the same controller
(STM32F427ZGT6, i am using using Keil v5.20, Pro version).

First part is a kind of a bootloader which is positioned at 0x80000000,
and the second part starts at 0x80010000. Of course bootloader
after proper start relocates vector table to 0x80010000 and moves
the PC to 0x80010000. And that's really fine. Everything works perfect
in such a configuration.

But the problem appears when the address is not 0x80010000, but 0x80020000 and above.
When i relocate the main portion of software to 0x80020000 program hangs
and stops on HardFault.

As far as i see the program stops on rt_memcpy_w function. But sometimes
the "caller" of HardFault points to 0x0 adress, not to rt_memcpy_w.
I've tried other adresses - 0x80030000 and so on. But the situation is the same.

I have to move the second portion of the software because of additional functions
in the bootloader part, so now it's code is more than 0x10000 bytes.

I've checked the reference manual about the memory map, but i haven't
found any clue for such a behavior.

Thanks in advance for any help!

Parents
  • Hello!

    In fact i use such code to move the address of the vector atable and code:

    //####################################################################################
    __asm void boot_jump( unsigned int address )
    {
            LDR SP, [R0]            ;Load new stack pointer address
            LDR PC, [R0, #4]        ;Load new program counter address
    }
    

    And everything works perfect when i'm using address such as 0x80010000 or 0x8000f000.
    But when i use 0x80020000 and above it is not working. I mean the processor starts and
    runs the bootloader and when it jumps to the 0x80020000 part it hangs at random points
    somewhere near the begin of the second part of the code.

    Best regards!

Reply
  • Hello!

    In fact i use such code to move the address of the vector atable and code:

    //####################################################################################
    __asm void boot_jump( unsigned int address )
    {
            LDR SP, [R0]            ;Load new stack pointer address
            LDR PC, [R0, #4]        ;Load new program counter address
    }
    

    And everything works perfect when i'm using address such as 0x80010000 or 0x8000f000.
    But when i use 0x80020000 and above it is not working. I mean the processor starts and
    runs the bootloader and when it jumps to the 0x80020000 part it hangs at random points
    somewhere near the begin of the second part of the code.

    Best regards!

Children
  • Hello!

    One more thing. I'am using such an instruction to move the vector table:

    #define _APPLIC_ADDR 0x0020000
    SCB->VTOR = (_APPLIC_ADDR & 0x1FFFFF80);
    


    and then function boot_jump() to move the PC and SP.

    Best regards!

  • That's not where the vector table is, set SCB->VTOR = 0x08020000;

    And make sure you don't have other code in SystemInit() or wherever changing it to other addresses.

    The shadowing/aliasing of 0x08000000 at 0x00000000 might not span the entire FLASH

  • Hi there!

    I've checked it and definetely the address of the vector table is
    0x8020000. I've added 0x8000000 mask to this address, but it doesn't
    change anything.
    I've prepared another bootloader which put the main code
    at this address. And this one is working. I mean now i can
    move entire code at address 0x8020000 and averything works perfect.
    It seems, that i have a problem somewhere else. The main differences
    between those two bootloaders is that i am using USB stack from KEIL
    in the first one bootloader (this one, which is not working properly).
    I am sure, that the code of the bootloader with USB stack is not bigger than
    this 0x20000. But is there a possibility, that the stack or heap or something
    else is messed up during the change of the vtor address? But, as far as i know,
    the stack and heap are in the SRAM, so how this could be connected to code in FLASH?
    I do not have any idea, why it is not working at that moment.
    I've tried to localize this problem via debbuging, but i cannot
    see the answer here.

    Best regards!

  • Hi there!

    Ok, i've found the problem.
    The problem was with the HAL and it's "stack".
    I've used HAL library for USB stack.
    So in my code there is HAL_Init() instruction.
    But, when i've changed vtor and PC and SP
    i haven't stopped HAL (by using HAL_DeInit()).
    And that was the problem.
    I assume, that for example SysTick has been
    working still, but i've changed the vector table
    and everything collapsed.
    So, thanks for the discussion. It has helped me
    to track the bug.

    Best regards!