This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Cannot add more struct to CMSDK_CM3.h

Dear everyone,

I want to add new struct type called I2C_TypeDef to the CMSDK_CM3.h
I followed the format, added right below the other CMSDK_TypeDef, but strangely the Keil IDE cannot recognize my new type.
Here is what I added


/*------------------- I2C ----------------------------------------------*/
/** @addtogroup I2C
  @{
*/
typedef struct
{

        __IO    uint32_t  PRER; // <h> I2C Prescaler Register   (R/W)    </h>
        __IO    uint32_t  CTR;  // <h> I2C Control Register     (R/W)    </h>
        __O     uint32_t  TXR;  // <h> I2C Transmit Register    (W)        </h>
        __I     uint32_t  RXR;  // <h> I2C Receive Register     (R)        </h>
        union {
                __O   uint32_t  CR;     // <h> I2C Command Register       (W)       </h>
                __I   uint32_t  SR;     // <h> I2C Status Register        (R)       </h>
        };

} I2C_TypeDef;

/*@}*/ /* end of group  I2C */

it is compiled but whenever I try to use the I2C_TypeDef in main, for example,
I2C_TypeDef mySensor;

It doesn't compile with an 'error: unknown type name 'I2C_TypeDef'
I am sure that I have included the CMSDK_CM3.h since the other CMSDK_xxx_typedef work just fine.
Also, when I declare the struct in the same file as the main. It recognizes the struct and now compiles.
Please, anybody know what is the problem? I am using Keil MDK5 by the way. Thank you for any help.

Parents
  • The warning appears before the other error
    warning : #1215-D: #warning directive: "My I2C TypeDef Included"
    on every files that includes the CMSDK_CM3.h.
    This means that it has been included correctly, right? And in the CMSDK_CM3.h there is already piece of guard like

    #ifndef CMSDK_CM3_H
    #define CMSDK_CM3_H
    
    // all the rest of the library
    
    #endif
    

    Isn't that should be enough to protect from recursive includes?

    Also, naming the union doesn't help

    It seems like the CMSDK_CM3.h not accepting any modification even though I can edit and save it normally. I've found out that not only struct, but simple #define addition also doesn't work.

    So, I tried to add all the I2C-related structs and defines in separate header file "i2c.h". The error changed to "invalid redeclaration of type name I2C_TypeDef"
    If I comment out the structs and defines in the CMSDK_CM3.h, it compiles and works with one error left

    error: #3092: anonymous unions are only supported in --gnu mode, or when enabled with #pragma_anon_unions
    

    I hope this information helps

Reply
  • The warning appears before the other error
    warning : #1215-D: #warning directive: "My I2C TypeDef Included"
    on every files that includes the CMSDK_CM3.h.
    This means that it has been included correctly, right? And in the CMSDK_CM3.h there is already piece of guard like

    #ifndef CMSDK_CM3_H
    #define CMSDK_CM3_H
    
    // all the rest of the library
    
    #endif
    

    Isn't that should be enough to protect from recursive includes?

    Also, naming the union doesn't help

    It seems like the CMSDK_CM3.h not accepting any modification even though I can edit and save it normally. I've found out that not only struct, but simple #define addition also doesn't work.

    So, I tried to add all the I2C-related structs and defines in separate header file "i2c.h". The error changed to "invalid redeclaration of type name I2C_TypeDef"
    If I comment out the structs and defines in the CMSDK_CM3.h, it compiles and works with one error left

    error: #3092: anonymous unions are only supported in --gnu mode, or when enabled with #pragma_anon_unions
    

    I hope this information helps

Children