• AVR Freaks

Hot!Address of a PSV variable

Page: 12 > Showing page 1 of 2
Author
CCP1CON
Super Member
  • Total Posts : 469
  • Reward points : 0
  • Joined: 2007/04/15 12:49:28
  • Location: good old Germany
  • Status: offline
2016/11/11 13:44:57 (permalink)
0

Address of a PSV variable

Hi all, I have the following variable:
volatile int __attribute__((address(0x2A00), space(psv))) Flash_Config[16];

If I Try to geht the address:
Word_burst_read_Flash((int)&Flash_Config, (int)&Ram_Config, 64);

The Compiler or Linker is of the oppinion Flash_Config is at 0xAA00.
I'm sure theres is an explanation fort that?
 
Tanks
Carsten
post edited by CCP1CON - 2016/11/12 04:03:35
#1

26 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 18060
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Address of a PSV variable 2016/11/11 14:03:31 (permalink)
    3 (1)
    It has a real address and a PSV address. Actually it has several PSV addresses. (read the data sheet)
    The address you get from that will be assuming the PSV is at the default compiler setting.
    You need to check the PSV to determine the physical address.
    #2
    MBedder
    Circuit breaker
    • Total Posts : 6809
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: Address of a PSV variable 2016/11/11 14:06:58 (permalink)
    3 (1)
    Program Memory chapter of the FRM - 4.5 PROGRAM SPACE VISIBILITY FROM DATA SPACE, Figure 4-7, 4-8.
    #3
    CCP1CON
    Super Member
    • Total Posts : 469
    • Reward points : 0
    • Joined: 2007/04/15 12:49:28
    • Location: good old Germany
    • Status: offline
    Re: Address of a PSV variable 2016/11/12 04:02:17 (permalink)
    0
    It cannot have several PSV addresses, at least not in my case, because this particular PIC has only one PSVPAGe. As I understand, it is a dsPIC33FJ16GS502.
    Also, if I force the Linker to place the variable at 0x2A00 how can it get a different address then?
    And finally it is at 0x2A00, the Debugger tells me.
     
    The address you get from that will be assuming the PSV is at the default compiler setting.

     
    I could not find such a setting!?
    post edited by CCP1CON - 2016/11/12 04:06:31
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 18060
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Address of a PSV variable 2016/11/12 06:17:01 (permalink)
    3 (1)
    Did you look up the PSV register and how it works?
    The variable is where you put it. If you want the use the flag API it is there.
    But if you use it in the program it is remapped via the PSV window. And you may need to change the PSV regeister to move the window if the variable is not in the default.
    If you do you would need to insure you consider the interrupts.
    #5
    CCP1CON
    Super Member
    • Total Posts : 469
    • Reward points : 0
    • Joined: 2007/04/15 12:49:28
    • Location: good old Germany
    • Status: offline
    Re: Address of a PSV variable 2016/11/12 13:23:59 (permalink)
    0
    Thanks Neil an sorry, I dont exactly get what you mean.
     
    Did you look up the PSV register and how it works?
    The variable is where you put it.

    Yes, I guess I got the principle of PSVPAG. But in my case PSVPAGE is always Zero.
    If you want the use the flag API it is there.

    What? :-)
    But if you use it in the program it is remapped via the PSV window. And you may need to change the PSV regeister to move the window if the variable is not in the default.

    Ok. But I dont want to map it. I just want its address in program memory.
    If you do you would need to insure you consider the interrupts.

    What? :-)
     
    #6
    NKurzman
    A Guy on the Net
    • Total Posts : 18060
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Address of a PSV variable 2016/11/12 14:34:15 (permalink)
    3 (1)
    The PSV start at 7fff
    So if the PSV register is 0
    At you read 7fff you will read flash address 0
    The compiler will group all its const data together so it can be accessed.
    If your address is in the window it picked you can use the compiler macro it the math in the data sheet to translate the address.
    If it is not you will need to change PSV so that your address is in the window.
    If you do and there is an interrupt it will not know the PSV is not at the default. This can be solved or ignored depending on your code.

    You can not use the actual address in the flash directly.
    #7
    NorthGuy
    Super Member
    • Total Posts : 5817
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Address of a PSV variable 2016/11/12 16:58:50 (permalink)
    4.5 (2)
    CCP1CON
    But I dont want to map it. I just want its address in program memory.



    There are two separate address spaces - program memory and data memory. If you want to address program memory as data you have to map the program memory space into the data memory space, and this is done through PSV.
     
    #8
    NKurzman
    A Guy on the Net
    • Total Posts : 18060
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Address of a PSV variable 2016/11/12 17:23:42 (permalink)
    0
    If you want to read it by it actual address you can use the flash API.
    But you can not just do a straight read wit C that way.
    #9
    CCP1CON
    Super Member
    • Total Posts : 469
    • Reward points : 0
    • Joined: 2007/04/15 12:49:28
    • Location: good old Germany
    • Status: offline
    Re: Address of a PSV variable 2016/11/13 02:36:55 (permalink)
    0
    Thanks Folks, this is all clear to me, I guess.
     
    My question is: if I foce the Linker to place the variable at 0x2A00 (and this works fine) how can I get it's address during compile time. Like (int)&variable?
    post edited by CCP1CON - 2016/11/13 02:58:53
    #10
    MBedder
    Circuit breaker
    • Total Posts : 6809
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: Address of a PSV variable 2016/11/13 03:01:41 (permalink)
    4 (1)
    unsigned int __builtin_psvoffset(const void *p);

    #11
    NKurzman
    A Guy on the Net
    • Total Posts : 18060
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Address of a PSV variable 2016/11/13 10:08:17 (permalink)
    4 (1)
    Which address it's PSV address or physical address? If you are out of the default PSV window you can not treat it like an ordinary C variable.

    What are you actually trying to do with this absolute flash variable? Is is important that it be absolute?
    The PSV window is 32K big
    #12
    CCP1CON
    Super Member
    • Total Posts : 469
    • Reward points : 0
    • Joined: 2007/04/15 12:49:28
    • Location: good old Germany
    • Status: offline
    Re: Address of a PSV variable 2016/11/13 23:55:21 (permalink)
    0
    With __attribute__((address(0x2A00)) I force it to its physical address. Which should be in my case the same as its PSV address because we are on page Zero (Am I right?). That is why I was of the oppinion that I can get the address during complile time in the usual way like &variable. But obviously the Compiler thinks different and gives me its address but on PSV page one (0xAA00). If I understand right.
     
    I will try with __builtin_ ...
    #13
    CCP1CON
    Super Member
    • Total Posts : 469
    • Reward points : 0
    • Joined: 2007/04/15 12:49:28
    • Location: good old Germany
    • Status: offline
    Re: Address of a PSV variable 2016/11/14 00:11:00 (permalink)
    4 (1)
    Ok I found more Explanation: The EA<15> is alway 1 to indicate that PSVPAG is to concateneted with the lower 15 bits of EA. That explains the 0xAA00
    #14
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3370
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: online
    Re: Address of a PSV variable 2016/11/22 10:16:11 (permalink)
    0
    Here is some code that reads from 24bit flash. 16bit or 24 bit data.
    Writing is a bit more involved.
    .include "xc.inc"
    .include "FlashLib2.inc"
    ;----------------------------------------------------
    .globl _rdflash24,_rdflash16
    ;----------------------------------------------------
    .equ arg_pSrc_H,   w0
    .equ arg_pSrc,       w1
    .equ arg_pDest,     w2
    .equ arg_Len,        w3
    ;rtn arg_pSrc_H,    w0
    ;rtn arg_pSrc,       w1
    ;rtn arg_pDest,     w2
    ;rtn error,            w3

    rdflash24:
        ;word aligned
        btsc    arg_pSrc,#0
        bra     error_word_align
        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ;null buffer?
        cp0     arg_pDest
        bra     z,error_null
        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ;1MB flash not available
        cp      arg_pSrc_H,#16
        bra     gtu,error_memory
        mov     arg_pSrc_H,TBLPAG
        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    loop_rf24:
        tblrdh.b [arg_pSrc],[arg_pDest++]
        tblrdl.b [arg_pSrc++],[arg_pDest++]
        tblrdl.b [arg_pSrc++],[arg_pDest++]
        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ;cross boundry
        cp0     arg_pSrc
        bra     nz,$+4
        inc     TBLPAG
        dec     arg_Len,arg_Len
        bra     nz,loop_rf24
        mov     #FLERROR_OK,w3
        return
    ;----------------------------------------------------
    ;----------------------------------------------------
    ;----------------------------------------------------
    .equ arg_pSrc_H,    w0
    .equ arg_pSrc,      w1
    .equ arg_pDest,     w2
    .equ arg_Len,       w3
    .equ tmp,           w4
    ;rtn arg_pSrc_H,    w0
    ;rtn arg_pSrc,      w1
    ;rtn arg_pDest,     w2
    ;rtn error,         w3

    rdflash16:
        ;word aligned
        btsc    arg_pSrc,#0
        bra     error_word_align
        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ;null buffer
        cp0     arg_pDest
        bra     z,error_null
        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ;1MB flash not available
        cp      arg_pSrc_H,#16
        bra     gtu,error_memory
        mov     arg_pSrc_H,TBLPAG
        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    loop_rf16:
        tblrdl  [arg_pSrc++],[arg_pDest++]
        cp0     arg_pSrc    ;cross boundry
        bra     nz,$+4
        inc     TBLPAG
        dec     arg_Len,arg_Len
        bra     nz,loop_rf16
        mov     #FLERROR_OK,w3
        return
     
     
     
      ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
     
     
    error_word_align:
        mov     #FLERROR_WORD_ALIGN,w3
        return
        ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
     
     
    error_null:
        mov     #FLERROR_NULL_BUFFER,w0
        return
     
     
     
       ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
     
     
    error_memory:
        mov     #FLERROR_MEMORY_1MB,w3
        return
    ;----------------------------------------------------
     
     
     
    .end

     
    __prog__ char __attribute__((space(prog),section("Gort1951"),fillupper(0xff))) NOT_THE_EVIL_DEAD[]="klaatu barada nikto";
     
    post edited by Gort2015 - 2016/11/22 10:21:29
    #15
    CCP1CON
    Super Member
    • Total Posts : 469
    • Reward points : 0
    • Joined: 2007/04/15 12:49:28
    • Location: good old Germany
    • Status: offline
    Re: Address of a PSV variable 2016/11/22 10:48:31 (permalink)
    3 (1)
    Thanks Marty, I got it working too.
    #16
    jeff_d
    Starting Member
    • Total Posts : 45
    • Reward points : 0
    • Joined: 2017/12/11 08:49:30
    • Location: 0
    • Status: offline
    Re: Address of a PSV variable 2019/11/12 09:03:26 (permalink)
    0
    CCP1CON
    Ok I found more Explanation: The EA<15> is alway 1 to indicate that PSVPAG is to concateneted with the lower 15 bits of EA. That explains the 0xAA00


    Thanks for pointing this out because I noticed the same when dealing with PSV storage defined in flash as:
    #define TEST_DATA_PAGE_ADDR (0x5000)
     
    uint16_t FlashPageRow1[] __attribute__ ((keep, space(psv), address(TEST_DATA_PAGE_ADDR))) = {...}

    __builtin_tblpage and __builtin_tbloffset can get the correct page and offset, but if I try to assign a pointer to the memory the address I get has the high bit set.
     
    uint16_t (*FlashMemoryPtr)[FLASH_PAGE_SIZE_INST];
     
    FlashMemoryPtr = FlashPageRow1;

    FlashMemoryPtr will be 0xD000, the map has it defined as 0x005000
     
    There seems to be no issue reading from the point with:
    umol = (*FlashMemoryPtr)[42];

    I'm on a 32k part so there's only one 32k page and have been told that 0xD000 maps to 0x5000 and that does seem to be true. Is there any reason to be concerned with the high bit being set in the pointer? Or is the high bit only used for table access and ignored with direct access using the pointer? Althought, why would the compliler puts this into configuration address space.
     
    (FWIW, I understand this only works for the single 32k page part where everything lives in the same page)
    post edited by jeff_d - 2019/11/12 09:04:47
    #17
    NKurzman
    A Guy on the Net
    • Total Posts : 18060
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Address of a PSV variable 2019/11/12 09:26:57 (permalink)
    0
    The page is 32K but it appears as the upper 32K RAM addresses. Note it is a sliding window not a page. The flash page start is not on 32K blocks.
    #18
    jeff_d
    Starting Member
    • Total Posts : 45
    • Reward points : 0
    • Joined: 2017/12/11 08:49:30
    • Location: 0
    • Status: offline
    Re: Address of a PSV variable 2019/11/12 13:17:53 (permalink)
    0
    NKurzman
    The page is 32K but it appears as the upper 32K RAM addresses. Note it is a sliding window not a page. The flash page start is not on 32K blocks.



    Thanks. The first part of your repsonse has me confused, what exactly does this mean from the perspective of the program and accessing the memory? Can it be read (I'm only reading, writing will be done with the tblwr functions) from program space with a 16-bit pointer reference? I think the answer is yes and you're saying it's just mapped to an upper region as the reson for the high bit being set. I want to access it as DS (16-bit addr) and not PS(24-bit addr). Since the PC is in the same 32K I only need 15 bits, which is what I'm trying to do with the pointer direct from the same 32K in PS.  I also don't care about the upper byte, so no need for the tblrdh. I do use tblwrl/h functions for the writes.
     
    FWIW I'm on a 33EP32MC202. The Paged Data Memory Space diagram is a little confusing but it looks like Program Space and Table Address Space map to the same EDS memory which would be accessed through the window you mentioned. But on a 32K part and I don't think the window slides, it's just a fixed 32k EDS window. Is that correct?
     
    Yup I understand the flash page differing from several other uses of "page" in the microchip world. I'm not a fan and found myself in disucssion where two people are talking about different pages without understand there's a difference.
     
    Yup, I understand the flash page boundries are smaller at 0x0400.
    #19
    DuaneH
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2009/10/15 11:49:22
    • Location: Sandy, UT
    • Status: offline
    Re: Address of a PSV variable 2019/11/12 13:46:02 (permalink)
    5 (1)
    bit 15 of the address is used as a flag to indicate PSV access.  In other words, the address of the constant is in the lower 15 bits of the address, and the upper bit of the address just means that the data will come from PSV (i.e., program memory) instead of data memory.
     
    FYI, there is a bug in every version of XC16 that I have tried where it will not correctly set the PSVPAG register for a variable in PSV page 1.  It apparently looks at the address (say, 0x8765), and assumes that it is addressing a constant at 0x765 in program space.  No code is generated to set the PSVPAG prior to the access.  The only workaround I have been able to find for this is to set up a separate constants section in the linker file, and assign all constants (usually strings) to that section so that they are all in PSV page 0.  This won't affect your 16K processor, but anything larger than that can potentially have this issue.

    duaneh
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5