Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/board/rapid_iot.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 rapiod_iot.c |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * |
Pawel Zarembski |
0:01f31e923fe2 | 4 | * DAPLink Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 5 | * Copyright (c) 2018, ARM Limited, All Rights Reserved |
Pawel Zarembski |
0:01f31e923fe2 | 6 | * SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 7 | * |
Pawel Zarembski |
0:01f31e923fe2 | 8 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
Pawel Zarembski |
0:01f31e923fe2 | 9 | * not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 10 | * You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 11 | * |
Pawel Zarembski |
0:01f31e923fe2 | 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 13 | * |
Pawel Zarembski |
0:01f31e923fe2 | 14 | * Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 15 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 16 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 17 | * See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 18 | * limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 19 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 20 | |
Pawel Zarembski |
0:01f31e923fe2 | 21 | #include "swd_host.h" |
Pawel Zarembski |
0:01f31e923fe2 | 22 | #include "target_board.h" |
Pawel Zarembski |
0:01f31e923fe2 | 23 | #include "target_family.h" |
Pawel Zarembski |
0:01f31e923fe2 | 24 | |
Pawel Zarembski |
0:01f31e923fe2 | 25 | char *board_id_kw41z = "0234"; |
Pawel Zarembski |
0:01f31e923fe2 | 26 | |
Pawel Zarembski |
0:01f31e923fe2 | 27 | #define MDM_STATUS 0x01000000 |
Pawel Zarembski |
0:01f31e923fe2 | 28 | #define MDM_CTRL 0x01000004 |
Pawel Zarembski |
0:01f31e923fe2 | 29 | #define MDM_IDR 0x010000fc |
Pawel Zarembski |
0:01f31e923fe2 | 30 | #define MDM_ID_K64 0x001c0000 // K64 |
Pawel Zarembski |
0:01f31e923fe2 | 31 | #define MDM_ID_KW4 0x001c0020 // KW4 |
Pawel Zarembski |
0:01f31e923fe2 | 32 | |
Pawel Zarembski |
0:01f31e923fe2 | 33 | /* Kinetis series ID */ |
Pawel Zarembski |
0:01f31e923fe2 | 34 | #define K_SERIES 0 |
Pawel Zarembski |
0:01f31e923fe2 | 35 | #define KW_SERIES 5 |
Pawel Zarembski |
0:01f31e923fe2 | 36 | |
Pawel Zarembski |
0:01f31e923fe2 | 37 | /* KW4 subfamily defines */ |
Pawel Zarembski |
0:01f31e923fe2 | 38 | #define KW40 0 |
Pawel Zarembski |
0:01f31e923fe2 | 39 | #define KW41 1 |
Pawel Zarembski |
0:01f31e923fe2 | 40 | |
Pawel Zarembski |
0:01f31e923fe2 | 41 | |
Pawel Zarembski |
0:01f31e923fe2 | 42 | static void prerun_board_config(void); |
Pawel Zarembski |
0:01f31e923fe2 | 43 | |
Pawel Zarembski |
0:01f31e923fe2 | 44 | |
Pawel Zarembski |
0:01f31e923fe2 | 45 | const board_info_t g_board_info = { |
Pawel Zarembski |
0:01f31e923fe2 | 46 | .info_version = kBoardInfoVersion, |
Pawel Zarembski |
0:01f31e923fe2 | 47 | .board_id = "0228", |
Pawel Zarembski |
0:01f31e923fe2 | 48 | .family_id = kNXP_RapidIot_FamilyID, |
Pawel Zarembski |
0:01f31e923fe2 | 49 | .flags = kEnablePageErase, |
Pawel Zarembski |
0:01f31e923fe2 | 50 | .daplink_url_name = "PRODINFOHTM", |
Pawel Zarembski |
0:01f31e923fe2 | 51 | .daplink_drive_name = "IOT-DAPLINK", |
Pawel Zarembski |
0:01f31e923fe2 | 52 | .daplink_target_url = "http://www.nxp.com/rapid-iot", |
Pawel Zarembski |
0:01f31e923fe2 | 53 | .target_cfg = &target_device, |
Pawel Zarembski |
0:01f31e923fe2 | 54 | .prerun_board_config = prerun_board_config, |
Pawel Zarembski |
0:01f31e923fe2 | 55 | }; |
Pawel Zarembski |
0:01f31e923fe2 | 56 | |
Pawel Zarembski |
0:01f31e923fe2 | 57 | static void prerun_board_config(void) |
Pawel Zarembski |
0:01f31e923fe2 | 58 | { |
Pawel Zarembski |
0:01f31e923fe2 | 59 | // SIM peripheral 0x40047000 |
Pawel Zarembski |
0:01f31e923fe2 | 60 | // address offset 0x 1024 |
Pawel Zarembski |
0:01f31e923fe2 | 61 | uint32_t SDID = 0x40048024; |
Pawel Zarembski |
0:01f31e923fe2 | 62 | uint32_t sdid; |
Pawel Zarembski |
0:01f31e923fe2 | 63 | |
Pawel Zarembski |
0:01f31e923fe2 | 64 | // get a hold of the target |
Pawel Zarembski |
0:01f31e923fe2 | 65 | if (target_set_state(HALT) == 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 66 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 67 | * When the Kinetis flash is empty the reset line toggles. This causes failures |
Pawel Zarembski |
0:01f31e923fe2 | 68 | * when trying to halt the target. Use the reset halt method in this case. |
Pawel Zarembski |
0:01f31e923fe2 | 69 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 70 | target_set_state(RESET_PROGRAM); |
Pawel Zarembski |
0:01f31e923fe2 | 71 | } |
Pawel Zarembski |
0:01f31e923fe2 | 72 | |
Pawel Zarembski |
0:01f31e923fe2 | 73 | // Read the system identification register |
Pawel Zarembski |
0:01f31e923fe2 | 74 | swd_read_memory(SDID, (uint8_t *)&sdid, 4); |
Pawel Zarembski |
0:01f31e923fe2 | 75 | |
Pawel Zarembski |
0:01f31e923fe2 | 76 | // Set the target flash algorithm |
Pawel Zarembski |
0:01f31e923fe2 | 77 | if (((sdid >> 20) & 0xF) == KW_SERIES) { |
Pawel Zarembski |
0:01f31e923fe2 | 78 | //mdm_id = MDM_ID_KW4; |
Pawel Zarembski |
0:01f31e923fe2 | 79 | |
Pawel Zarembski |
0:01f31e923fe2 | 80 | if (((sdid >> 24) & 0x3) == KW40) { |
Pawel Zarembski |
0:01f31e923fe2 | 81 | // Program to the KW40 flash |
Pawel Zarembski |
0:01f31e923fe2 | 82 | extern target_cfg_t target_device_kw40; |
Pawel Zarembski |
0:01f31e923fe2 | 83 | target_device = target_device_kw40; |
Pawel Zarembski |
0:01f31e923fe2 | 84 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 85 | // Program to the KW41 flash |
Pawel Zarembski |
0:01f31e923fe2 | 86 | extern target_cfg_t target_device_kw41; |
Pawel Zarembski |
0:01f31e923fe2 | 87 | target_device = target_device_kw41; |
Pawel Zarembski |
0:01f31e923fe2 | 88 | target_device.rt_board_id = board_id_kw41z; |
Pawel Zarembski |
0:01f31e923fe2 | 89 | } |
Pawel Zarembski |
0:01f31e923fe2 | 90 | } |
Pawel Zarembski |
0:01f31e923fe2 | 91 | |
Pawel Zarembski |
0:01f31e923fe2 | 92 | // Let the target run |
Pawel Zarembski |
0:01f31e923fe2 | 93 | target_set_state(RUN); |
Pawel Zarembski |
0:01f31e923fe2 | 94 | } |