blob: 460eb9c7ad0567f657d656ae756d999bdc09c931 [file] [log] [blame]
Harald Welte8ee15db2016-03-20 16:00:39 +01001#include "chip.h"
2
3#define EFC_FCMD_STUI 0x0E
4#define EFC_FCMD_SPUI 0x0F
5
6__attribute__ ((section(".ramfunc")))
7void EEFC_ReadUniqueID(unsigned int *pdwUniqueID)
8{
9 unsigned int status;
10
11 /* Errata / Workaround: Set bit 16 of EEFC Flash Mode Register
12 * to 1 */
13 EFC->EEFC_FMR |= (1 << 16);
14
15 /* Send the Start Read unique Identifier command (STUI) by
16 * writing the Flash Command Register with the STUI command. */
17 EFC->EEFC_FCR = (0x5A << 24) | EFC_FCMD_STUI;
18
19 /* Wait for the FRDY bit to fall */
20 do {
21 status = EFC->EEFC_FSR;
22 } while ((status & EEFC_FSR_FRDY) == EEFC_FSR_FRDY);
23
24 /* The Unique Identifier is located in the first 128 bits of the
25 * Flash memory mapping. So, at the address 0x400000-0x400003.
26 * */
27 pdwUniqueID[0] = *(uint32_t *) IFLASH_ADDR;
28 pdwUniqueID[1] = *(uint32_t *) (IFLASH_ADDR + 4);
29 pdwUniqueID[2] = *(uint32_t *) (IFLASH_ADDR + 8);
30 pdwUniqueID[3] = *(uint32_t *) (IFLASH_ADDR + 12);
31
32 /* To stop the Unique Identifier mode, the user needs to send
33 * the Stop Read unique Identifier command (SPUI) by writing the
34 * Flash Command Register with the SPUI command. */
35 EFC->EEFC_FCR = (0x5A << 24) | EFC_FCMD_SPUI;
36
37 /* When the Stop read Unique Unique Identifier command (SPUI)
38 * has been performed, the FRDY bit in the Flash Programming
39 * Status Register (EEFC_FSR) rises. */
40 do {
41 status = EFC->EEFC_FSR;
42 } while ((status & EEFC_FSR_FRDY) != EEFC_FSR_FRDY);
43}