• AVR Freaks

Helpful ReplyHot!Cannot read pointed location using __eds__ pointer

Author
GianlucaL
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2017/06/13 09:30:00
  • Location: 0
  • Status: offline
2019/11/15 07:13:00 (permalink)
0

Cannot read pointed location using __eds__ pointer

Hi all!
I'm trying to read a value using a __eds__ pointer.
The value I want to read is at the address 0x25c00 and the value is 0x55.
 
Here is the code I'm using:
    uint8_t check; 
    EZBL_ReadROMObj(&check, 0x25c00); //I'm using EZBL...
    // here check=0x55 correctly
    
    //I would use this method, but is not working:
    __eds__ uint8_t *myPtr;
    myPtr= (__eds__ uint8_t *)0x25c00;
    // here myPtrpoint to 0x45c00 that is the correct eds pointer for hw address 0x25c00
    
    uint8_t result;
    result= *myPtr;
    // here result=0 but it should be 0x55

 
Can someoun point out the correct method for reading a value in flash using this kind of pointer?
 
Notes:
XC16 v1.41
PIC24FJ256GB406
#1
cawilkie
Administrator
  • Total Posts : 1993
  • Reward points : 0
  • Joined: 2003/11/07 12:49:11
  • Status: offline
Re: Cannot read pointed location using __eds__ pointer 2019/11/15 07:37:01 (permalink)
+1 (1)
An eds pointer is not simply a flash address.  A pointer is not an int and an int is not a pointer.  Even with a cast.
 
If you want to read the value of a flash address int his manner, use __builtin_tblrdl() (and set the TBLPAG fist).
 
0x45c00 is not the correct eds pointer value for the flash address 0x25c00.
 
With __eds__,__psv__  or other pointer types, its best to take the address of an object (which is the only valid C way of creating anything other than a NULL pointer).   You can create an object at a fixed address using the 'address' attribute; if you like.
 
Regards
Calum
#2
GianlucaL
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2017/06/13 09:30:00
  • Location: 0
  • Status: offline
Re: Cannot read pointed location using __eds__ pointer 2019/11/15 09:34:56 (permalink)
0
thanks cawilkie,
0x45c00 is not the correct eds pointer value for the flash address 0x25c00

As you can see I'm not an expert... infact I tought this was right because of this post https://www.microchip.com/forums/FindPost/725613
 
The address 0x25c00 is chosen as the starting address of a "flash hole" section created in the bootloader project.
My goal was to read some constants from the flash memory without having to copy the whole thing in the RAM (ie using EZBL_ReadROMObj or similar).
In my example I was using a pointer to uint8_t (__eds__ uint8_t *myPtr;) for simplicity, but in the real case I want to point to a quite complex struct which I know to be stored in the flash at that address.
So the point is to obtain something like this
typedef struct{
  uint8_t field1;
  uint16_t field2;
  char field3[3];
// lot of fields etc..
}my_struct_t

my_struct_t *structPointer;

void init(void){
   structPointer = 0x25c00 //point to the struct stored in flash
}

void use(void){
   uint8_t myvar;
   myvar = structPointer->field1;
   // etc...
}

without messing around with __builtin_tblrdl etc..
 
With __eds__,__psv__ or other pointer types, its best to take the address of an object..

Have you any suggestion for this particular case, where I know only the address?
#3
cawilkie
Administrator
  • Total Posts : 1993
  • Reward points : 0
  • Joined: 2003/11/07 12:49:11
  • Status: offline
Re: Cannot read pointed location using __eds__ pointer 2019/11/18 07:31:34 (permalink)
0
Question:  how do you know the address?
 
If its defined in the same link, then your definition looks something like this:
__eds__ my_struct_t flash_object __attribute__((space(prog))) = { /* some initial values */};

