ARM M3 move code & # 8594; mistakes

ARM Cortex M3 (LPC1519)

I wrote a bootloader (which still works) that runs in flash memory and writes a program to Flash (behind the bootloader). The program is written and starts to work properly (at least during debugging).

When I use the SEGGER Ozone debugger, I can set the breakpoint to "main" and execute the firmware. However, when I run a large operation in the code (to another breakpoint), I always get unexpected interrupts:

  • UsageFault_Handler
  • BusFault_Handler
  • and etc.

This does not happen when I execute a code command with a command. This means that interrupts will not work properly.

The program works fine when I flash it to address 0x00000000. I changed the script builder so that the origin lies at a later offset (where the loader places the firmware).

Anyone having similar problems?

Thanks Johann

PS: sorry, I can not provide a minimum sample, because I do not know where to start

Edit - Additional Information: Now I have downloaded a small project where I can find an error in the debugger. There is a uint32_t variable in the structure, which seems to cause an error. It says:

Mis-alligned memory read: Address: 0x00001596, NumBytes: 8, Alignment: 4 (word alignment)

In fact, 0x1596 is not decrypted to 4, so the error is justified, but how can it be? Should the compiler not care about aligning variables in structures?

- : , IRQ USART0 (txReady). , ? ARM Cortex SysTick (SysTick_Handler) !?

[[noreturn]]
inline void startFirmware(std::uint32_t address) noexcept
{
    //<removed checks for correct address>

    //pointer to the address
    const auto ptr = reinterpret_cast<std::uint32_t*>(address);

    // Set vector table offset
    SCB->VTOR = address & SCB_VTOR_TBLOFF_Msk;

    // Set top stack handler
    __set_MSP(*ptr);

    // Get address of reset handler
    const auto resetHandler = *(ptr + 1);

    // Jump to reset handler
    reinterpret_cast<internal::ResetHandlerFunction>(resetHandler)();
    while(true);
}

- : , , USART, CCTimer .., , .

+4
1

, .

ARM Doku :

TBLOFF . 32 , 16 . . , 21 , 64 37 , 64. . .

, 16 , SCB- > VTOR , 32- ( 0x80), 64- ( 0x00), 0x1100 0x1080 ( 128 , ).

+2

Source: https://habr.com/ru/post/1677332/


All Articles