Cannot resolve the error during compilation - "Error: Identifier "SIM" is undefined in "main.cpp""

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Cannot resolve the error during compilation - "Error: Identifier "SIM" is undefined in "main.cpp""

跳至解决方案
1,227 次查看
shobitsharma01
Contributor I

I just started learning about ARM Cortex-M Microcontrollers and I am following this book - "Embedded Systems Fundamentals with Arm Cortex M Based Microcontrollers: A Practical Approach (ISBN-13: 978-1911531036) by Alexander Dean".

I tried to compile the code given in the book to flash different colors on onboard RGB LED (file attached with name Main.cpp and also the header file I used MKL25Z4.h). I tried to create a .bin file using online Mbed IDE (ide.mbed.com) but I am getting the following error - "Error: Identifier "SIM" is undefined in "main.cpp", Line: 12, Col: 4" and I am not able to figure out why.

1 解答
1,005 次查看
benjamin_tait
Contributor II

You say, "I am not able to figure out why," but I think that you have - you even stated the reason yourself. SIM is not defined.

A quick look into the header file, reveals this is true: the "SIM" macro is never defined, anywhere.

You try to access the SCGC5 field of SIM. Since SIM isn't defined anywhere, lets look for SCGC5. A search of the header, reveals that SCGC5 is a field of the SIM_MemMap struct. Seems promising. So we keep digging.

Now we look for a macro or variable defined as a SIM_MemMap, or a pointer to one. Next, we find that this macro exists:

/* SIM - Peripheral instance base addresses */
/** Peripheral SIM base pointer */
#define SIM_BASE_PTR ((SIM_MemMapPtr)0x40047000u)

Ta-dah! We have found the missing macro. Substituting "SIM_BASE_PTR" for "SIM", seems like a reasonable place to start.

在原帖中查看解决方案

3 回复数
1,005 次查看
shobitsharma01
Contributor I

Thank You benjamin.tait@perkinelmer.com‌ & nxf54944‌ for your replies. I added _BASE_PTR  to SIM, PORTB, PTB etc in the code and everything works. I will also try the SDK builder.

Thank You for your quick replies :smileyhappy:

0 项奖励
1,005 次查看
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello Shobit Sharma

Another solution is download the board sdk Welcome | MCUXpresso SDK Builder .

You can replace your header for the included on the sdk folder. This allow you to call the SIM macro.

The sdk header is in the following direction: SDK_2.2.0_FRDM-KL25Z -> devices -> MKL25Z4

Let me know if this helps

Best regards,

Omar

---------------------------------------------------------------------------------------------------------------------------

Note:

- If this post answers your question, please click the "Mark Correct" button. Thank you!

----------------------------------------------------------------------------------------------------------------------------

1,006 次查看
benjamin_tait
Contributor II

You say, "I am not able to figure out why," but I think that you have - you even stated the reason yourself. SIM is not defined.

A quick look into the header file, reveals this is true: the "SIM" macro is never defined, anywhere.

You try to access the SCGC5 field of SIM. Since SIM isn't defined anywhere, lets look for SCGC5. A search of the header, reveals that SCGC5 is a field of the SIM_MemMap struct. Seems promising. So we keep digging.

Now we look for a macro or variable defined as a SIM_MemMap, or a pointer to one. Next, we find that this macro exists:

/* SIM - Peripheral instance base addresses */
/** Peripheral SIM base pointer */
#define SIM_BASE_PTR ((SIM_MemMapPtr)0x40047000u)

Ta-dah! We have found the missing macro. Substituting "SIM_BASE_PTR" for "SIM", seems like a reasonable place to start.