Is there any way to place a const variable to an odd address of the flash, so that the value is in the HEX file?
It needs to be at a specific flash address, i can not use the SAF Block because its to small also the eeprom is fully occupied. Therefor a specific flash area will be allocated for storing values that are not changing so often.
in PIC16F devices this works flawless with:
const uint8_t dummydata[] __attribute__((address(0x2003))) = {0xAA};
PIC18F16Q41 to be exact, tells me that this is not on 2 Byte Boundary.
I've tried to create my own section but this gives me the same error.
i created my own section with the folling additional linker option:
-Wl,-PdummyData=2003h
in code i used the section as follows:
const uint8_t dummyData __section("dummyData") = {0xAA};
If i use an even address everything works and the value appears in the HEX file.
But because of the system design it needs to be at an odd address. (And in the HEX file of course)
Enviroment used:
- MPLAX v6.20
- XC8 v2.50 PRO
- Device: PIC18F16Q41
- Linker ROM Ranges: default,-2000-2400 (tried it also without this, still the same error)
-
1You probably need to use a linker script to define the region as non-executable (data) region since in PIC18, code must be 16 bit aligned.Clifford– Clifford2024年09月30日 13:37:18 +00:00Commented Sep 30, 2024 at 13:37
-
Is it feasible enough to write a linker script just for the region, since the default linker script is not present. If so how to hook it it up to the linker? The linker will run with the options defines in the ide. And there I have no clue how to define the region as non executable. I read the data sheet for the xc8 compiler and there is nearly nothing regarding this. (Or I over read that)Studiusus– Studiusus2024年09月30日 14:42:31 +00:00Commented Sep 30, 2024 at 14:42
-
To be honest if I knew, I'd have posted an answer. That is just where I'd start looking if it were me. MPLAB X can certainly accept a custom linker script youtu.be/or9K-zEbFMs?si=0QC8uF4dYM0ANGmIClifford– Clifford2024年09月30日 15:35:16 +00:00Commented Sep 30, 2024 at 15:35
-
1Thanks anyway. Will take a look at it if I'm back in the office. If I will find a solution I'll post it.Studiusus– Studiusus2024年09月30日 15:40:34 +00:00Commented Sep 30, 2024 at 15:40
-
Can't you simply put a 16 bit value at the even address 0x2002 with your byte in the upper half?the busybee– the busybee2024年09月30日 16:08:22 +00:00Commented Sep 30, 2024 at 16:08
1 Answer 1
Found a solution that works. its not pretty but anyway.
The linker options you can provide in the IDE are not sufficient enough to define the section to the need.
so i got an idea from this Microchip forum post
asm("psect dummyData,class=CODE,space=0,delta=1,reloc=1,noexec,ovrld,abs");
asm("org 0x2003");
volatile const uint8_t dummyData[] __section("dummyData") = {0xAA};
Now the following line will appear in the HEX file:
:01200300AA32