Page 1 of 1

stm32-template: structs with more than 12 members go to blocking_handler

Posted: Tue Oct 12, 2021 8:49 am
by janosch
Hello,

as described in the title, if I create a struct that is too big it fails in the initialisation in main.

If I break it up into smaller structs and initialise them separately with pointers inbetween them it works fine, so I don't think I am running out of chip memory. This happens around 12 members. I thought it might be a malloc call failing, but of course we don't really have malloc on bare metal.

Any ideas? Maybe a compiler flag?

Code: Select all

 21 typedef struct{
 22    char     gear            = 'P';
 23    uint8_t  gear_d          = 0;
 24    uint8_t  gear_r          = 0;
 25    uint8_t  gear_p          = 0;
 26    uint8_t  gear_n          = 0;
 27    uint8_t  start           = 0;
 28    int      pre             = 0;
 29    int      main            = 0;
 30    uint8_t  brake           = 0;
 31    int      throttle        = 0;
 32    int      ac_present      = 0;
 33    int      door_open       = 0;
 34 } inputs;

Code: Select all

238 extern "C" int main(void)
239 {
/// ... snip ...
// in main.cpp
262    input in; // this goes to void blocking_handler in libopencm3
263    v->in = ∈
Interesting!

Re: stm32-template: structs with more than 12 members go to blocking_handler

Posted: Mon Nov 15, 2021 1:07 pm
by janosch
Is there any literature for this, or common causes?

I could try creating a large array and see if I get the same problem.

Re: stm32-template: structs with more than 12 members go to blocking_handler

Posted: Mon Nov 15, 2021 2:41 pm
by mpgMike
I work with PIC processors, but it may have something to do with page size. You may be filling a page and overflowing to another, and the context of usage cannot deal with that. Look at the disassembly for addressing to see where your linker is putting it. That may show you what's happening.

Re: stm32-template: structs with more than 12 members go to blocking_handler

Posted: Tue Nov 16, 2021 9:55 am
by johu
Weird, I've allocated way more memory on the stack (like 1k buffers) and it never caused an issue. Why would it at 20k total memory. Maybe are you allocating too much memory statically?
What's the output of arm-none-eabi-size on your binary (the one without extension)?

Re: stm32-template: structs with more than 12 members go to blocking_handler

Posted: Tue Dec 07, 2021 5:01 pm
by janosch
johu wrote: Tue Nov 16, 2021 9:55 am Weird, I've allocated way more memory on the stack (like 1k buffers) and it never caused an issue. Why would it at 20k total memory. Maybe are you allocating too much memory statically?
What's the output of arm-none-eabi-size on your binary (the one without extension)?
still haven't changed the default name:

Code: Select all

arm-none-eabi-size stm32_yourname
   text	   data	    bss	    dec	    hex	filename
  29244	    912	    680	  30836	   7874	stm32_yourname
looks similar compared to yours:

Code: Select all

arm-none-eabi-size stm32_car
   text	   data	    bss	    dec	    hex	filename
  21532	   2852	    704	  25088	   6200	stm32_car
by the way just checking out most recent master from stm32_car gave me an error compiling, libopeninv might need a push to github.