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:

Affordable and flexible platform to ease prototyping using a STM32L152RET6 microcontroller.

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 Daniel Blendea 06 Feb 2015

With 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...

}
posted by Wim Huiskamp 06 Feb 2015