2014-05-08 02:57 AM
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: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.
thanks!2014-05-08 03:09 AM
2014-05-08 03:27 AM
That doesn't answer my question I'm afraid.
For instance I have an STM32F103VCT6 here - that should have 48kB of RAM, so accessing 0x2000FFFC should give a bus fault - but it doesn't. In fact the whole 16kB of memory between 48k and 64k is usable.However if I access 1 word further on - 0x20010000 - I get a bus fault.2014-05-08 03:41 AM
OK - your question is - how do I deal with a BusFault.
My answer is : do not let it get to a bus fault. Sure it can be done - but it will be a lot of effort. What will it gain? What are you really trying to do? ''I'm writing a language interpreter for an STM32F103'' Does it really have to allow probing of all memory - or can you check to see if the memory address is in an allowable range before executing the instruction?2014-05-08 04:01 AM
The main use for this is to probe the chip to see just how much memory is really available on-chip - regardless of the part number written into the chip's ROM.
If there was some way of finding out exactly how much RAM there was without this, it would be preferable - but it seems that there isn't.So I need to be able to find out whether accessing memory is going to give a BusFault (or I need to be able to disable BusFaults, or handle them).Are there any examples of BusFault handlers that just ignore the BusFault and carry on as normal? I did spend quite some time looking (and trying) but I haven't been able to find one.2014-05-08 04:28 AM
''The main use for this is to probe the chip to see just how much memory is really available on-chip - regardless of the part number written into the chip's ROM.''
As I said before - in the embedded world (and STM32 parts are used mainly in the embedded world) the part being used is known! However, the information you seek (about faults) is in the ARM programmers manuals : http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0440b/Chdbeibh.html (look at the bottom of page - downloadable PDF version) The STM32 customized version : document/programming_manual/CD00228163.pdf I think part of the problem is the definition for the Bus handler ISR. Most compilers if not defined will automatically save registers on entry. For what you want - this must be disabled (preserving the stack for the RTI) - for GNU gcc 'naked' is used - do not know what compiler you are using. I think there was someone else trying to recover from BusFaults to try and determine RAM size in this forum.2014-05-08 04:51 AM
Thanks for the info - I'd done a quick search before posting, but all I found was this:
https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/How%20to%20Enable%20BusFault,%20MemManage%20InterruptsI had looked at the programming manual before too, but had no luck producing a BusFault handler that didn't Hardfault right after returning. Thanks for the info about the 'naked' keyword - does accessing the stack in the BusFault handler cause problems then?
2014-05-08 05:15 AM
Are you sure to understand the consequence of this *discovery* process ? There are a lot of questions to answer:
* How do you define 'ignore the busfault and carry on as normal' ? * Let's take this example, you are reading random memory locations; Where there is memory, you got the content of the cell, but what do you expect anywhere else ? A value ? An error ? * You want to find the boundary of the memory, what tells you that you reached the end ? * The busfault handler shall not carry on as normal, you must implement in the handler a way to signal the reading error, don't you ? Perhaps the most simple is to read bytes: normal values are comprised between 0-255, an error would return -1. So the busfault handler must not only ignore the faulty load byte, but also fill the destination register with -1 (you need to decode the faulty instruction). All of this is *possible*, but is eventually not trivial to do.2014-05-08 06:21 AM
Hi,
I'd be entirely happy with an undefined result - perhaps with the 'ldr' operation actually being a no-op.Assuming I can effectively 'disable' busfaults (either with a handler, or by actually disabling them), I'd just do:2014-05-08 06:24 AM
Just to add - because of this, the 'ldr'/'str' instruction being a no-op, or with undefined result, is absolutely fine.