cato,
@cato@chaos.social avatar

"I just need to implement a bootloader" he said, unaware of the fact that the Cortex M0 core lacks a vector table offset register, making switching between two user programs a lot harder 🫠

Toble_Miner,
@Toble_Miner@chaos.social avatar

@cato Ah yes, one of my favorite M0 vs M0+ differences

cato,
@cato@chaos.social avatar

@Toble_Miner yeah but as I discovered it was dead easy in the end lol

Toble_Miner, (edited )
@Toble_Miner@chaos.social avatar

@cato Hm, how does it work though? Is there already a small shim in the application that redirects execution from the vector table in flash to SRAM? Think that would be my preferred solution if I did not have VTOR available.
Or does the MCU in question have some type if hardware address translation/remapping capabilities that can be used to map some SRAM where the vector table would be?

cato,
@cato@chaos.social avatar

@Toble_Miner the linker script says "place vector table in sram" because that's where the MCU expects it, so the internal startup code handles copying it from flash to sram when I jump to the reset vector

Toble_Miner,
@Toble_Miner@chaos.social avatar

@cato Oh, that is pretty interesting. Is there a second copy of the vector table in flash for initial startup to fetch top of stack and reset vector? Guess the SRAM would usually not be initialized at that point.

cato,
@cato@chaos.social avatar

@Toble_Miner that's the point I haven't quite understood yet. The datasheet says the vector table is in ROM (actual ROM, not User Flash) at 0x00000000 but is remapped to the start of SRAM, except the stack pointer and reset vector, which are at the start of User Flash. So I guess at the very start it starts off in user flash and the reset vector points to the startup code that copies the vector table to SRAM. Not quite sure how the ROM plays into this

Private
cato,
@cato@chaos.social avatar

current level of insanity: reading instructions from RAM and parsing them to get to the actual function pointers being used

cato,
@cato@chaos.social avatar

I :DD
I did last week's work for nothing :DDDDD

Turns out :D if you just branch to the reset handler of the application code :D it already loads the vector table into RAM :D and sets up everything :DDD I don't need to do the whole "manually edit the vector table" thing :DDD

oh well a bit of time wasted

LeoDJ,
@LeoDJ@chaos.social avatar

@cato
Is it wasted if you learned something new / gained some new insight?

Private
manawyrm,
@manawyrm@chaos.social avatar

@cato whoopsie...

depending on how complex/timing-sensitive your code is: Maybe relocatable code is an option?

cato,
@cato@chaos.social avatar

@manawyrm I'm working on options, it's fine, it's just more hassle than I thought :D

manawyrm,
@manawyrm@chaos.social avatar

@cato When you're exporting the symbol table from your compiler along with the binaries only to live-patch your code before executing -- then things get messy x)

karotte,
@karotte@chaos.social avatar

@cato Same here 😢 Apparently the way to go on my STM32F0 is to remap the RAM to 0x0 and copy the vector tables to it or so 🤷

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • Hentai
  • doujinshi
  • announcements
  • general
  • All magazines