Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 10 months ago.
Board type/id
Is there a way to read the board type from code? For instance when running on L152RE it would report "L152RE" or something similar, or a code.
Question relating to:
2 Answers
9 years, 10 months ago.
Hi,
The only thing I have come across is you can check for the microcontroller. I can't remember exactly but it was something with ifdef target LPC1768. I haven't seen a list of what works.
9 years, 10 months ago.
You have to select the platform when you compile your projectcode. The code is always specific for a platform. The compiler can however figure out for which platform it is compiling and select different source code depending on the target:
#if defined (TARGET_LPC812) pc.printf("\r\nHello World from LPC812\r\n"); #endif #if defined (TARGET_LPC1768) pc.printf("\r\nHello World from LPC1768\r\n"); #endif
You can also use similar defines for the whole family (eg TARGET_NXP). Check the directory tree in mbed_src for the correct names.
I was hoping for a more generic code, something like device.getPlatform() or .getId() that would return TARGET_LPC812
posted by 06 Feb 2015With a bit of typing you can create that function yourself. Perhaps even develop a simple lib that you publish for all to use :)
#define TARGET_LPC812_ID 0 #define TARGET_LPC1768_ID 1 etc... int getPlatform() { #if defined (TARGET_LPC812) return TARGET_LPC812_ID; #endif #if defined (TARGET_LPC1768) return TARGET_LPC1768_ID; #endif etc... }