Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/hic_hal/atmel/sam3u2c/read_uid.c@0:01f31e923fe2, 2020-04-07 (annotated)
- Committer:
- Pawel Zarembski
- Date:
- Tue Apr 07 12:55:42 2020 +0200
- Revision:
- 0:01f31e923fe2
hani: DAPLink with reset workaround
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:01f31e923fe2 | 1 | /** |
Pawel Zarembski |
0:01f31e923fe2 | 2 | * @file read_uid.c |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * @brief |
Pawel Zarembski |
0:01f31e923fe2 | 4 | * |
Pawel Zarembski |
0:01f31e923fe2 | 5 | * DAPLink Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved |
Pawel Zarembski |
0:01f31e923fe2 | 7 | * SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 8 | * |
Pawel Zarembski |
0:01f31e923fe2 | 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
Pawel Zarembski |
0:01f31e923fe2 | 10 | * not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 11 | * You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 12 | * |
Pawel Zarembski |
0:01f31e923fe2 | 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 14 | * |
Pawel Zarembski |
0:01f31e923fe2 | 15 | * Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 18 | * See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 19 | * limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 20 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 21 | |
Pawel Zarembski |
0:01f31e923fe2 | 22 | #include "stdbool.h" |
Pawel Zarembski |
0:01f31e923fe2 | 23 | |
Pawel Zarembski |
0:01f31e923fe2 | 24 | #include "read_uid.h" |
Pawel Zarembski |
0:01f31e923fe2 | 25 | #include "sam3u.h" |
Pawel Zarembski |
0:01f31e923fe2 | 26 | #include "cortex_m.h" |
Pawel Zarembski |
0:01f31e923fe2 | 27 | |
Pawel Zarembski |
0:01f31e923fe2 | 28 | bool unique_id_created = false; |
Pawel Zarembski |
0:01f31e923fe2 | 29 | static uint32_t unique_id[4]; |
Pawel Zarembski |
0:01f31e923fe2 | 30 | void read_unique_id(uint32_t *id) |
Pawel Zarembski |
0:01f31e923fe2 | 31 | { |
Pawel Zarembski |
0:01f31e923fe2 | 32 | if (!unique_id_created) { |
Pawel Zarembski |
0:01f31e923fe2 | 33 | create_unique_id(); |
Pawel Zarembski |
0:01f31e923fe2 | 34 | unique_id_created = true; |
Pawel Zarembski |
0:01f31e923fe2 | 35 | } |
Pawel Zarembski |
0:01f31e923fe2 | 36 | |
Pawel Zarembski |
0:01f31e923fe2 | 37 | id[0] = unique_id[0]; |
Pawel Zarembski |
0:01f31e923fe2 | 38 | id[1] = unique_id[1]; |
Pawel Zarembski |
0:01f31e923fe2 | 39 | id[2] = unique_id[2]; |
Pawel Zarembski |
0:01f31e923fe2 | 40 | id[3] = unique_id[3]; |
Pawel Zarembski |
0:01f31e923fe2 | 41 | } |
Pawel Zarembski |
0:01f31e923fe2 | 42 | |
Pawel Zarembski |
0:01f31e923fe2 | 43 | __attribute__((section("ram_func"))) |
Pawel Zarembski |
0:01f31e923fe2 | 44 | void create_unique_id(void) |
Pawel Zarembski |
0:01f31e923fe2 | 45 | { |
Pawel Zarembski |
0:01f31e923fe2 | 46 | cortex_int_state_t state; |
Pawel Zarembski |
0:01f31e923fe2 | 47 | state = cortex_int_get_and_disable(); |
Pawel Zarembski |
0:01f31e923fe2 | 48 | EFC0->EEFC_FMR |= (1UL << 16); |
Pawel Zarembski |
0:01f31e923fe2 | 49 | EFC0->EEFC_FCR = 0x5A00000E; |
Pawel Zarembski |
0:01f31e923fe2 | 50 | |
Pawel Zarembski |
0:01f31e923fe2 | 51 | /*Monitor FRDY*/ |
Pawel Zarembski |
0:01f31e923fe2 | 52 | while ((EFC0->EEFC_FSR & EEFC_FSR_FRDY) == EEFC_FSR_FRDY); |
Pawel Zarembski |
0:01f31e923fe2 | 53 | |
Pawel Zarembski |
0:01f31e923fe2 | 54 | unique_id[0] = *(uint32_t *)0x80000; |
Pawel Zarembski |
0:01f31e923fe2 | 55 | unique_id[1] = *(uint32_t *)0x80004; |
Pawel Zarembski |
0:01f31e923fe2 | 56 | unique_id[2] = *(uint32_t *)0x80008; |
Pawel Zarembski |
0:01f31e923fe2 | 57 | unique_id[3] = *(uint32_t *)0x8000C; |
Pawel Zarembski |
0:01f31e923fe2 | 58 | EFC0->EEFC_FCR = 0x5A00000F; |
Pawel Zarembski |
0:01f31e923fe2 | 59 | |
Pawel Zarembski |
0:01f31e923fe2 | 60 | /*Monitor FRDY*/ |
Pawel Zarembski |
0:01f31e923fe2 | 61 | while ((EFC0->EEFC_FSR & EEFC_FSR_FRDY) != EEFC_FSR_FRDY); |
Pawel Zarembski |
0:01f31e923fe2 | 62 | |
Pawel Zarembski |
0:01f31e923fe2 | 63 | EFC0->EEFC_FMR &= ~(1UL << 16); |
Pawel Zarembski |
0:01f31e923fe2 | 64 | cortex_int_restore(state); |
Pawel Zarembski |
0:01f31e923fe2 | 65 | } |