 |
 |
View previous topic :: View next topic |
Author |
Message |
mgiuliani
Joined: 30 Mar 2023 Posts: 21
|
Saving a constant str in program memory instead of RAM? |
Posted: Mon Jun 02, 2025 6:22 am |
|
|
I have a file for configuring a peripheral device on my board that is 7KB. I am using a PIC24FJ1024GA606. It has 32KB of RAM total so saving this in RAM isn't exactly ideal. The file is useless after configuring the peripheral device. Saving it in program memory isn't great either but for manufacturing reasons it'd be best for me.
The file is essentially a giant string of ASCII characters. Saving it as a const char array (e.g. const char my_data[] = "....";) still puts it in RAM, as does using the #import directive.
Is there a way to save a large constant string in program memory instead of RAM using the CCS compiler? |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19851
|
|
Posted: Mon Jun 02, 2025 9:19 am |
|
|
Yes. But you have to fiddle a bit.
How is the file available?. Is it a separate file or have you got it in C code
form?.
If a separate file, then you can use a method like this:
Code: |
#IMPORT(FILE=.\data.bin, RAW, LOCATION=where_stored, BPI=3)
|
This imports the file 'data.bin', binary data file from the current directory
into the ROM,
handling the 3 bytes per word storage (remember the main program
memory only has 24 bits out of every 32 physically there). This is the
BPI=3 parts (bytes per instruction).
The variable 'where_stored', is set as the location where this 'is'. You can see
this value as a BYTE * to access the data, provided you have pass_strings
=IN_RAM selected.
I use this for a font, and a large logo.
You can load data directly into ROM as a simple array, if you have it in
this format, just declaring this as CONST. In CCS const 'variables' by default
are stored in ROM not RAM. |
|
 |
jeremiah
Joined: 20 Jul 2010 Posts: 1391
|
Re: Saving a constant str in program memory instead of RAM? |
Posted: Tue Jun 03, 2025 8:36 am |
|
|
mgiuliani wrote: | I have a file for configuring a peripheral device on my board that is 7KB. I am using a PIC24FJ1024GA606. It has 32KB of RAM total so saving this in RAM isn't exactly ideal. The file is useless after configuring the peripheral device. Saving it in program memory isn't great either but for manufacturing reasons it'd be best for me.
The file is essentially a giant string of ASCII characters. Saving it as a const char array (e.g. const char my_data[] = "....";) still puts it in RAM, as does using the #import directive.
Is there a way to save a large constant string in program memory instead of RAM using the CCS compiler? |
I did a test program in v5.113 and it puts the array in ROM for me instead of RAM. My guess is you turned on ANSI mode, making "const" work as ram instead of rom. Here is my test program:
Code: |
#case
#include <24FJ1024GA606.h>
const char my_data[7168] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
void main(){
char test;
for(int i = 0; i < 7168; i++){
test = my_data[i];
}
while(TRUE);
}
|
You can see from the SYM file it is in ROM instead of RAM:
Code: |
W0 @SCRATCH
W0L _RETURN_
W0 -W1 @DIV3232B.P1
W0 -W1 @READ_ROM_MEMORY.P2
W1 @SCRATCH
W1 @READ_PACKED_MEMORY.P1
W1 @WRITE_PACKED_MEMORY.P2
W2 @READ_ROM_MEMORY.P1
W2 @READ_PACKED_MEMORY.P2
W2 @WRITE_PACKED_MEMORY.P3
W2 -W3 @DIV3232B.P4
W3 @READ_PACKED_MEMORY.P1
W3 @WRITE_PACKED_MEMORY.P2
W3 @READ_ROM_MEMORY.P3
1D8.3 TSAEVT
1D8.4 TSBEVT
232.6 OC1_TRIGSTAT
23C.6 OC2_TRIGSTAT
246.6 OC3_TRIGSTAT
250.6 OC4_TRIGSTAT
25A.6 OC5_TRIGSTAT
264.6 OC6_TRIGSTAT
271.4 CCP_1_SSDG
278.4 CCP_1_ASEVT
278.5 CCP_1_TRCLR
278.6 CCP_1_TRSET
295.4 CCP_2_SSDG
29C.4 CCP_2_ASEVT
29C.5 CCP_2_TRCLR
29C.6 CCP_2_TRSET
2B9.4 CCP_3_SSDG
2C0.4 CCP_3_ASEVT
2C0.5 CCP_3_TRCLR
2C0.6 CCP_3_TRSET
2EB.0 C1OUT
2EB.1 C1ENV
2ED.0 C2OUT
2ED.1 C2ENV
2EF.0 C3OUT
2EF.1 C3ENV
305.4 CCP_4_SSDG
30C.4 CCP_4_ASEVT
30C.5 CCP_4_TRCLR
30C.6 CCP_4_TRSET
329.4 CCP_5_SSDG
330.4 CCP_5_ASEVT
330.5 CCP_5_TRCLR
330.6 CCP_5_TRSET
34D.4 CCP_6_SSDG
354.4 CCP_6_ASEVT
354.5 CCP_6_TRCLR
354.6 CCP_6_TRSET
371.4 CCP_7_SSDG
378.4 CCP_7_ASEVT
378.5 CCP_7_TRCLR
378.6 CCP_7_TRSET
464.6 LC1OUT
470.6 LC2OUT
47C.6 LC3OUT
488.6 LC4OUT
802 main.test
804-805 main.i
7F80-7FFF _STACK_
ROM Allocation:
000200 my_data.call
00021C my_data.data
0014C8 main
0014C8 @cinit1
0014E6 @cinit2
|
|
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19851
|
|
Posted: Tue Jun 03, 2025 11:03 am |
|
|
I think you have put your finger on it Jeremiah. He is probably selecting
#DEVICE ANSI, which then makes a const behave as a non writable RAM
variable
It doesn't actually work since the PIC does not have the hardware to protect
a RAM area, but it 'tries'.
He can bring back the CCS behaviour for const, by simply having:
Code: |
#DEVICE ANSI
#DEVICE CONST=ROM
|
|
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|