Understanding Fatal Error with respect to STM32
Understanding Fatal Error with respect to STM32
Hello Everyone!!
I have got running micropython in my custom hw based on stm32.(As of now using pyb module completely)
I have implemented uasyncio to run some coros so as to get data from different sensors at different time frames, amongst sending data to server.
What happens is that the controller runs for few hours and after some time it encounters FATAL ERROR with most of the time the issue being memory allocation. What am I missing ?
Thanks in advance!!
I have got running micropython in my custom hw based on stm32.(As of now using pyb module completely)
I have implemented uasyncio to run some coros so as to get data from different sensors at different time frames, amongst sending data to server.
What happens is that the controller runs for few hours and after some time it encounters FATAL ERROR with most of the time the issue being memory allocation. What am I missing ?
Thanks in advance!!
lnsri22
-
- Posts: 11
- Joined: Mon May 28, 2018 11:48 pm
Re: Understanding Fatal Error with respect to STM32
Any particular fatal errors like MemManage or HardFault?
Have you tried to set a breakpoint @ __fatal_error() function in ports/stm32/main.c (or in your HW STM32 port)?
Have you tried to set a breakpoint @ __fatal_error() function in ports/stm32/main.c (or in your HW STM32 port)?
Re: Understanding Fatal Error with respect to STM32
Hi Maksym,
Thanks for reply there!!
I'm not sure about the particularity of the error.
But all I could see is that the LED (on-board) toggle in a specific pattern(I have made the custom hardware have only one LED for indicating CPU heart-beat( which is actually RED Led in pyboard I mean the hardware mapping)
Ever since this error is encountered by the hardware, my perception is that the pattern might be similar to that of this
https://github.com/micropython/micropyt ... main.c#L88
I will put a breakpoint as you said and observe the behaviour. Anyhow I'm not sure about when this would happen. It happens in a random manner. (At times in a couple of days, and sometimes may be in 6 or 7 hours)
Thanks!!
Thanks for reply there!!
I'm not sure about the particularity of the error.
But all I could see is that the LED (on-board) toggle in a specific pattern(I have made the custom hardware have only one LED for indicating CPU heart-beat( which is actually RED Led in pyboard I mean the hardware mapping)
Ever since this error is encountered by the hardware, my perception is that the pattern might be similar to that of this
https://github.com/micropython/micropyt ... main.c#L88
I will put a breakpoint as you said and observe the behaviour. Anyhow I'm not sure about when this would happen. It happens in a random manner. (At times in a couple of days, and sometimes may be in 6 or 7 hours)
Thanks!!
lnsri22
-
- Posts: 11
- Joined: Mon May 28, 2018 11:48 pm
Re: Understanding Fatal Error with respect to STM32
I would start with capturing your debug UART port output defined @ mp_hal_stdout_tx_strn() and looking for "\nFATAL ERROR:\n" strings in order to find out the actual error (as a parameter to __fatal_error() function).
Re: Understanding Fatal Error with respect to STM32
Thanks again!!
Let me give a quick try to capture this.
I will update the result once this error occur!!
Let me give a quick try to capture this.
I will update the result once this error occur!!
lnsri22
Re: Understanding Fatal Error with respect to STM32
Hi Maksym!!
Thought of giving it a try and finally got the output
It is
This happens at random time intervals after restart.
What am I missing?
Thanks in advance!!
Thought of giving it a try and finally got the output
It is
Code: Select all
MemoryError: memory allocation failed, allocating 31655 bytes
MicroPython 8dc4982-dirty on 2019-02-09; MySTM with STM32F405VG
Type "help()" for more information.
What am I missing?
Thanks in advance!!
lnsri22
Re: Understanding Fatal Error with respect to STM32
I'd guess that you have an ISR which is trying to allocate a buffer.
Any code which uses ISRs should allocate an emergency exception buffer as described here:
http://docs.micropython.org/en/latest/r ... ion-buffer
then you should get some more detail (i.e. file and line number) about the exception
Any code which uses ISRs should allocate an emergency exception buffer as described here:
http://docs.micropython.org/en/latest/r ... ion-buffer
then you should get some more detail (i.e. file and line number) about the exception
Re: Understanding Fatal Error with respect to STM32
Thanks Dave for the quick reply!!
Let me look into it. But Dave, How do i get the info on file and line number ??
Let me look into it. But Dave, How do i get the info on file and line number ??
lnsri22
Re: Understanding Fatal Error with respect to STM32
I'm assuming that you've got some code running from main.py and this code is what's causing the failure. Are there any other messages before this? Allocating 31655 is a rather large buffer and needs to done properlly to ensure success. For a buffer that large, you want to allocate it as early as possible in your program and you don't want to free it. You want to reuse it. The chances of allocating another buffer that large a second time after your program is running for a while is extremely slim due to heap fragmentation.
I think your error might be something slightly different than what I was proposing in my previous message. This is the example I tried: If I run that then I get this error: If I then uncomment the 2nd and 3rd lines and re-run, I get this error instead: which has the line number and filename information. Your error would seem to indicate actually running out of memory.
I think your error might be something slightly different than what I was proposing in my previous message. This is the example I tried:
Code: Select all
import pyb
#import micropython
#micropython.alloc_emergency_exception_buf(100)
def heartbeat_cb(tim):
global tick
if tick <= 3:
led.toggle()
x = []
tick = (tick + 1) % 10
tick = 0
led = pyb.LED(4) # 4 = Blue
tim = pyb.Timer(4)
tim.init(freq=10)
tim.callback(heartbeat_cb)
Code: Select all
>>> import memfail
>>> uncaught exception in Timer(4) interrupt handler
MemoryError:
Code: Select all
>>> import memfail
>>> uncaught exception in Timer(4) interrupt handler
Traceback (most recent call last):
File "memfail.py", line 9, in heartbeat_cb
MemoryError: memory allocation failed, heap is locked
Re: Understanding Fatal Error with respect to STM32
Dave,
I am about to try this.
Will update you once I'm done with this
Thanks again!!
I am about to try this.
Will update you once I'm done with this
Thanks again!!
lnsri22