牛卧堂MCU技术交流

标题: 芯片ID读取 [打印本页]

作者: newphj    时间: 2016-10-22 11:21
标题: 芯片ID读取
nuc442的芯片ID怎么读取的?

作者: harvardx    时间: 2016-10-28 10:20
打开M472 442的bsp;
NUC472_NUC442_BSP_CMSIS_V3.02.000\SampleCode\StdDriver\SYS_Control
里面有个例程SYS_Control

.

  1. int32_t main (void)
  2. {
  3.     uint32_t u32data;

  4.     /* Lock protected registers */
  5.     if(SYS->REGLCTL == 1) // In end of main function, program issued CPU reset and write-protection will be disabled.
  6.         SYS_LockReg();

  7.     /* Init System, IP clock and multi-function I/O */
  8.     SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register.

  9.     /* Init UART0 for printf */
  10.     UART0_Init();

  11.     printf("\n\nCPU @ %dHz\n", SystemCoreClock);

  12.     /*
  13.         This sample code will show some function about system manager controller and clock controller:
  14.         1. Read PDID
  15.         2. Get and clear reset source
  16.         3. Setting about BOD
  17.         4. Change system clock depended on different PLL settings
  18.         5. Output system clock from CKO pin, and the output frequency = system clock / 4
  19.     */

  20.     printf("+---------------------------------------+\n");
  21.     printf("|           System Driver Sample Code   |\n");
  22.     printf("+---------------------------------------+\n");

  23.     if (M32(FLAG_ADDR) == SIGNATURE) {
  24.         printf("  CPU Reset success!\n");
  25.         M32(FLAG_ADDR) = 0;
  26.         printf("  Press any key to continue ...\n");
  27.         getchar();
  28.     }

  29.     /*---------------------------------------------------------------------------------------------------------*/
  30.     /* Misc system function test                                                                               */
  31.     /*---------------------------------------------------------------------------------------------------------*/

  32.     /* Read Part Device ID */
  33.     printf("Product ID 0x%x\n", SYS->PDID);

  34.     /* Get reset source from last operation */
  35.     u32data = SYS->RSTSTS;
  36.     printf("Reset Source 0x%x\n", u32data);

  37.     /* Clear reset source */
  38.     SYS->RSTSTS = u32data;

  39.     /* Unlock protected registers for Brown-Out Detector settings */
  40.     SYS_UnlockReg();

  41.     /* Check if the write-protected registers are unlocked before BOD setting and CPU Reset */
  42.     if (SYS->REGLCTL != 0) {
  43.         printf("Protected Address is Unlocked\n");
  44.     }

  45.     /* Enable Brown-Out Detector and Low Voltage Reset function, and set Brown-Out Detector voltage 2.7V */
  46.     SYS->BODCTL =SYS_BODCTL_BODEN_Msk | SYS_BODCTL_BODVL_2_7V | SYS_BODCTL_LVREN_Msk;

  47.     /* Enable Brown-Out Interrupt function */
  48.     SYS->BODCTL &= ~SYS_BODCTL_BODRSTEN_Msk;
  49.     NVIC_EnableIRQ(BOD_IRQn);

  50.     /* Get system clock frequency and PLL clock frequency */
  51.     printf("  Change system clock to %d Hz and PLL clock is %d Hz\n", SystemCoreClock, CLK_GetPLLClockFreq());

  52.     /* Run PLL Test */
  53.     SYS_PLL_Test();

  54.     /* Write a signature work to SRAM to check if it is reset by software */
  55.     M32(FLAG_ADDR) = SIGNATURE;
  56.     printf("\n\n  >>> Reset CPU <<<\n");

  57.     /* Waiting for message send out */
  58.     UART_WAIT_TX_EMPTY(UART0);

  59.     /* Switch HCLK clock source to Internal 22MHz */
  60.     CLK->CLKSEL0 = CLK_CLKSEL0_HCLKSEL_HIRC;

  61.     /* Set PLL to Power down mode and HW will also clear PLLSTB bit in CLKSTATUS register */
  62.     CLK->PLLCTL |= CLK_PLLCTL_PD_Msk;

  63.     /* Reset CPU */
  64.     SYS_ResetCPU();
  65. }
复制代码


作者: harvardx    时间: 2016-10-28 10:21
看到了吗 很简单的一句话

    /* Read Part Device ID */
    printf("Product ID 0x%x\n", SYS->PDID);
作者: newphj    时间: 2016-11-16 18:34
万分感谢。。。
作者: newphj    时间: 2016-11-16 18:34
harvardx 发表于 2016-10-28 10:21
看到了吗 很简单的一句话

    /* Read Part Device ID */

万分感谢。。。




欢迎光临 牛卧堂MCU技术交流 (http://nuvoton-mcu.com/) Powered by Discuz! X3.2