Loop in code/tight leads to hard fault
Closed this issue · 3 comments
mterber commented
Hi,
I compiled the following Céu code for an STM32F103 ARM Cortex-M3 microcontroller using the Céu compiler "ceu 0.30 (8540111)":
native/pre do
##include "diag/Trace.h"
end
native/nohold _trace_puts;
native/nohold _trace_printf;
code/tight Test (var u32 a) -> none do
loop do
if a < 1 then break; end
a = a - 1;
_trace_puts("bar");
end
end
loop do
_trace_puts("foo");
await 1s;
call Test(3);
end
When I run the code on the microcontroller, I get the following output:
foo
bar
[HardFault]
Stack frame:
R0 = 00000001
R1 = 08004EC0
R2 = 00000000
R3 = 00000002
R12 = 20004E50
LR = 08001433
PC = 080034B8
PSR = 21000000
FSR/FAR:
CFSR = 00000400
HFSR = 40000000
DFSR = 0000000A
AFSR = 00000000
Misc
LR/EXC_RETURN= FFFFFFF9
So as soon as the second iteration of the loop in the code/tight is executed a hard fault error makes the controller to halt. This behavior is reproducible and happens on every run. If I remove the loop and just output "bar" the error is gone.
fsantanna commented
Thank you for the report.
I can confirm it is a bug.
This code also reproduces the bug:
code/tight Test (var int a) -> none do
loop do
if a < 1 then break; end
a = a - 1;
end
end
call Test(3);
escape 1;
(Surprising that there's no similar test case.)
fsantanna commented
Fixed on master
.
It is a little bit ahead of v0.30
but it should not be a problem.