You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This should be less than min(remaining RAM, max storage). If we want to never decrease this, we should leave some wiggle room, as proposed here.
Previously, user program size was implicitly limited to 25% of RAM (half for heap, then half again to be able to copy large MPY files). So, on all hubs this is either kept the same or improved (and by some margin).
We can probably set this to 3K or more, so at least 2K for MicroPython. Since RAM wasn't the constraining factor on this hub, it doesn't reduce the allowed program size anyway.
('movehub', '3.2.0b3', 'v3.2.0b3-10-g6acc817d-dirty on 2022-08-01')
top 436
1 668
2 900
3 1132
4 1364
5 1596
6 1828
7 2060
8 2292
9 2524
10 2756
11 2988
Traceback (most recent call last):
File "main.py", in <module>
File "main.py", in f
File "main.py", in f
File "main.py", in f
File "main.py", in f
File "main.py", in f
File "main.py", in f
File "main.py", in f
File "main.py", in f
File "main.py", in f
File "main.py", in f
File "main.py", in f
File "main.py", in f
RuntimeError: maximum recursion depth exceeded
This shows us that MicroPython requires 436 bytes of stack to just run and 232 bytes each for a simple function call.
So with a 1K safety factor, a 2K stack would get us two levels deep, a 3K stack gets us 6 levels deep and a 4K stack gets us 11 levels deep.
We could also consider backing down the 1K safety factor but we would need to be quite certain that library (pbio+3rd party) calls could never exceed that amount.
As an experiment, we could record the minimum sp register value in the systick interrupt, then let the hub run for a while running motors, using Bluetooth, etc to get an idea of how much stack is actually used. Of course this relies on random chance that the interrupt occurs during max stack usage, so it wouldn't be a 100% guarantee that we would get an exact value, but it could get us in the ballpark.
To help TechnicHub users to save the exception in their program after a connect to an xBox controller,
I try to write the exception to user storage so it can be shown later.
Maybe a bit too advanced and not really handleable, but I want to try.
Is there a variable already available in beta version(s) to indicate: "for this hub in this firmware level" the userdata starts "here"?
Activity
laurensvalk commentedon Aug 29, 2022
Stack is also a design choice, also up for grabs. Thoughts welcome.
Originally posted by @dlech in pybricks/pybricks-micropython#106 (comment)
With 1K for exception handling, this leaves just 1K for the MicroPython stack, which isn't much. This program trips it already (needs 1116):
We can probably set this to 3K or more, so at least 2K for MicroPython. Since RAM wasn't the constraining factor on this hub, it doesn't reduce the allowed program size anyway.
bricks/move_hub: Increase stack size.
bricks/stm32: Set user flash to practical length.
laurensvalk commentedon Aug 29, 2022
This is a bit more work than just changing the values, because the bootloader will be checking a portion of the data.
dlech commentedon Aug 29, 2022
outputs (on older firmware):
This shows us that MicroPython requires 436 bytes of stack to just run and 232 bytes each for a simple function call.
So with a 1K safety factor, a 2K stack would get us two levels deep, a 3K stack gets us 6 levels deep and a 4K stack gets us 11 levels deep.
dlech commentedon Aug 29, 2022
We could also consider backing down the 1K safety factor but we would need to be quite certain that library (pbio+3rd party) calls could never exceed that amount.
As an experiment, we could record the minimum
spregister value in the systick interrupt, then let the hub run for a while running motors, using Bluetooth, etc to get an idea of how much stack is actually used. Of course this relies on random chance that the interrupt occurs during max stack usage, so it wouldn't be a 100% guarantee that we would get an exact value, but it could get us in the ballpark.bricks/move_hub: Increase stack size.
bricks/stm32: Set user flash to useful length.
bricks/stm32: Set user flash to useful length.
bricks/stm32: Set user flash to useful length.
laurensvalk commentedon Aug 30, 2022
This is all done. Let's reopen if we want to change these values.
laurensvalk commentedon Oct 11, 2022
The values were changed in pybricks/pybricks-micropython@2e97a74.
BertLindeman commentedon Nov 7, 2024
To help TechnicHub users to save the exception in their program after a connect to an xBox controller,
I try to write the exception to user storage so it can be shown later.
Maybe a bit too advanced and not really handleable, but I want to try.
Is there a variable already available in beta version(s) to indicate: "for this hub in this firmware level" the userdata starts "here"?
Would that be including gyro settings etc?
laurensvalk commentedon Nov 7, 2024
The user data offset always starts at 0, so there is no issue writing there. You cannot write outside of the user area.