• AVR Freaks

Hot!PIC24 Flash addressing: How do I calculate the correct block address?

Author
user2x
Super Member
  • Total Posts : 318
  • Reward points : 0
  • Joined: 2011/02/10 20:43:36
  • Location: 0
  • Status: offline
2019/10/16 19:44:02 (permalink)
0

PIC24 Flash addressing: How do I calculate the correct block address?

I am dealing with PIC24FJ32GA002.
 
I need to find the start address of the last erasable Flash memory block.
Must not erase the Flash Config Words.   It is not clear to me if that is part of the User Flash or not.
 
Under "5.2 RTSP Operation":

 
The PIC24F Flash program memory array is organized
into rows of 64 instructions or 192 bytes. RTSP allows
the user to erase blocks of eight rows (512 instructions)
at a time and to program one row at a time. It is also
possible to program single words.
The 8-row erase blocks and single row write blocks are
edge-aligned, from the beginning of program memory, on
boundaries of 1536 bytes and 192 bytes, respectively.
 

 
How do I calculate the address of the last erasable block based on this information?
 
 
 
 
#1

4 Replies Related Threads

    NorthGuy
    Super Member
    • Total Posts : 5734
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: PIC24 Flash addressing: How do I calculate the correct block address? 2019/10/17 05:24:11 (permalink)
    0
    The config bytes start at 0x57fc. You round this to the nearest page boundary (0x400) = 0x5400 - that's the last page. This page contains config. The page below that is at 0x5000.
    #2
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3293
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: PIC24 Flash addressing: How do I calculate the correct block address? 2019/10/17 06:13:13 (permalink)
    0
    The block erase function should check that it does not overwrite itself or any memory that should be protected.
     
    error_code_overwrite:
        retlw     #FLERR_OVERWRITESELF,w0

    I set two markers: protect_start address and protect_end address.
    xxx xxx xxx
    xxx xxx xxx                             [CFG]
    0    1     2    3   4    5    6    7    end block
     
    3 and 4 contain the flash code,  protect that.
    8 contains config, protect that or modify.
    IVT etc.
     
     
     
     
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #3
    user2x
    Super Member
    • Total Posts : 318
    • Reward points : 0
    • Joined: 2011/02/10 20:43:36
    • Location: 0
    • Status: offline
    Re: PIC24 Flash addressing: How do I calculate the correct block address? 2019/10/17 13:59:23 (permalink)
    0
    NorthGuy
    The config bytes start at 0x57fc. You round this to the nearest page boundary (0x400) = 0x5400 - that's the last page. This page contains config. The page below that is at 0x5000.




    Thanks.That is great. I came to the same figure earlier. I will do a few experiments today.
     
    @Gort2015, I will check that too. Thanks  
    #4
    dan1138
    Super Member
    • Total Posts : 3260
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: PIC24 Flash addressing: How do I calculate the correct block address? 2019/10/17 15:03:36 (permalink)
    5 (1)
    For the PIC24 family calculating the the size of Read, Write and Erase blocks in bytes will twist your brain in knots.

    What keeps me saner is using instruction words and address units per instruction words.

    The one thing to remember is that instruction words are aligned on EVEN address.

    For the PIC24FJ32GA002 there are:

    11264 instruction words in device.
      512 instruction words in an erase block.
       22 erase blocks in the device.
       64 instruction words in a write block.
      176 write blocks in the device.

    Each erase block begins on a 0x400 address unit boundary.
    Each write block begins on a 0x080 address unit boundary.

    Because each instruction word is 3 bytes but is represented by only 2 address units converting blocks to bytes to addresses is very stressful on the brain.

    This exercise becomes pointless when your realize that the write block is packed with every two instruction words stuffed into three 16-bit words of the write block buffer.
    #5
    Jump to:
    © 2019 APG vNext Commercial Version 4.5