j123b567 / scpi-parser

Open Source SCPI device library
BSD 2-Clause "Simplified" License
470 stars 196 forks source link

How low (in memory capacity) can we go? #112

Closed PolyPik closed 8 months ago

PolyPik commented 4 years ago

My company is planning on working with TMS320F2838x MCUs from Texas Instruments.

It's Connectivity Manager (CM) has 96KB of RAM. I want to know has anyone here has gotten the parser to work in a real application with even lower memory constraints?

j123b567 commented 4 years ago

There are even possibilities to run this on 8-bit AVR. Primary purpose of this library are small microcontrollers.

This library has these memory requirements

There are no dynamic memory allocations. There are no extensive stack usages but I don't know exact numbers.

ecrin4102 commented 4 years ago

Without any command and a buffer of only 10, I increase the .text of only 11632 bytes and .data of 368 on an stm32l496 (cortex m4) So it's really small !

jancumps commented 4 years ago

That will fit. I use the library with the TI Hercules family. The drivers of TMS320 are somewhat similiar to the Hercules ones - I'm using the UART one for SCPI exchange. Ping if you need an example.

PolyPik commented 4 years ago

@jancumps Are any of those Hercules MCUs the ones that only have 32 KB RAM?

https://www.ti.com/microcontrollers/hercules-safety-mcus/products.html#p1219=32

jamiestepanian commented 1 year ago

I'm unable to get below roughly 90K binary size, even using -Os. I'm targeting a system with 32K of ram, and slow flash. I configured the library for SYSTEM_BARE_METAL. Do you have any suggestions?

j123b567 commented 1 year ago

And that's just the library. All command patterns and their callbacks consume more flash. This library is written in such a way that it should follow the standards as much as possible. You can sacrifice this functionality by removing some commands.

Writing a simple command handler from scratch is also possible if you don't need these command patterns and these standard SCPI commands. It's just a tradeoff between completeness and size. Then you can say that you support the SCPI-Like interface. The more you remove from the standard functionality, the more your users will get angry. But unfortunately this is common practice for all companies, including those you wouldn't expect (including some industry-leading companies in test and measurement).

martinmoene commented 1 year ago

...users may express their gratefulness via disappointment through anger :)

Yorkshire-Jack commented 1 year ago

It should be possible to get well below 90KB. We have a binary for a AVR8 (32K flash 2.5K ram) which is 20KB, and that includes dozens of quite long commands. The binary also includes a decent amount of application specific code, a USB library, and a DFU bootloader - I'd be surprised if the SCPI parser component is more than 12KB. Unless I'm missing something?

jamiestepanian commented 1 year ago

Thanks @j123b567 for the great library! Good to have some perspective on what is achievable from the comments in this thread. I was able to decrease my code size by using the --gc-sections option in my LD flags to garbage collect unreferenced sections, and -ffunction-sections -fdata-sections in my CC flags. It seems like this is the norm in embedded applications.

I will put together a build with all of my commands and callbacks to see what code size I can achieve. Worst case I can live with the performance hit of linking libscpi exclusively in flash (8x higher read latency in my case).