2024-03-20 08:05 PM
Hi All,
I want to port VL53L4CX bare driver to my M0+ MCU (36KB SRAM) however it cannot fit into RAM (.bss)
What's RAM requirement of VL53L4CX bare driver ?
(I used VL53L1CX ULD and VL53L4CD ULD driver that's ok)
or how to trim down the memory requirement ?
BR,
Sam
2024-03-21 07:32 AM
When you jump from the ULD drivers of the VL53L1X and VL53L4CD up to the big drivers of the VL53L1CB or the VL53L4CX, you really do step up the complexity.
Those big drivers use histograms. And the histogram data is uploaded to where it is your host that extracts the range from the raw data.
Your VL53L4CX runs the same code as the VL53L1 Full - with very slight modifications.
It looks to me like RAM isn't going to be the issue, but the ROM is the trick.
That larger code was written by a bunch of Linux programmers, and they don't think about code size - ever.
There isn't an easy way to make it smaller - without reducing functionality. Although one could remove those useless abstraction layers. But that doesn't save a significant amount.
But search GitHub, I'm betting someone is proud of what they have done.
I'd investigate the cost of selecting the next larger processor size. (But then I'm a software guy, and hardware solutions are easy - for me.)
2024-03-26 08:43 PM
Hi John,
I found the root cause of the RAM issue is
VL53LX_Dev_t
A single instance takes around 9k which it too big for MCU SRAM.
It there any way to trim it down or fine tune to fit limited SRAM ?
2024-03-27 08:43 AM
That's a trick invented by Unix. Because the Dev is on the stack and we know stack sizes are basically infinite, one can shove every possible thing into the Dev. (It's why I demanded the Dev in the VL53L4CD Ultra Lite Driver be an integer.)
That Dev structure looks pretty harmless until you start digging. You get to:
typedef struct {
VL53LX_LLDriverData_t LLData;
/*!< Low Level Driver data structure */
VL53LX_LLDriverResults_t llresults;
/*!< Low Level Driver data structure */
VL53LX_DeviceParameters_t CurrentParameters;
/*!< Current Device Parameter */
} VL53LX_DevData_t;
and those structures are pretty large.
I measured 10872 bytes.
Worse is that our footprint size calculations do not include structures put on the stack. (That is a mistake.)
The easy solution (software wise) is to switch to the VL53l1CX. The UltraLite Driver runs on that part.
But the lens on the L1CX makes it more expensive, and if you had more money, you could use a chip with more ram of course.
I don't a have a good solution.
The folks who wrote that code were thinking Cellphones and PCs - not tiny MCUs.
- john