• AVR Freaks

Hot!How to get processor name into source code?

Author
BillP
Super Member
  • Total Posts : 414
  • Reward points : 0
  • Joined: 2014/09/28 07:53:35
  • Location: CA
  • Status: offline
2020/06/17 10:33:37 (permalink)
0

How to get processor name into source code?

Is there a #define or function call to get the processor name (i.e. PIC32MZ or ATSAM) for use in my source code?  I thought I had seen something like this in the past, but my searches cannot find it.  Anybody know?
#1

9 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 18854
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: How to get processor name into source code? 2020/06/17 11:27:26 (permalink)
    0
    There will be an Enum for it an usually a -d ( #define) on the Command line.
    Not sure if they are Printable.
    #2
    KTrenholm
    Super Member
    • Total Posts : 787
    • Reward points : 0
    • Joined: 2012/08/08 14:04:23
    • Location: Connecticut, USA
    • Status: offline
    Re: How to get processor name into source code? 2020/06/17 12:28:24 (permalink)
    5 (2)
    The device headers for PIC32 devices look to have something like:

    #ifndef __32MX150F128C
        #define __32MX150F128C 1
    #endif

     
    xc.h also picks the device header to include based on a defined processor name with 2 underscores on each end, which I think is provided by the MPLAB X project if I remember correctly:
    __32MX150F128C__
    These can be helpful when targeting different devices and enabling/disabling code accordingly, but isn't printable.
     
    AFAIK there's no string for easy printing anywhere, so I usually have to do it manually with a #define in my main.h in order to have a nice printable string:

    #define    MCU_NAME    "PIC24FV16KM202"



    I know PICs have a DEVID register that can be read and printed, but it's just a number and the associated part name would need to be looked up based on the number.
     
    post edited by KTrenholm - 2020/06/17 12:51:34
    #3
    RISC
    Super Member
    • Total Posts : 5776
    • Reward points : 0
    • Status: offline
    Re: How to get processor name into source code? 2020/06/18 06:08:34 (permalink)
    0
    Hi,
    I checked MPLAB X manual and there are some macros. One of them (Device) represents the device for which it will be compiled.
    I am not sure but maybe there is a way to have this information "inserted into the project" through a pre-built script/command ?
    Look at section 4.10.2 of the c:\Program Files (x86)\Microchip\MPLABX\v5.40\docs\MPLAB_X_IDE_Users_Guide.pdf
    Regards 
    #4
    BillP
    Super Member
    • Total Posts : 414
    • Reward points : 0
    • Joined: 2014/09/28 07:53:35
    • Location: CA
    • Status: offline
    Re: How to get processor name into source code? 2020/06/18 17:56:04 (permalink)
    0
    Good responses.  I was not clear about where I needed this info.  What I want is a #define that allows me to conditionally compile a line of source code depending on the target CPU.  Specifically I would like to have this in my source code:
    #ifdef  __PIC32MZ__
      #define CDC_MAKE_BUFFER_DMA_READY  __attribute__((aligned(16))) __attribute__((coherent)) 
    #else
      #define CDC_MAKE_BUFFER_DMA_READY  __attribute__((aligned(16)))
    #endif
    #5
    ric
    Super Member
    • Total Posts : 28000
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: How to get processor name into source code? 2020/06/18 18:21:28 (permalink)
    5 (1)
    BillP
    ...
    Specifically I would like to have this in my source code:

    Have you tried it?
    Looking in some of the device specific header files, all the PIC32MZ devices have:
    #ifndef __PIC32MZ
    #  define __PIC32MZ 1
    #endif
    #ifndef __PIC32MZ__
    #  define __PIC32MZ__ 1
    #endif

    The PIC32MX have the same, and there's some PIC32WK as well.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    BillP
    Super Member
    • Total Posts : 414
    • Reward points : 0
    • Joined: 2014/09/28 07:53:35
    • Location: CA
    • Status: offline
    Re: How to get processor name into source code? 2020/06/19 08:00:47 (permalink)
    0
    @ric.  How stupid of me!  I did many searches of the project files and could not find any definition of __PIC32MZ (even though I thought I had seen the defines you showed somewhere).  Anyway, I never tried it as you suggested. 
     
    I added the following to a PIC32MZ project and it worked.
     
    #ifdef __PIC32MZ
      #define CDC_MAKE_BUFFER_DMA_READY  __attribute__((aligned(16))) __attribute__((coherent))
    #else
      #define CDC_MAKE_BUFFER_DMA_READY  __attribute__((aligned(16)))
    #endif


    I then tried it in an ATSAME70 project and that also worked. 
     
    The reason I did this is that XC32 v2.41 does not recognize the __attribute__((coherent)) so the compile fails.
     
    Problem solved for now.  Thanks
    #7
    mlp
    boots too small
    • Total Posts : 946
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: How to get processor name into source code? 2020/06/19 10:00:57 (permalink)
    0
    BillP
    I did many searches of the project files and could not find any definition of __PIC32MZ

    In case anyone is still confused: you will see no definition of this symbol or any of the part-number-specific ones because they are done by the compiler itself, when it is told it is to compile for a specific part. The system header files do, and your own files should if they care about it, check for the definedness of the relevant symbols.

    Mark (this opinion available for hire)
    #8
    ric
    Super Member
    • Total Posts : 28000
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: How to get processor name into source code? 2020/06/19 14:22:39 (permalink)
    4 (1)
    mark.pappin
    BillP
    I did many searches of the project files and could not find any definition of __PIC32MZ

    In case anyone is still confused: you will see no definition of this symbol or any of the part-number-specific ones because they are done by the compiler itself, when it is told it is to compile for a specific part. The system header files do, and your own files should if they care about it, check for the definedness of the relevant symbols.

    Mark, I just showed in post#6 that the part-number-specific header files DO in fact define __PIC32MZ and __PIC32MZ__
    I don't know if the compiler is already defining them as well.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    RISC
    Super Member
    • Total Posts : 5776
    • Reward points : 0
    • Status: offline
    Re: How to get processor name into source code? 2020/06/20 16:33:16 (permalink)
    0
    Hi,
    If you check each XC compiler manual and also MPLAB X manual  you'll find some macros which are defined by the compiler and also by MPLABX (environment defined macros). Each XC compiler has different ones e.g. XC16 __HAS_DMA__,....I remeber that MLA was using something like __DATE __TIME to include in the webpage the date time when it was compiled so that you can see the application version .
    So these macros are documented and very useful to do conditional compilation.
    Regards
     
    #10
    Jump to:
    © 2020 APG vNext Commercial Version 4.5