Reputation: 53
I'm working on an SoC with 128K RAM, and currently the UART printing is too much so we have to reduce the code size by drawing it from memory.
We've got an working 128Mb SPI serial FLASH on board, and i'd like to store strings on it. please notice there is no file system on flash or in our FW.
Instead writing everything by myself, i'd like to know is there any useful code or standard or other material we can make use of?
including: (anything below could be helpful)
I'm expecting something like this:
UART_PRINT(C315);
and there is an “C315”, item on FLASH, corresponding to "Hello world".
we read it out then print through UART while run time. and the final result is "Hello world" on the terminal.
of course, anything that will blow my mind is welcome.:)
Upvotes: 1
Views: 553
Reputation: 2486
You may be able to leverage the linker.
Place the SPI FLASH strings in a custom section in a custom region. Program the SPI FLASH with the linker-generated contents of the custom region.
Use the string pointers as the argument to UART_PRINT()
. The function should convert the pointer to an offset by subtracting the base address of the custom section from the string pointer. Then use the offset to retrieve the string from the SPI FLASH.
Upvotes: 1
Reputation: 28921
Create an array of pointers to strings, and use an index into the array similar to a resource. This array as well as the strings can be stored in the flash memory. It may be easier to use assembler for the array of pointers and strings, possibly as a separate build from your embedded code. You'll need to coordinate index names used in a .h include file with the array of pointers to strings, similar to a resource file used for windows apps. This could be done with a bunch of defines or an enum:
enum stringindexes{C000, C001, ...};
update - I'm wondering if it would be possible to use something like a windows resource editor to create pointers and strings. This make require some reverse engineering to create a utility to convert the produced resource file into a binary image with just an array of pointers and strings, but it would automatically generate the include file giving names to the pointers. If anything, the resource editor could be used as a guide for creating a custom program to generate an include file with defines or enums to index into an array of pointers to strings.
Upvotes: 1