How to control sfr region

Hi

 

I would like to redefine sfr region.

Can I do it? 

If I can , I would like to know how to redefine sfr region.

 

Thanks.

  • Hello Jo Sangwoong,

    Could you give more details what do you exactly want to do?

    Best Regards,
    masj
  • In reply to masj:

    Hi masj

    Are there any precautions to change S7G2.h that SFR is defined on S7 basis?
    After modifying S7G2.h, Should I just change the attribute to read-only?

     

    and Can the SFR defined in the general user code?

  • In reply to Jo Sangwoong:

    Of course you could modify s7g2.h. But you should not do so. If you modify the standard header the SSP will run into problems.
    If you need your own definitions you should write your own header file.
    SFR definition in code is a bad idea. If multiple source files access to one SFR you add the definition to every source? How do you maintain it?
  • In reply to FrankL:

    Thanks Frankl

    I understand your answer.

    I'm sorry, but can you explain how to write own header file?
    I would like to guide that define is possible but not recommended for maintenance SSP issues.

    thanks.
  • In reply to Jo Sangwoong:

    Sorry, I think you don't understand the answer.
    The original header file has nearly 20k lines. Why would anyone want to rewrite this?

    The original header uses one structure for every peripheral module, and then it uses #define to define a pointer to these structures and place them at the peripheral module start addresses.
    typedef struct {...} R_MMPU_Type
    #define R_MMPU_BASE 0x40000000UL
    #define R_MMPU ((R_MMPU_Type *) #define

    Another way is to define own sections and place all sfr as "normal" variable definitions in these sections. You could do one section per peripheral module (which means > 100 sections) or 1 section. Variables can be assigned to these sections using the __attribute__ instruction.
    unsigned short MMPUCTL0 __attribute__ ((section ("MMPU")));
    unsigned char reserved_001[0x100] __attribute__ ((section ("MMPU")));
    unsigned short MMPUPTA __attribute__ ((section ("MMPU")));
    unsigned char reserved_002[0x0FC] __attribute__ ((section ("MMPU")));
    unsigned long MMPUCA0 __attribute__ ((section ("MMPU")));
    unsigned long MMPUSA0 __attribute__ ((section ("MMPU")));
    unsigned long MMPUEA0 __attribute__ ((section ("MMPU")));
  • In reply to FrankL:

    I am very sorry about this question.

    thank you very much.