In this case you can simply use an appropriate prototype:
extern __eds__ my_struct_t flash_object;
If it isn't defined in this link, then you can tell the compiler where its located:
__eds__ my_struct_t flash_object __attribute__((space(prog),noload,address(0x<addr>));

noload tells the language tool that the memory shouldn't be loaded (its defined elsewhere) and the address attribute can be used to properly assign the address.
 
If you are already assigning an address using an address attribute; share the prototype between bootloader and application.  If you are hacking the linker script to create the hole and assign the address; share at least the portion of the linker script that you have used to define addresses.   Linker scripts can be pre-processed, if that helps, and more than one linker script can be passed to the tool.
 
When I modify linker scripts (for demo only), I will use the standard device linker script and a partial linker scripts with the changes I wish to use.
 
I don't really know how you know the address; hopefully you have assigned it in some way.   There are other methods for reserving memory between two applications, it all depends upon what you are trying to achieve.
 
Regards
Calum
 
#4
GianlucaL
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2017/06/13 09:30:00
  • Location: 0
  • Status: offline
Re: Cannot read pointed location using __eds__ pointer 2019/11/18 10:05:40 (permalink)
0
Question: how do you know the address?

I've reserved address space 0x25c00 to the end of the flash to my "eeprom" data.
The flash hole is declard in the BL project.
Is declared here because I don't want to wipe out the data when I download a new FW version.
(maybe there is another finer method, but I don't know)...
So by declaring the flash hole in BL, (I assume) the bootloader will not erase the flash portion I want to preserve.
 
__eds__ my_struct_t flash_object __attribute__((space(prog),noload,address(0x));

This would be perfect, but it return the error "Link Error: Could not allocate program memory"
I've tried this two alternatives:
__eds__ DATA_MEMORY_t flash_object __attribute__((space(eds), noload,address(0x25c00)));
__eds__ DATA_MEMORY_t flash_object __attribute__(( noload,address(0x25c00)));

and it compiles with both, but when the program reach an instruction like
myVar = flash_object.field;

an address error trap is triggered...
#5
cawilkie
Administrator
  • Total Posts : 1993
  • Reward points : 0
  • Joined: 2003/11/07 12:49:11
  • Status: offline
Re: Cannot read pointed location using __eds__ pointer 2019/11/19 07:20:51 (permalink)
0
Yes, you were supposed to fill in the address and you forgot space(prog).
 
Hopefully you are right about the bootloader...
 
Regards
Calum
#6
GianlucaL
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2017/06/13 09:30:00
  • Location: 0
  • Status: offline
Re: Cannot read pointed location using __eds__ pointer 2019/11/19 07:27:44 (permalink)
0
Oh, no wait...
Of course I've filled your proposed code line with the address
It was a typo in the post... stupid me
I've tried exactly the line
__eds__ DATA_MEMORY_t flash_object __attribute__((space(prog),noload,address(0x25c00)));

but as said, the link error was returned...
DATA_MEMORY_t is my struct type
I've added a missing ) from your proposed code:
__eds__ my_struct_t flash_object __attribute__((space(prog),noload,address(0x<addr>)); //missing ) after address

post edited by GianlucaL - 2019/11/19 07:31:43
#7
cawilkie
Administrator
  • Total Posts : 1993
  • Reward points : 0
  • Joined: 2003/11/07 12:49:11
  • Status: offline
Re: Cannot read pointed location using __eds__ pointer 2019/11/19 07:42:47 (permalink)
0
What is the error?
#8
GianlucaL
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2017/06/13 09:30:00
  • Location: 0
  • Status: offline
Re: Cannot read pointed location using __eds__ pointer 2019/11/19 07:45:55 (permalink)
0
 Link Error: Could not allocate program memory
make[2]: *** [dist/usb_msd/production/VDN3019_1.0.X.production.hex] Error 255
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
#9
cawilkie
Administrator
  • Total Posts : 1993
  • Reward points : 0
  • Joined: 2003/11/07 12:49:11
  • Status: offline
Re: Cannot read pointed location using __eds__ pointer 2019/11/20 07:38:22 (permalink)
0
You already provided that message, was there no other message from the linker?  Normally "could not allocate program memory" would provide other hints; which is what I was asking for. 
 
It would helpful to see the output from the link command line to the end.   Have you edited the linker script?  How big is the type my_struct_t?  Is there enough room for the allocation?
 
Perhaps you should contact support.microchip.com and provide an example or your FAE since we have now gone beyond the original question and there are other problems.
 
Regards
Calum
#10
GianlucaL
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2017/06/13 09:30:00
  • Location: 0
  • Status: offline
Re: Cannot read pointed location using __eds__ pointer 2019/11/20 09:01:55 (permalink)
0
 was there no other message from the linker?

No, this was the only message
 Have you edited the linker script?

I don't, but the ezbl utility produced this lines:
 
in file ex_boot_usb_msd.merge.gld:
  EZBL_ROM_AT_0x25C00 0x25C00 (NOLOAD) :
  {
    *(EZBL_ROM_AT_0x25C00); /* [0x25C00, 0x2AF7E), contains 32061 bytes */
  } > program
 
in file ex_boot_usb_msd.merge.S:
    ; Bootloader noload attributed hole intended for program region 'program'
    ; 0x025C00 to 0x02AF7E, length 0x00537E (32061 bytes; needs 20 pages)
    .pushsection    .text.eepromEmulation, address(0x025C00), code, keep, noload
    .skip 0x00537E
    .popsection
 
How big is the type my_struct_t?

about 300 bytes
Is there enough room for the allocation?

yes
 
Perhaps you should contact support.microchip.com and provide an example or your FAE since we have now gone beyond the original question and there are other problems.

Yes, maybe i will contact them.. But for now I will dump the flash content to the RAM (using the EZBL function EZBL_ReadROMObj which it works very well) and use the data from here... I don't like so much this solution because is a wasting of RAM... In case I will need a much bigger struct that don't fit in the RAM all in once, I will come back to try to solve this issue.
Anyway, I would like to thanks you so much for the support!
#11
cawilkie
Administrator
  • Total Posts : 1993
  • Reward points : 0
  • Joined: 2003/11/07 12:49:11
  • Status: offline
Re: Cannot read pointed location using __eds__ pointer 2019/11/21 07:44:39 (permalink) ☄ Helpfulby GianlucaL 2019/11/21 08:24:00
+1 (1)
Is the EZBL added content defined in the same executable that you are trying to link?  If so, that is the issue we are facing.   The .gld or .S file is defining some space and the C file is defining the same space.  We can't allocate more than one item there. 
 
The EZBL generated stuff does not provide any symbol to refer to it; shame.   Its there to make a hole in program memory.
 
Is there a way to get EZBL to define a symbol at the top of that space?
 
This would allow you to refer to the 'bootloaded' space:
 
; Bootloader noload attributed hole intended for program region 'program'
    ; 0x025C00 to 0x02AF7E, length 0x00537E (32061 bytes; needs 20 pages)
    .global _flash_object
    .pushsection    .text.eepromEmulation, address(0x025C00), code, keep, noload
    _flash_object:
    .skip 0x00537E
    .popsection
 
And:
 
extern __eds__ DATA_MEMORY_t flash_object __attribute__((space(prog),noload,address(0x25c00)));
It looks like EZBL is not set up to allow this kind of activity.
 
Regards
Calum 
#12
GianlucaL
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2017/06/13 09:30:00
  • Location: 0
  • Status: offline
Re: Cannot read pointed location using __eds__ pointer 2019/11/21 08:12:17 (permalink)
0
mmmm wait...
In the macro "EZBL_AllocFlashHole(holeName, byteLen, padAlignAddrSize, optAllocAddr) " there is something like the code you write:
// lot of stuff...
.global " STRINGIFY_SYM(holeName)
// lot of stuff...

And sure enough in my application project the code
extern __eds__ DATA_MEMORY_t eepromEmulation __attribute__((space(prog),noload,address(0x25c00)));

is compiled without errors!
 
But then the code.....
 
uint8_t test;
test = eepromEmulation.field;

 
throws some linker error.... sad: sad
build/usb_msd/production/src/app/data/data.o(.text+0xce): In function `.L9':
: Link Error: Cannot use WORD - EDSOFFSET on an absolute symbol (_eepromEmulation).
build/usb_msd/production/src/app/data/data.o(.text+0xd0): In function `.L9':
: Link Error: Cannot use WORD - EDSPAGE on an absolute symbol (_eepromEmulation).
make[2]: *** [dist/usb_msd/production/VDN3019_1.0.X.production.hex] Error 255
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
#13
GianlucaL
New Member
  • Total Posts : 19
  • Reward points : 0
  • Joined: 2017/06/13 09:30:00
  • Location: 0
  • Status: offline
Re: Cannot read pointed location using __eds__ pointer 2019/11/21 08:23:40 (permalink)
+1 (1)
EUREKA!!!
I don't really know why, but
extern __prog__ DATA_MEMORY_t eepromEmulation __attribute__((space(prog),noload,address(0x25c00)));

works like a charm!
Now it compiles, and all my struct fields are accessible
 
Wow, thanks so much cawilkie for your help! witout your suggestion I would never tried this last code.
 
 
#14
Jump to:
© 2019 APG vNext Commercial Version 4.5