PSV section `.const` exceeds 32K

Author
tystent
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2006/11/02 14:52:03
  • Location: 0
  • Status: offline
2010/03/17 15:30:21 (permalink)
0

PSV section `.const` exceeds 32K

My C program has a huge amount of constant data.  The program is small, and together they should not use up all the program space in the dsPIC33FJ256GP710 (and yes, I know that data storage in PSV wastes 1/3 of the bytes).

I get this error from Link30:
 Link Error: PSV section '.const' exceeds 32K bytes (actual size = 107360).
 Link Error: Could not allocate program memory

Besides qualifying the arrays with 'const', I tried using __attribute__((space(auto_psv))) to the same ill effect.

Does anyone know a way around this?
#1

7 Replies Related Threads

    aschen0866
    Super Member
    • Total Posts : 4113
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    RE: PSV section `.const` exceeds 32K 2010/03/17 16:33:18 (permalink)
    +2 (1)
    Read C30 User's Guide Section 6.2.2. You can use either __psv__ or __prog__ along with space(psv) or space(prog) to define constants in the program memory. For example:

    const __prog__ int __attribute__((space(prog))) my_table[] = {1, 2, 3, 4, 5};

    The compiler will manage PSVPAG to get the data for you. It is slower than the normal PSV access but that's the best you can.

    You can also use assembly file to define objects in the program memory and then use either _memcpy_p2d16() or _memcpy_p2d14() to read the object into data memory space.
    #2
    tystent
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2006/11/02 14:52:03
    • Location: 0
    • Status: offline
    RE: PSV section `.const` exceeds 32K 2010/03/17 17:33:09 (permalink)
    0
    Thanks for the tip; it satisfies the linker.
     
    My admittedly old copy (51284E, 2005) of the C30 User Guide does not mention this.  I can't find a newer one online.
    #3
    CesareAugusto
    Starting Member
    • Total Posts : 50
    • Reward points : 0
    • Joined: 2005/11/05 05:37:25
    • Status: offline
    RE: PSV section `.const` exceeds 32K 2010/03/19 00:06:31 (permalink)
    0
    Hi tystent,
    I gave the same problem (few days ago), my solution was like this:
    1) define in the linking script the area from where to store the data:
    __FPGA_PROG_DATA = 0x00AA00;

    ...

    .fpgadata __FPGA_PROG_DATA :
      {
        *(.fpga_prog_data_00);
        *(.fpga_prog_data_01);
        *(.fpga_prog_data_02);
        *(.fpga_prog_data_03);
        *(.fpga_prog_data_04);
        *(.fpga_prog_data_05);
        *(.fpga_prog_data_06);
        *(.fpga_prog_data_07);
        *(.fpga_prog_data_08);
        *(.fpga_prog_data_09);
        *(.fpga_prog_data_10);
        *(.fpga_prog_data_11);
        *(.fpga_prog_data_12);
        *(.fpga_prog_data_13);
        *(.fpga_prog_data_14);
        *(.fpga_prog_data_15);
      } >fpgadata

    2) generate the array used for store the data with the proper directive to the linker:
    const __attribute__ ((section (".fpga_prog_data_00,code"))) FPGA_CfgData_t FPGA_CfgData_00 =
    {
        /* 0x0000AA00 */    {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
    ...
    };

    const __attribute__ ((section (".fpga_prog_data_06,code"))) FPGA_CfgData_t FPGA_CfgData_06 =
    {
        /* 0x00022A00 */    {0x9F, 0x84, 0x25, 0xD2, 0x18, 0xF4, 0x84, 0x2E, 0x12, 0x9F, 0x84, 0x25, 0xD2, 0x18, 0xF4, 0x84, 0x2E, 0x12, 0x9F, 0x84, 0x25, 0xD2, 0x18, 0xF4, 0x84, 0x2E, 0x12, 0x9F, 0x84, 0x25, 0xD2, 0x18},
    ...
    };

    keep the data public in order to avoid cancellation due to the compiler's optimization;

    3) write a very short program to copy the data from the FLASH to the RAM in order to speed up the programming process of the component (in my case a Ciclone III):

    ;***************************************************************
    ; W1:W0 -> Data's start address;
    ; W2    -> Buffer's destination address;
    ; W3    -> Buffer's length
    ; The data is exchanged while loaded (Hi <-> Lo)

    __ReadDataFromFlashX:
        push    TBLPAG
        mov      w1, _TBLPAG    ; TBLPAG = tblpage(src)
        mov      w0, w5         ; w5 =   tbloffset(src)
    rd_loopX:
        tblrdl  [w5++], W0
        swap    W0              ; Swaps the bytes
        mov     W0, [w2++]      ; dst++ = lo byte
        cp0     w5
        bra     nz, no_wrapX
        add     w1, #1, W1
        mov     w1, _TBLPAG     ; TBLPAG = tblpage(src)
    no_wrapX:
        dec     w3, w3          ; num--
        bra     nz, rd_loopX    ; br if done
    rd_doneX:
        pop        TBLPAG
        return

    in order to speed up the copy process, the data is readden and writen as words (keep attention on the byte orders when the data is sent out from the MCU).

    Thak's all.
    Hope this can help.
    Good work!
      Cesare

    #4
    Kruse
    Super Member
    • Total Posts : 1224
    • Reward points : 0
    • Joined: 2005/04/15 09:04:09
    • Location: Denmark
    • Status: offline
    RE: PSV section `.const` exceeds 32K 2010/03/21 19:52:43 (permalink)
    0
    ORIGINAL: tystent

    My admittedly old copy (51284E, 2005) of the C30 User Guide does not mention this.  I can't find a newer one online.

     
    Is it a .pdf ?
    MCHP has emerged to the much more convient .chm files for documentation, they should allready be in your installation.

    A PIC listens to your commands -not your intentions.
    #5
    cawilkie
    Administrator
    • Total Posts : 1955
    • Reward points : 0
    • Joined: 2003/11/07 12:49:11
    • Status: offline
    RE: PSV section `.const` exceeds 32K 2010/03/22 10:35:59 (permalink)
    0
    ORIGINAL: CesareAugusto

    Hi tystent,
    I gave the same problem (few days ago), my solution was like this:
    1) define in the linking script the area from where to store the data:
    __FPGA_PROG_DATA = 0x00AA00;

    ...

    .fpgadata __FPGA_PROG_DATA :
    {
       *(.fpga_prog_data_00);
       *(.fpga_prog_data_01);
       *(.fpga_prog_data_02);
       *(.fpga_prog_data_03);
       *(.fpga_prog_data_04);
       *(.fpga_prog_data_05);
       *(.fpga_prog_data_06);
       *(.fpga_prog_data_07);
       *(.fpga_prog_data_08);
       *(.fpga_prog_data_09);
       *(.fpga_prog_data_10);
       *(.fpga_prog_data_11);
       *(.fpga_prog_data_12);
       *(.fpga_prog_data_13);
       *(.fpga_prog_data_14);
       *(.fpga_prog_data_15);
    } >fpgadata

    2) generate the array used for store the data with the proper directive to the linker:
    const __attribute__ ((section (".fpga_prog_data_00,code"))) FPGA_CfgData_t FPGA_CfgData_00 =
    {
       /* 0x0000AA00 */    {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
    ...
    };

    const __attribute__ ((section (".fpga_prog_data_06,code"))) FPGA_CfgData_t FPGA_CfgData_06 =
    {
       /* 0x00022A00 */    {0x9F, 0x84, 0x25, 0xD2, 0x18, 0xF4, 0x84, 0x2E, 0x12, 0x9F, 0x84, 0x25, 0xD2, 0x18, 0xF4, 0x84, 0x2E, 0x12, 0x9F, 0x84, 0x25, 0xD2, 0x18, 0xF4, 0x84, 0x2E, 0x12, 0x9F, 0x84, 0x25, 0xD2, 0x18},
    ...
    };

    keep the data public in order to avoid cancellation due to the compiler's optimization;

    3) write a very short program to copy the data from the FLASH to the RAM in order to speed up the programming process of the component (in my case a Ciclone III):

    ;***************************************************************
    ; W1:W0 -> Data's start address;
    ; W2    -> Buffer's destination address;
    ; W3    -> Buffer's length
    ; The data is exchanged while loaded (Hi <-> Lo)

    __ReadDataFromFlashX:
       push    TBLPAG
       mov      w1, _TBLPAG    ; TBLPAG = tblpage(src)
       mov      w0, w5         ; w5 =   tbloffset(src)
    rd_loopX:
       tblrdl  [w5++], W0
       swap    W0              ; Swaps the bytes
       mov     W0, [w2++]      ; dst++ = lo byte
       cp0     w5
       bra     nz, no_wrapX
       add     w1, #1, W1
       mov     w1, _TBLPAG     ; TBLPAG = tblpage(src)
    no_wrapX:
       dec     w3, w3          ; num--
       bra     nz, rd_loopX    ; br if done
    rd_doneX:
       pop        TBLPAG
       return

    in order to speed up the copy process, the data is readden and writen as words (keep attention on the byte orders when the data is sent out from the MCU).

    Thak's all.
    Hope this can help.
    Good work!
    Cesare



    You have worked way too hard, a little light reading would have saved you some coding and it would have been much more flexible.

    ie:


    const __attribute__ ((section (".fpga_prog_data"),space(prog),address(0xAA00))) FPGA_CfgData_t FPGA_CfgData_00 =
    {
    /* 0x0000AA00 */ {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
    ...
    };

    const __attribute__ ((section (".fpga_prog_data"),space(prog))) FPGA_CfgData_t FPGA_CfgData_06 =
    {
    /* 0x00022A00 */ {0x9F, 0x84, 0x25, 0xD2, 0x18, 0xF4, 0x84, 0x2E, 0x12, 0x9F, 0x84, 0x25, 0xD2, 0x18, 0xF4, 0x84, 0x2E, 0x12, 0x9F, 0x84, 0x25, 0xD2, 0x18, 0xF4, 0x84, 0x2E, 0x12, 0x9F, 0x84, 0x25, 0xD2, 0x18},
    ...
    };


    No need to hack the linker script in any shape or form.

    No need to write your own memcpy routine, checkout memcpy_p2d16 (libraries guide or read libpic30.h, which ever you prefer). There are also strcpy versions of these functions.

    (Or use the __prog__ or __psv__ qualifers instead of const - as appropriate - and no need to copy the strings first).

    Regards
    Calum
    #6
    TLHansEEn
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2008/05/16 08:32:22
    • Location: 0
    • Status: offline
    Re: RE: PSV section `.const` exceeds 32K 2010/08/26 10:11:52 (permalink)
    0
    I am getting exactly the same error, but I do not have any large arrays of const data.  There are lots of printf() statements in the code and I suspect the compiler puts them in the .const section.  Does anyone have a good fix for this?
    #7
    cawilkie
    Administrator
    • Total Posts : 1955
    • Reward points : 0
    • Joined: 2003/11/07 12:49:11
    • Status: offline
    Re: RE: PSV section `.const` exceeds 32K 2010/08/30 10:41:05 (permalink)
    0
    Strings are const data, I am afraid.

    The C libraries only handle one page of PSV data at present, which is not ideal for large amounts of printf() functions.

    I have an idea for a work-around but will need some time to verify it.

    Regards
    Calum
    #8
    Jump to:
    © 2017 APG vNext Commercial Version 4.5