AnsweredAssumed Answered

How to access *any* memory address without a bus fault?

Question asked by Gordon Williams on May 8, 2014
Latest reply on May 8, 2014 by Gordon Williams
How could I write some code that would access a memory address and wouldn't generate a bus fault if it was incorrect? Or failing that, is there a way to safely check if an address is valid, or maybe even a way to have the BusFault handler return and have normal execution resume?

I'm writing a language interpreter for an STM32F103, and there are some cases when this would be very handy:

  • Providing a 'peek' instruction that wouldn't crash the micro if an invalid address was given (presumably some addresses would still cause pain - but it'd be a lot less likely!)
  • Checking at run-time how much usable RAM there was, and expanding the stack+heap to use it - because some chips appear to just be re-badged higher end parts (eg. some STM32F103VC chips have 64kb instead of the marketed 48kb) - this is for use by enthusiasts - obviously it wouldn't be relied on for production.
I've tried quite hard to get something working, but haven't had much luck so far - if I return from the Bus Fault handler (even after clearing the flags) the processor immediately HardFaults.