| View previous topic :: View next topic |
| Author |
Message |
SeeCwriter
Joined: 18 Nov 2013 Posts: 167
|
| Pointers to ROM data |
Posted: Thu Jul 09, 2026 10:48 am |
|
|
In the past when I tried to access data in ROM using a pointer it would fail. I have a new application I'm writing and would like to try that again. Perhaps I was doing something wrong.
Example:
| Code: |
const uint_8 band0_data[] = {
0x00,
0x40,
0x2B,
0x5D,
0x00
}
void read_data()
{
uint_8 *ptr = band0_data;
for int i=0; i < sizeof(band0_data); i++, ptr++ )
{
SetReg(*ptr); <-- this didn't work
SetReg(band0_data[i]); <-- this works
}
|
I'm using an 18LF1455 and PCH v5.124. |
|
 |
jeremiah
Joined: 20 Jul 2010 Posts: 1424
|
|
Posted: Thu Jul 09, 2026 11:24 am |
|
|
Try changing
| Code: | | const uint_8 band0_data[] = { |
to
| Code: | | rom uint_8 band0_data[] = { |
and change
| Code: | | uint_8 *ptr = band0_data; |
to
| Code: | | rom uint_8 *ptr = band0_data; |
Unless things have changed since I last checked long ago, you cannot make a pointer to a const declared table because it doesn't build it like a normal table. In the old days you had to use the 'rom' keyword instead of 'const'
Also uint_8 is not a standard type. Did you mean uint8_t perchance? |
|
 |
SeeCwriter
Joined: 18 Nov 2013 Posts: 167
|
|
Posted: Thu Jul 09, 2026 11:56 am |
|
|
Yes, that was a typo with uint8_t.
Thanks, I will give it a try. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20108
|
|
Posted: Thu Jul 09, 2026 12:47 pm |
|
|
There is also the question of 'what chip'?.
There are different 'tricks' to allow this on different chip families.
As has already been posted, rom supports pointers in general.
On PIC24/30/44, you could add #device PSV=TRUE near the start of
the code, and the pointers will then work directly to the const data
(this is a feature supported by most of these chips 'Program Space Visibility'
which allows a window to be created to the ROM in RAM).
The compiler does also have a feature 'PASS_STRINGS=IN_RAM', which would
allow string arrays to have pointers generated to them. If you changed your
data to be in the form of a char array, you could 'sneak' this to allow the
pointers to const to be used. |
|
 |
|