Hot!PIC18F67k40 XC8 big struct problem

Page: 12 > Showing page 1 of 2
Author
C_Guy
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2007/06/02 11:53:42
  • Location: 0
  • Status: offline
2017/11/14 10:12:01 (permalink)
0

PIC18F67k40 XC8 big struct problem

Hi,
 
I need to place few const struct at 0x10000 and moore. However, the only way i can access those is by doing :
 
            USER *pp_user = &flash_parameters.user;
            USER *p_user = &pp_user[user];
            LIGHT *p_light = &p_user->light;
            SEQUENCE *pp_sequence= &p_light->basic_color;
            SEQUENCE *p_sequence = &pp_sequence[chromatherapy.sequence_index];
            //COLOR_POINT *pp_color_point = &p_sequence->color_point;
            COLOR_POINT *pp_color_point = (COLOR_POINT *)((u8 *)p_sequence+(u32)3);
            color_point = &pp_color_point[chromatherapy.color_index];

 
If I do :
 
color_point = &flash_parameters.user[user].light.basic_color[chromatherapy.sequence_index].color_point[chromatherapy.color_index];

 
The value is wrong. In fact by printing the addresses with printf("%08lX", ...), i notice that sometime the address get truncate to 16 bits. (i lost the 0x10000 msb). Please microchip help me
#1

