• AVR Freaks

Hot!Flash Memory Programming - EEPROM Emulation

Author
RonGer
Starting Member
  • Total Posts : 51
  • Reward points : 0
  • Joined: 2018/11/27 08:43:34
  • Location: 0
  • Status: offline
2019/08/27 03:06:34 (permalink)
0

Flash Memory Programming - EEPROM Emulation

Dear all,
 
I'm trying to use the flash memory of the DSPIC33EV256GM104 as a EEPROM.
Therefore I coded a routine, based on the flash_demo project.
For reserving flash memory I'm using the following code line.
uint16_t reserved_flash[1024] __attribute__((space(prog), address(0x1000), section(".reserved_flash"), noload));
 
With this code I would expect that when I reserve memory at address 0x1000, the SW writes to this adress and the next 64 rows. But it doesn't! It writes the data to the address (in hex file) 0x002000.
When I reserve memory at address 0x2000 the SW writes the data to address 0x004000.
The memory should be within the User Flash Memory area (0x000200 - 0x00AB7E).
 
Does anybody know whats the systematic behind this or why this does happen?
 
Kind Regards and thanks in advance
 
Ron
#1

9 Replies Related Threads

    ric
    Super Member
    • Total Posts : 25200
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Flash Memory Programming - EEPROM Emulation 2019/08/27 03:17:46 (permalink)
    0
    Are you allowing for the fact that hex files are byte based?
    All addresses in a hex file refer to byte addresses.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    RonGer
    Starting Member
    • Total Posts : 51
    • Reward points : 0
    • Joined: 2018/11/27 08:43:34
    • Location: 0
    • Status: offline
    Re: Flash Memory Programming - EEPROM Emulation 2019/08/27 03:33:16 (permalink)
    0
    Hello Ric,
     
    thanks for your fast reply.
    I think I consider that the addresses in a hex file refer to by addresses.
    What I tried to address with e.g. 0x2000 in the hex file, is the line which has this address.
    Unfortunately the data isn't written from this address, but from the address 0x4000 (see hex extract - in fat letters).
    This confuses me.
     
    :103FD000FFFFFF00FFFFFF00FFFFFF00FFFFFF00ED
    :103FE000FFFFFF00FFFFFF00FFFFFF00FFFFFF00DD
    :103FF000FFFFFF00FFFFFF00FFFFFF00FFFFFF00CD
    :104000008810020088100200FFFFFF00FFFFFF0082
    :104010000100000066554400CCBBAA00FFEEDD00A5
    :104020000200000066554400CCBBAA00FFEEDD0094
    :104030000300000066554400CCBBAA00FFEEDD0083
    :104040000400000066554400CCBBAA00FFEEDD0072
    :104050000500000066554400CCBBAA00FFEEDD0061
    :104060000600000066554400CCBBAA00FFEEDD0050
    :104070000700000066554400CCBBAA00FFEEDD003F
    :104080000800000066554400CCBBAA00FFEEDD002E
    :104090000900000066554400CCBBAA00FFEEDD001D
    :1040A0000A00000066554400CCBBAA00FFEEDD000C
    :1040B0000B00000066554400CCBBAA00FFEEDD00FB
    :1040C0000C00000066554400CCBBAA00FFEEDD00EA
    :1040D0000D00000066554400CCBBAA00FFEEDD00D9
    :1040E0000E00000066554400CCBBAA00FFEEDD00C8
    :1040F0000F00000066554400CCBBAA00FFEEDD00B7
    :104100001000000066554400CCBBAA00FFEEDD00A5
    :104110001100000066554400CCBBAA00FFEEDD0094
    :104120001200000066554400CCBBAA00FFEEDD0083
    :104130001300000066554400CCBBAA00FFEEDD0072
    :104140001400000066554400CCBBAA00FFEEDD0061
    :10415000FFFFFF00FFFFFF00FFFFFF00FFFFFF006B
    :10416000FFFFFF00FFFFFF00FFFFFF00FFFFFF005B
    :10417000FFFFFF00FFFFFF00FFFFFF00FFFFFF004B
    :10418000FFFFFF00FFFFFF00FFFFFF00FFFFFF003B
    :10419000FFFFFF00FFFFFF00FFFFFF00FFFFFF002B
    :1041A000FFFFFF00FFFFFF00FFFFFF00FFFFFF001B
    :1041B000FFFFFF00FFFFFF00FFFFFF00FFFFFF000B
    #3
    du00000001
    Just Some Member
    • Total Posts : 3314
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Flash Memory Programming - EEPROM Emulation 2019/08/27 03:50:17 (permalink)
    0
    PEBKAC!
     
    When writing flash on  the dsPICs, the addresses are word addresses. Thus you'd have to divide your byte addresses by 2. This way you'll have 2 bytes for the same address (as the xxx1 is "vanishing" when dividing). IIRC, there may be some more intricacies, but there's some documentation available.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #4
    RonGer
    Starting Member
    • Total Posts : 51
    • Reward points : 0
    • Joined: 2018/11/27 08:43:34
    • Location: 0
    • Status: offline
    Re: Flash Memory Programming - EEPROM Emulation 2019/12/09 03:13:07 (permalink)
    0
    Hello,
     
    I found the EEPROM Emulation on the Microchip page:
    https://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en530593
     
     
    I implemented the API to my SW so far and it works.
    Unfortunately it's only feasible to write seperate variables into the EEPROM. I can't create a structure inside the EEPROM. Has anybody experience with this? It would increase the Performance of my SW a lot.
    #5
    RonGer
    Starting Member
    • Total Posts : 51
    • Reward points : 0
    • Joined: 2018/11/27 08:43:34
    • Location: 0
    • Status: offline
    Re: Flash Memory Programming - EEPROM Emulation 2019/12/09 04:44:18 (permalink)
    0
    Initializing the EEPROM itself isn't working either.
    The API only seems to support read and write. But as soon as I do the following:
     
    unsigned char emulationPages[DATA_EE_BANKS * NUM_DATA_EE_PAGES][NUMBER_OF_INSTRUCTIONS_IN_PAGE * 2] __attribute__ ((space(psv), address(ADD_STRUCT_A), aligned(NUMBER_OF_INSTRUCTIONS_IN_PAGE *2))) = {1,2,3,4,5,6}
     
    the EEPROM is initialized, but when I read the Memory at boot, the ReadEE() function Returns "SetaddrNotFound".
     
    Can anybody provide me some Information how to initialize the Emulated EEPROM Content at build and in best case with a typedef structure datatype or even better with a union.
     
    Thanks in advance and kind regards 
     
    Ron
    #6
    du00000001
    Just Some Member
    • Total Posts : 3314
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: Flash Memory Programming - EEPROM Emulation 2019/12/09 04:55:17 (permalink)
    5 (1)
    The error is in line 47.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #7
    JPortici
    Super Member
    • Total Posts : 876
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: Flash Memory Programming - EEPROM Emulation 2019/12/09 05:32:30 (permalink)
    0
    mm.. i have use the library succesfully with almost zero effort on my part.
    The header file has some settings that have to match your code and device (ECC, row size, base address, .. that sorts of things)
     
    At some point i modified the library because
    -the code inside the library is blocking :( Well.. not an issue in the EV as the execution is halted while writing. It's an issue if you use it on devices with AUX flash and write to aux flash, which doesn't halt the execution.
    -the code inside the library will mess with your interrupts, if you have frequent interrupts you will miss events.. but not an issue in the EV because of the above
    #8
    RonGer
    Starting Member
    • Total Posts : 51
    • Reward points : 0
    • Joined: 2018/11/27 08:43:34
    • Location: 0
    • Status: offline
    Re: Flash Memory Programming - EEPROM Emulation 2019/12/09 13:40:25 (permalink)
    0
    Hello JPortici,
     
    thanks for you reply. The library itself is running on my device as well. The Thing that isn't working is that I would like to initialize the allocated Flash at the build. When I do it like in my last post, the EERead function Returns the failure Code mentioned above. For this reason I think my initialization isn't 100% correct.
    Unfortunately the documentation and description in AN1095 isn't really detailled in this regard.
    The other Thing that I would like to accomplish is not only to use regular datatypes in the emulated EEPROM, but typedef structs. For reading this isn't an issue. Problems occur when I try to write to the structure, because the functions of the API are made for regular datatypes. 
    So for this reason I asked whether someone has experience with using typedef structures with this code and whether it makes sense to modify it, or better just write an own code.
     
     
    Kind Regards
     
    Ron
     
    #9
    JPortici
    Super Member
    • Total Posts : 876
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: Flash Memory Programming - EEPROM Emulation 2019/12/10 00:13:42 (permalink)
    5 (1)
    I have to go from memory because i transitioned to a different solution.
     
    No, you cannot initialize the allocated flash on a build.
    I assume that by "initialize" you mean write predefined values in your eeprom. You have to for example check one cell for a known value and if it's not there initialize it yourself.
    You clearly have not understood how the library works and how initialization works. The library uses one or more flash pages per eeprom cell in order to perform wear levelling and other manteinance tasks. initializing like that means you are writing to successive flash cells. It's should be obvious it doesn't work like that.
     
    For the same reason you can't write and read structures in a single pass. You have to read and write single bytes (with all the overhead and the stalling during writes) and disassemble/reassemble the struct.
     
    These are the reasons why in my 33EV projects i use external EEPROMs. Let them be SPI or I2C, i don't care. I keep a copy of the content in ram during execution and when needed i reload or rewrite.
    In devices with aux memory i use the aux memory to store the data directly without libraries or whatever. A lot faster to read/write, doesn't stall execution, not affected by communication issues and i'm not concerned about flash cell wearing because the number of expected writes during the lifetime of the product is under 1000
    #10
    Jump to:
    © 2020 APG vNext Commercial Version 4.5