MBD toolbox, external mode: asking for too much RAM = system hang

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MBD toolbox, external mode: asking for too much RAM = system hang

581 Views
glenndoiron
Contributor II

We have been trying to use the external mode with the S32K144 MBD toolkit, and have found a hard crash problem.

If you go into Model Properties -> Code Generation -> Interface -> External Mode Configuration and check "Static memory allocation", then give it a static memory buffer size that (along with everything else in your model) exceeds the total RAM on the system, then the compilation correctly fails and gives you a message that there is 0 ram left.  This is good.

However, if you uncheck "Static memory allocation", and allocate enough signals to monitor and a duration which causes the buffer to exceed available memory (in the Control Panel -> Signal and Triggering window), then model hangs and gives a timeout error, instead of erroring out with an out of memory error.

Reviewing the compiled binary, the logic to report the failed memory allocation in UploadBufInit()  in fact looks to be correct to report the error, however the malloc() function linked to in the project triggers an exception instead of returning 0, causing a crash of the model; Simulink eventually times out with an error instead of reporting that the memory allocation failed.

Here in the debugger I have the program counter trapped on the malloc() function where it is about to call malloc(48048), which exceeds the remaining RAM.  I also have a breakpoint on the next instruction after the malloc() call.

glenndoiron_18-1663101062914.png

I then hit run, and the system generates an exception instead of returning from malloc().

glenndoiron_19-1663101203134.png

After many hours of trying to understand why external mode was "not working", I finally have the smoking gun.  If we reduce the trigger duration to a very small number, the allocation succeeds and external mode works as advertised.

I don't think that this one needs to be reported to Mathworks, as Simulink is almost certainly linking against the NXP-supplied linker libraries for malloc().  It technically isn't an MBD Toolbox issue either, but hopefully the MBD guys can find out which linker library is broken and get it fixed.

 

0 Kudos
1 Reply

484 Views
stefancinipeanu
NXP Employee
NXP Employee

Hello, @glenndoiron 

Could you send me the model with multiple signals logged that overflow the buffer for external mode? So I can investigate further the problem that you have found.

Thank you!

Regards,

Stefan.

0 Kudos