Page 2 of 2

Re: I2C transfer of large data (10kb +) crashes chibios

Posted: Mon Aug 03, 2020 3:56 pm
by Nicolai86
Giovanni,

thank you so much for your help.

It turns out that the issue is inside my Makefile: I had

Code: Select all

USE_FPU=hard
set; once I disabled it it all started working.

I'm not 100% sure why the FPU would break an I2C transaction, but I'm glad that it works when I disable it.

Re: I2C transfer of large data (10kb +) crashes chibios

Posted: Mon Aug 03, 2020 6:27 pm
by Giovanni
FPU increases stack usage.

Giovanni

Re: I2C transfer of large data (10kb +) crashes chibios

Posted: Mon Aug 03, 2020 7:45 pm
by Nicolai86
Giovanni,

I guess I was a little premature here - it works fine with -O0 only.
Once I enable either -O1 or -O2 it fails again with the unhandled exception, even with FPU disabled.

So back to the stacksize issue. I'll keep you posted if I find anything concrete. First time debugging issues when using chibios :)

For the sake of documenting this endavour; I've enabled idle threads again, and bumped up the thread default PORT_IDLE_THREAD_STACK_SIZE to 512.

Code: Select all

HardFault_Handler exceptionvectors.c:63
<signal handler called> 0x00000000ffffffed
_idle_thread chcore_v7m.h:774
<unknown> 0x0000000001000000


Code: Select all

isFaultPrecise = {_Bool} true
isFaultAddressValid = {_Bool} true


I guess this means it's an issue with addresses when switching threads, but I don't know.
LR points to where I call i2cStart, so this happens somewhere inside chibios when I want to ensure the i2c state machine is ready.

Oh, and if you have any advice on how to triage the issue, please let me know :)

Re: I2C transfer of large data (10kb +) crashes chibios

Posted: Mon Aug 03, 2020 8:22 pm
by Giovanni
Which compiler are you using? chibios version? are you using chibios startup files?

Giovanni

Re: I2C transfer of large data (10kb +) crashes chibios

Posted: Mon Aug 03, 2020 9:21 pm
by Nicolai86

Code: Select all

❯ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Arm Embedded Toolchain 9-2020-q2-update) 9.3.1 20200408 (release)
❯ git st
## stable_20.3.x...origin/stable_20.3.x
❯ git rev-parse HEAD
5f523dc8e95d7ff6c6daf3bc41531cae7285cbdf


However it seems I fixed the issue entirely by following your suggestion:

both stm32_write_memory and stm32_write_data, one 256 and another one 258 bytes long.

I change the size to 128 and 130 bytes and all works. So it seems your comment about not allocating big arrays inside functions was on point, and indeed the source of this bug.

Thank you so much Giovanni! <3

It works now with all optimization levels without crash and with FPU enabled as well.