Skip to content

Commit

Permalink
F421: work around bug in old bootloader
Browse files Browse the repository at this point in the history
the released F421 bootloader does this:

   0x08000b3a:	ldr	r0, [r4, am32-firmware#24]
   0x08000b3c:	str	r0, [r4, am32-firmware#28]
   0x08000b3e:	ldr	r0, [r5, #0]
   0x08000b40:	msr	MSP, r0
   0x08000b44:	ldr	r0, [r4, am32-firmware#28]
   0x08000b46:	ldmia.w	sp!, {r4, r5, r7, lr}
   0x08000b4a:	bx	r0

that writes to the application stack area before jumping. If the
application stack is set to the end of ram then the ldmia instruction
hard faults as it writes past the end of memory

this avoids the issue by only giving the app 15k instead of 16k of
ram. This is not needed when we fix the bootloader to use the right
jump method, which is this:

    // setup sp, msp and jump
    asm volatile(
        "mov sp, %0	\n"
        "msr msp, %0	\n"
        "bx	%1	\n"
	: : "r"(stack_top), "r"(JumpAddress) :);
  • Loading branch information
tridge committed Sep 12, 2024
1 parent a6588a6 commit cb42516
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Mcu/f421/AT32F421x6_FLASH.ld
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@
/* Entry Point */
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = 0x20004000; /* end of RAM */
/*
Highest address of the user mode stack

we set this less than the 16k available due to a bug in the old
bootloader for F421. The old bootloader writes to the stack pointer
after setting up the stack based on the app header. This means if we
set the app stack right at the end of memory then the bootloader
hard faults.
*/
_estack = 0x20003c00;

/* Generate a link error if heap and stack don't fit into RAM */
_Min_Heap_Size = 0x200; /* required amount of heap */
Expand All @@ -34,7 +42,7 @@ FLASH (rx) : ORIGIN = 0x08001000, LENGTH = 27K
FLASH_VERSION (rx) : ORIGIN = 0x08007C00 - 48, LENGTH = 16
FILE_NAME (rx) : ORIGIN = 0x08007C00 - 32, LENGTH = 32
EEPROM (rx) : ORIGIN = 0x08007C00, LENGTH = 1K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 16K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 15K

}

Expand Down

0 comments on commit cb42516

Please sign in to comment.