0

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)
9
  • 1
    You 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. Commented 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) Commented 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=0QC8uF4dYM0ANGmI Commented Sep 30, 2024 at 15:35
  • 1
    Thanks anyway. Will take a look at it if I'm back in the office. If I will find a solution I'll post it. Commented 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? Commented Sep 30, 2024 at 16:08

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.