LTO linker option

Post here first, or if you can't find a relevant section!
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: LTO linker option

Post by ag123 »

i think there are stm32 soc that offers like 1 MB flash, it cost a similar premium for that benefit.
for that convenience it is likely worth it depends on your use case, but you could do away messing with spi or any 'extra' peripherals, simply build the whole lot data and all maybe even add images and bundle it in there 1 MB that is, whatever you can fit .
then there are interesting techniques like data compression
https://rosettacode.org/wiki/Huffman_coding
https://www.cprogramming.com/tutorial/c ... ffman.html
my guess is it'd work rather well for text.
but generally it seem some codes can pack quite a bit in a little flash
this lcd library along with its graphics test sketch + usb-serial and stm core takes about 40KB flash.
not the most optimized (-Os is specified, but maybe it can be improved, i'm using a makefile, but if you want to go the distance, perhaps it is possible to play with the compile flags say in boards.txt or platform.txt, these are all 'beyond the norm', they do not necessary make a difference for size at least) and i used an older compiler (which seemed to make fatter binaries)
https://github.com/ag88/Adafruit_ILI9341_SPI_stm32duino
within there it bundle Adafruit GFX graphics library as well as a font with it
https://learn.adafruit.com/adafruit-gfx ... y/overview
no LTO is used in the built, it runs rather well despite its rather 'fat' size.
as long as the app can fit in that flash, fat looking apps may still run.

that said, actually one of the biggest constraint is sram, not just flash, running memory hungry apps will set you against out of memory challenges
if it is just (storing) data, i've successfully used 16 GB sdcards, well that kinds of breaks every storage 'barrier' one can think of.
vlad
Posts: 12
Joined: Tue Mar 30, 2021 5:19 pm
Answers: 1

Re: LTO linker option

Post by vlad »

On comment of mrburnette, my app is not a blank sketch. In Arduino IDE it takes 162KB. It basically is a set of 15 guitar effects that I can combine in any sequence, and in any number (although only one instance of each). Besides that, the effects are configurable through serial line commands (each effect has 2 to 8 parameters), with support to up 6 expression pedals. I didn't make it public on github but that is something that I really want to do soon.
On ag123 comments, it id nice to know that there are stm32 with 1 MB flash. Unfortunately, the Daisy Seed board comes with the standard STM32H750 with 128 k. For a customized board this certainly should be the best solution. And since there is just a small bunch of text in code, I don't think that the gain is high by compressing it.
Again, thank you all for the valuable comments.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: LTO linker option

Post by ag123 »

one of those boards i stuffed in my box is stm32f405rg based boards
https://www.st.com/en/microcontrollers- ... 405rg.html
i'm not too familiar with the stm32h7 stm32f7, those are deemed 'high end' series e.g.
https://store.arduino.cc/usa/portenta-h7
but for the 'humble' (modest) stm32f405 there are quite a few sources of these boards
one of them is a 'well known' pyboard
https://store.micropython.org/product/PYBv1.1H
then adafruit has one
https://www.adafruit.com/product/4382
https://learn.adafruit.com/adafruit-stm ... er-express
more over at olimex
https://www.olimex.com/Products/ARM/ST/
then more over at amazon, ebay, aliexpress etc
edit:
oh, these days if stm32f4xx isn't enough juice, it is just a web search away
https://www.st.com/en/microcontrollers- ... 3-753.html
https://www.aliexpress.com/item/1005001700815862.html
https://www.aliexpress.com/wholesale?ca ... xt=stm32h7
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: LTO linker option

Post by fpiSTM »

Sorry about my previous post. I read too quickly.
In your case the best bet would be to use external flash.
mlundin
Posts: 94
Joined: Wed Nov 04, 2020 1:20 pm
Answers: 6
Location: Sweden

Re: LTO linker option

Post by mlundin »

Sorry I was confused, now I realise you had 128+19 KB of program.

So what to do, the Daisy Seed has 8MB of external flash, that should be useable to store a lot of presets. How that can be programmed and accessed can probably be found in Electrosmith documentation and or example code. Or you can read data from SD card into external RAM, 64MB should be available.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: LTO linker option

Post by mrburnette »

mlundin wrote: Fri Apr 02, 2021 5:57 pm ...
So what to do, the Daisy Seed has 8MB of external flash, that should be useable to store a lot of presets. ...
The external flash is QSPI, so is not memory mapped for access by the linker ... at least through no trick that I am aware of...
So, you can likely move lots of strings and config into the ext flash, but you will need a separate program to perform that operation. If you store the external records as a structure, you can retrieve them and init an in-memory structure with their values at the beginning of your tightly constrained program.

It appears that Electro-Smith mainly expected the external flash to be for data logging.
https://github.com/electro-smith/DaisyE ... /seed/QSPI
--- and ---
https://github.com/electro-smith/DaisyE ... eed/Logger

One trick I have used with SPIFFS on the Espressif chips is to put all of my strings and messages into external flash and "tokenize" to a single character messages in the main program: 8-bit char (signed char8_t) allows for unique reference strings stored into QSPI flash.
(char MtPointer = 48; is ASCII 0)
You could extend this to 127 values or even 256 if you wish by mucking around with the ASCII equivalents... just depends on how you organize and map a single character to an array index.

You can build a lookup matrix at startup by scanning the external string storage OR simply use "equal size blocks" for string storage to simplify retrieval: wasteful but very fast as the offsets are identical and correspond to the char value:
0 = (48-48) = 0 == 0-7,
1 = (49-48) = 1 == 8-15,
2 = (50-48) = 2 == 16-23 ...

Ex: If your worst case string is 13 characters, your block size is 2^4 or 16 characters which is:
pointer 0 = ex flash addresses 0 through 15
pointer 1 = ex flash addresses 16 through 23
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: LTO linker option

Post by ag123 »

stm32h7 is 'no ordinary' hardware/mcu, at least when compared to its poor cousins e.g. stm32f0, stm32f1xx and maybe even stm32f4
a google search turns this up
https://www.st.com/content/ccc/resource ... UADSPI.pdf
https://www.st.com/resource/en/applicat ... ronics.pdf
but i do not have the board nor have tried it, so these are the 'roads less traveled', maybe someone else may have tried etc.
in effect it turns qspi flash into 'memory'
The Quad-SPI memory interface also has a Memory-
mapped mode. The main application benefit introduced by
this mode is the simple integration of an external memory
extension thanks to there being no difference between the
read accesses of internal or externally-connected memories,
except for the number of wait states.
This mode is only suitable for read operations and the
external Flash memory is seen as internal one with wait
states included to compensate for the lower speed of the
external memory. The maximum size supported by this
mode is limited to 256 Mbytes.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: LTO linker option

Post by mrburnette »

The Quad-SPI memory interface also has a Memory-
mapped mode.
Well, I was wrong about that one! :shock:
I did not see an example up on github that showed that magic, but I only spent maybe 15 minutes rambling through the code. :shock:

Ray
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: LTO linker option

Post by fpiSTM »

Example using Quad-SPI NOR Flash memory MX25R6435F using the Quad SPI flash memories interface.
https://github.com/stm32duino/MX25R6435 ... edMode.ino
vlad
Posts: 12
Joined: Tue Mar 30, 2021 5:19 pm
Answers: 1

Re: LTO linker option

Post by vlad »

Thank you very much, guys. There's a lot of useful info and it seems that I'll have a lot of work to test each one.
ag123 suggested that I'd eventually could change to STM32H743 in this link:
https://www.aliexpress.com/item/1005001700815862.html
but it seems that Arduino IDE does not have support for this board (I'm not sure about that). If someone have experienced this board with Arduino, please let me know.
I'll keep you updated on my progress.
Post Reply

Return to “General discussion”