Another newbie question-
How do I store a bunch of data in ROM/Flash memory.
I thought I could use the
RSEG DATA16_N, but can only declare space for uninitialized data.
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi Hithesh,
well, first off all I need to say that I'm writing my applications in C and not in assembly languange. Second, I'm now using CCS and abandoned IAR, but I - maybe - can give you a hint were to find some informations on that issue.
If you want too, have a look at http://focus.ti.com/lit/ug/slau157k/slau157k.pdf - the Code Composer Studio Users Guide for MSP430.
Rgds
aBUGSworstnightmare
Hithesh said:How do I store a bunch of data in ROM/Flash memory.
Hithesh - i recommend that you take a look at the code examples for your specific device. you'll find a few examples on writing to flash.
Guys, where can I find the listing file.
For initializing memory, I tried
RSEG DATA16_I
DB 0x012,0x011,0x10,0x0A,0X0B
IAR doesn't seem to complain. But I have no idea how to verify if the data has been stored and at what location the data is stored..
If you want to store constant data (such as precalculated tables) in FLASH, just put them into the same segment the code is written into.
If you need to preinitialize variables stored in RAM, then, well, I don't know whether the assembler has some prebuilt mechanism for that. Under C, the init data is autmatically put together and the automatically added reset function will copy this content from flash to ram before entering main().
If you want to access the data later, you should give it a label :)
YOu can even maually write a function that copyies data from flash to ram later. All you nee dit to know the source address (the label), the destination address (the address of the destination variable or struct or whatever in RAM) and the size.
If you want something else, you should be a bit more detailed of what do you want and why.
Jens-Michael Gross said:If you want to store constant data (such as precalculated tables) in FLASH, just put them into the same segment the code is written into.
This is exactly what I am asking for. I want to use this feature to store look up tables etc.
But how do I do this?
Do I just say
My_table EQU 0x01,0x02,0x03........
If you need to preinitialize variables stored in RAM, then, well, I don't know whether the assembler has some prebuilt mechanism for that. Under C, the init data is autmatically put together and the automatically added reset function will copy this content from flash to ram before entering main().
If you want to access the data later, you should give it a label :)
This would be nice too. I am pretty sure, I will end up wanting this some time in the future.
I just found out, I can use
RSEG DATA16_I to initialize RAM and
RSEG DATA16_c to initialize ROM.
I went ahead and tried something like below
RSEG DATA16_C
MYCONST DB 0AH,0BH,0CH,0DH...
I put Myconst in the watch window. Myconst =0B0Ah, the address where it
was stored was 8000h(these bytes were stored in ROM just before the program hex codes).
I would like to store this address in a register like R12. I cannot
figure out how to do it.
I tried @Myconst, but that would go to memory location 0B0Ah.
If you put data in DATA16_C, thisdata is put into a separate segment and linked later. you can then access it jus tlike any other data with absolute addressing mode (with &).
But you can just put this data in between your assembly code in the same segment the code goes:
myfunc:
mov.b mydata,R4 ; move first byte of mydata into R4
mov #mydata,R5; move address of mydata into R5
mov.b #2(R5),R6; move second byte of mydata into R6
ret
mydata: DB 01h, 02h, 03h ...
This way, the data will be put right behind the code, and you can access it by using symbiolic mode (without the &). It is then addressed relatively to the PC and data as well as code can be moved together freely at runtime. This can be handy if you're writing code that will be moved to RAM or modular code that will be loaded from an external storage device. It is of course still available with symbolic references as long as you leave it at its linked position.
I don't know the exact meaning of those segments. I use MSPGCC and there the segment names are different. (andmost people never need their names as mspgcc is mostly used for c programming, even if it produces intermediate assembly oputput and you can write diretly in assembler too if you want)
What you describe seems to indicate tha tthe data is stored in FLASH, but at startup (maybe in the reset function) will be copied to RAM. So all references to MYCONST point into RAM and only the linker knows that copying the _C segment from flash to ram will put your init code to the correct destination.
Maybe _I and _C are identical except for the fact that _C is considered constant, so the labels defined there cannot be used as destination, only as source, and the assembler will complain.
**Attention** This is a public forum