• AVR Freaks

access flash memory

Author
kulkarni_saurabh
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2009/07/08 07:39:46
  • Location: 0
  • Status: offline
2009/07/18 04:28:40 (permalink)
0

access flash memory

i want to write and read some variable at run time in flash memory in dsPIC33F. it is possible? is there any library functions are available?
#1

6 Replies Related Threads

    pk_volt
    Super Member
    • Total Posts : 354
    • Reward points : 0
    • Joined: 2007/04/27 19:35:47
    • Location: 0
    • Status: offline
    RE: access flash memory 2009/07/18 04:46:27 (permalink)
    0
    If you search on the forums, you will find numerous information and code examples on how to read/write in program space.
    #2
    MoltenVoltage
    New Member
    • Total Posts : 22
    • Reward points : 0
    • Joined: 2008/11/02 22:22:56
    • Location: 0
    • Status: offline
    RE: access flash memory 2009/07/22 16:07:29 (permalink)
    0
    ORIGINAL: pk_volt

    If you search on the forums, you will find numerous information and code examples on how to read/write in program space.


    I've looked all over.  There is nothing out there worth a s*it.

    The best thing I've found yet is CE109 but I am still slogging through it
    #3
    pk_volt
    Super Member
    • Total Posts : 354
    • Reward points : 0
    • Joined: 2007/04/27 19:35:47
    • Location: 0
    • Status: offline
    RE: access flash memory 2009/07/22 23:02:13 (permalink)
    0
    Do you just simply want to read or write into flash memory?  Or is there something I'm misinterpreting? 

    I don't know how you searched the forums, but I'm sure there's more information in the C30 compiler forum section for what you may be looking for.


    post edited by pk_volt - 2009/07/22 23:21:45
    #4
    PeteA
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2007/05/16 08:49:19
    • Location: 0
    • Status: offline
    RE: access flash memory 2009/07/23 01:40:33 (permalink)
    0
    Hi Molten,

    Here are some functions to get you started. It's not particularly neat (I would re-write it without having a union), but it works for me. Apologies, there might be some slight syntax errors, as I've pasted this from a much larger set of functions (with CRC, different sectors for different settings, and various other bits and pieces).

    Be warned, many of the dspic33F's have a guaranteed flash life of 100 write cycles. You could call WriteNV() thousands of times a second and trash your PIC's flash in a second. Make sure you don't!!!

    These functions are documented in the C30 manual, and the headers are fairly helpful, and if you search for them in the forum there will be many hits.



    #define NV_NUM_PAGES 1

    typedef union
    {
        int Ints[_FLASH_ROW * NVRAM_NUM_PAGES];
        char Chars[_FLASH_ROW * NVRAM_NUM_PAGES * sizeof(int)];
    } NVStorage; 

    typedef struct
    {
        int Ints[_FLASH_PAGE * NVRAM_NUM_PAGES];
    } NVPage;


    static NVStorage RAMParams;
    __prog__ NVPage __attribute__((space(prog))) NVParams;

    void ReadNV(void)
    {
        _prog_addressT p;
        _init_prog_address(p, NVParams.Ints);
        memset((void *)RAMParams.Chars, 0, sizeof(NVStorage));
        _memcpy_p2d16((void *)RAMParams.Chars, p, sizeof(NVStorage));
    }

    void WriteNV(void)
    {
            int i;
            _init_prog_address(p, NVParams.Ints);
            _erase_flash(p);
           
            _init_prog_address(p, NVParams.Ints);       

            for(i = 0; i < NVRAM_NUM_PAGES; i++)
            {
                _write_flash16(p, &RAMParams.Ints[i * _FLASH_ROW]);
                p += (_FLASH_ROW * 2);
            }   
    }



    Pete
    #5
    pk_volt
    Super Member
    • Total Posts : 354
    • Reward points : 0
    • Joined: 2007/04/27 19:35:47
    • Location: 0
    • Status: offline
    RE: access flash memory 2009/07/23 01:58:39 (permalink)
    0
    the functions PetaA used to write to flash are documented in the C30 library support in section 4.7 :  http://ww1.microchip.com/downloads/en/DeviceDoc/51456E.pdf

    There are also a list of non-standard built-in function for mplab c30, which you can take a look at the C30 user manual.

    http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010065
    #6
    kulkarni_saurabh
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2009/07/08 07:39:46
    • Location: 0
    • Status: offline
    RE: access flash memory 2009/07/25 05:32:46 (permalink)
    0
    actually i want to store some variables in flash rom at RUN time not at compilation time. it is possible? using PSV it is possible? any inbuilt functions for it? 
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5