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

Post Reply
User avatar
janosch
Posts: 306
Joined: Tue Jun 30, 2020 9:23 am
Location: London, UK
Has thanked: 67 times
Been thanked: 54 times
Contact:

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

Post 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!
User avatar
janosch
Posts: 306
Joined: Tue Jun 30, 2020 9:23 am
Location: London, UK
Has thanked: 67 times
Been thanked: 54 times
Contact:

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

Post 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.
User avatar
mpgMike
Posts: 8
Joined: Tue Nov 09, 2021 5:56 pm

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

Post 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.
I'm betting on the future!
User avatar
johu
Site Admin
Posts: 5682
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 153 times
Been thanked: 960 times
Contact:

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

Post 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)?
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
User avatar
janosch
Posts: 306
Joined: Tue Jun 30, 2020 9:23 am
Location: London, UK
Has thanked: 67 times
Been thanked: 54 times
Contact:

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

Post 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.
Post Reply