20 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 14959
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/14 11:01:40 (permalink)
    +1 (1)
    const struct mystruct_type mystruct ={...} @ 0x10000
     
    your top code does not include the Struct so it is hard to see the Issue.  as far as the bottom access, you do know it is a low end 8 bit CPU?
    #2
    C_Guy
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2007/06/02 11:53:42
    • Location: 0
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/14 11:07:58 (permalink)
    0
    The struct is really complicated:
     
    #define SETPOINT_COUNT 3
    #define WAVE_POINT_COUNT 8
    #define WAVEFORM_COUNT 4
    #define OUTPUT_COUNT 6
    #define COLOR_POINT_COUNT 16
    #define SEQUENCE_COUNT 8
    #define RAINBOW_COUNT 2
    #define USER_COUNT 6
    #define PRESET_COUNT 3
    #define PRESET_NAME_LENGTH 10
    #define USER_NAME_LENGTH 15
     
    typedef struct
    {
    u16 sleeptime;
    u16 timer_gate_flag;
    }COMMUN;
    typedef struct
    {
    u8 point;
    u8 step_count;
    u8 step_time;
    }WAVEPOINT;
    typedef struct
    {
    u8 wavepoint_count;
    WAVEPOINT wave_point[WAVE_POINT_COUNT];
    }WAVEFORM;
    typedef struct
    {
    u8 start_speed;
    u8 min_speed;
    u8 max_speed;
    u8 user_min_speed;
    u8 user_max_speed;
    u8 setpoint[SETPOINT_COUNT];
    u8 mode;
    u16 sleeptime;
    u8 waveform_count;
    WAVEFORM waveform[WAVEFORM_COUNT];
    }OUTPUT;
    typedef struct
    {
    u8 red;
    u8 green;
    u8 blue;
    }COLOR_POINT;
    typedef struct
    {
    u16 bit_is_rainbow;
    u8 color_point_count;
    COLOR_POINT color_point[COLOR_POINT_COUNT];
    }SEQUENCE;
    typedef struct
    {
    u8 mode;
    u16 sleeptime;
    u8 rainbow_step_count[RAINBOW_COUNT];
    u16 rainbow_step_time[RAINBOW_COUNT];
    u16 rainbow_timebase[RAINBOW_COUNT];
    u8 sequence_count;
    SEQUENCE basic_color[SEQUENCE_COUNT];
    SEQUENCE rainbow[SEQUENCE_COUNT];
    }LIGHT;
    typedef struct
    {
    u8 status;
    u8 color_index;
    u8 sequence_index;
    u8 step_count;
    u16 step_time;
    u16 timebase;
    u8 mode;
    }CHROMATHERAPY_PRESET;
    typedef struct
    {
    u8 name[PRESET_NAME_LENGTH+1];
    u8 speed[OUTPUT_COUNT];
    u8 output_mode[OUTPUT_COUNT];
    CHROMATHERAPY_PRESET chromatherapy;
    }PRESET;
    typedef struct
    {
    COMMUN commun;
    OUTPUT output[OUTPUT_COUNT];
    LIGHT light;
    PRESET preset[PRESET_COUNT];
    u8 user_name[USER_NAME_LENGTH+1];
    u8 dummy[9304];
    }USER;
    typedef struct
    {
    USER user[USER_COUNT];
    u8 dummy[2];
    u16 CRC;
    }FLASH_PARAMETERS;
     
    const FLASH_PARAMETERS flash_parameters @0x10000
    #3
    DarioG
    leaving this planet
    • Total Posts : 53071
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/14 11:09:04 (permalink)
    0
    Smile

    Dario Greggio
    --
    how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

    #4
    jack@kksound
    code tags!
    • Total Posts : 2086
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/14 11:12:34 (permalink)
    +2 (2)
    Have you applied the +nvmreg errata fix that the K40 pics require? Otherwise it can/will give you incorrect results when reading data from FLASH.
    #5
    C_Guy
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2007/06/02 11:53:42
    • Location: 0
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/14 11:15:38 (permalink)
    0
    Yes I have +nvmreg errata set in my linker
    #6
    jtemples
    Super Member
    • Total Posts : 10278
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/14 12:24:35 (permalink)
    +3 (3)
    Why do they need to be at a particular address?  Does it work if you don't specify an address?
    #7
    C_Guy
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2007/06/02 11:53:42
    • Location: 0
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/14 13:13:25 (permalink)
    0
    right now it work at 0xC000, but i would like to keep 0x10000-0x1FFFF as user flash and below 0x10000 as program
    #8
    jtemples
    Super Member
    • Total Posts : 10278
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/14 13:16:47 (permalink)
    +1 (1)
    i would like to keep 0x10000-0x1FFFF as user flash and below 0x10000 as program

     
    Why?
    #9
    C_Guy
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2007/06/02 11:53:42
    • Location: 0
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/14 14:48:17 (permalink)
    0
    I may need at least 0x10000 of user flash && when I put it at 0x100 it doesnt work. 
    #10
    C_Guy
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2007/06/02 11:53:42
    • Location: 0
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/14 14:58:51 (permalink)
    0
    I just realize that 0x00000-0x0C000 is write protect by configuration bit. I'll give it another try
     
    #11
    jtemples
    Super Member
    • Total Posts : 10278
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/14 15:09:20 (permalink)
    +2 (2)
    Why are you putting it anywhere?  Let the linker put it in the most appropriate location.  Putting things at an absolute location makes the linker's job more difficult.
    #12
    C_Guy
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2007/06/02 11:53:42
    • Location: 0
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/15 06:19:03 (permalink)
    0
    I need to read write data to transfert it over wifi. Using struct is not an obligation, but that would simplify it
    #13
    jack@kksound
    code tags!
    • Total Posts : 2086
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/15 09:36:36 (permalink)
    +2 (2)
    C_Guy
    I need to read write data to transfert it over wifi. Using struct is not an obligation, but that would simplify it


    OK but that does not answer (at least I don't see it) the question of why to use absolute addresses for the structure(s) location?
    #14
    C_Guy
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2007/06/02 11:53:42
    • Location: 0
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/15 09:53:17 (permalink)
    0
    So I can write protect code section I guess. Do you mean if I don't use @ to locate my struct, there won't be bug ? I mean what if the compiler decide to place my struct at 0x10000 ?
    #15
    DarioG
    leaving this planet
    • Total Posts : 53071
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/15 09:56:07 (permalink)
    +2 (2)
    why THE HELL you wanna place it at fixed address????

    Dario Greggio
    --
    how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

    #16
    C_Guy
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2007/06/02 11:53:42
    • Location: 0
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/15 10:00:14 (permalink)
    +1 (1)
    I understand that is not necesary, but I get :
     
    :0: error: (1346) can't find 0x103C4 words for psect "mediumconst" in class "MEDIUMCONST" (largest unused contiguous range 0xF200)
     
    without the @
    #17
    DarioG
    leaving this planet
    • Total Posts : 53071
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/15 10:07:06 (permalink)
    +2 (2)
    Maybe it's just too big to fit into available memory: have you estimated how big is it?
    (not easy with all those defines...)

    Dario Greggio
    --
    how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

    #18
    C_Guy
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2007/06/02 11:53:42
    • Location: 0
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/15 10:10:12 (permalink)
    +1 (1)
    when I place it at 0x100, it ends at 0x1100 if I look at the lst file.
    #19
    C_Guy
    Starting Member
    • Total Posts : 32
    • Reward points : 0
    • Joined: 2007/06/02 11:53:42
    • Location: 0
    • Status: offline
    Re: PIC18F67k40 XC8 big struct problem 2017/11/15 11:36:07 (permalink)
    +1 (1)
    Ok, I found a solution. After some testing, I found out that the bug only apear when I have moore then 3 level of struct. Good news is 3 struct level is enought for this projet. Maybe if someone read the xc8 manual, we are going to see that we can't use more then 3 elvel
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2017 APG vNext Commercial Version 4.5