Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/board/hexiwear.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 hexiwear.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 | static void prerun_board_config(void); |
Pawel Zarembski |
0:01f31e923fe2 | 42 | |
Pawel Zarembski |
0:01f31e923fe2 | 43 | |
Pawel Zarembski |
0:01f31e923fe2 | 44 | const board_info_t g_board_info = { |
Pawel Zarembski |
0:01f31e923fe2 | 45 | .info_version = kBoardInfoVersion, |
Pawel Zarembski |
0:01f31e923fe2 | 46 | .board_id = "0214", |
Pawel Zarembski |
0:01f31e923fe2 | 47 | .family_id = kNXP_RapidIot_FamilyID, |
Pawel Zarembski |
0:01f31e923fe2 | 48 | .flags = kEnablePageErase, |
Pawel Zarembski |
0:01f31e923fe2 | 49 | .daplink_url_name = "PRODINFOHTM", |
Pawel Zarembski |
0:01f31e923fe2 | 50 | .daplink_drive_name = "HEX-DAPLINK", |
Pawel Zarembski |
0:01f31e923fe2 | 51 | .daplink_target_url = "http://www.hexiwear.com/", |
Pawel Zarembski |
0:01f31e923fe2 | 52 | .target_cfg = &target_device, |
Pawel Zarembski |
0:01f31e923fe2 | 53 | .prerun_board_config = prerun_board_config, |
Pawel Zarembski |
0:01f31e923fe2 | 54 | }; |
Pawel Zarembski |
0:01f31e923fe2 | 55 | |
Pawel Zarembski |
0:01f31e923fe2 | 56 | static void prerun_board_config(void) |
Pawel Zarembski |
0:01f31e923fe2 | 57 | { |
Pawel Zarembski |
0:01f31e923fe2 | 58 | // SIM peripheral 0x40047000 |
Pawel Zarembski |
0:01f31e923fe2 | 59 | // address offset 0x 1024 |
Pawel Zarembski |
0:01f31e923fe2 | 60 | uint32_t SDID = 0x40048024; |
Pawel Zarembski |
0:01f31e923fe2 | 61 | uint32_t sdid; |
Pawel Zarembski |
0:01f31e923fe2 | 62 | |
Pawel Zarembski |
0:01f31e923fe2 | 63 | // get a hold of the target |
Pawel Zarembski |
0:01f31e923fe2 | 64 | if (target_set_state(HALT) == 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 65 | /* |
Pawel Zarembski |
0:01f31e923fe2 | 66 | * When the Kinetis flash is empty the reset line toggles. This causes failures |
Pawel Zarembski |
0:01f31e923fe2 | 67 | * when trying to halt the target. Use the reset halt method in this case. |
Pawel Zarembski |
0:01f31e923fe2 | 68 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 69 | target_set_state(RESET_PROGRAM); |
Pawel Zarembski |
0:01f31e923fe2 | 70 | } |
Pawel Zarembski |
0:01f31e923fe2 | 71 | |
Pawel Zarembski |
0:01f31e923fe2 | 72 | // Read the system identification register |
Pawel Zarembski |
0:01f31e923fe2 | 73 | swd_read_memory(SDID, (uint8_t *)&sdid, 4); |
Pawel Zarembski |
0:01f31e923fe2 | 74 | |
Pawel Zarembski |
0:01f31e923fe2 | 75 | // Set the target flash algorithm |
Pawel Zarembski |
0:01f31e923fe2 | 76 | if (((sdid >> 20) & 0xF) == KW_SERIES) { |
Pawel Zarembski |
0:01f31e923fe2 | 77 | |
Pawel Zarembski |
0:01f31e923fe2 | 78 | if (((sdid >> 24) & 0x3) == KW40) { |
Pawel Zarembski |
0:01f31e923fe2 | 79 | // Program to the KW40 flash |
Pawel Zarembski |
0:01f31e923fe2 | 80 | extern target_cfg_t target_device_kw40; |
Pawel Zarembski |
0:01f31e923fe2 | 81 | target_device = target_device_kw40; |
Pawel Zarembski |
0:01f31e923fe2 | 82 | } else { |
Pawel Zarembski |
0:01f31e923fe2 | 83 | // Program to the KW41 flash |
Pawel Zarembski |
0:01f31e923fe2 | 84 | extern target_cfg_t target_device_kw41; |
Pawel Zarembski |
0:01f31e923fe2 | 85 | target_device = target_device_kw41; |
Pawel Zarembski |
0:01f31e923fe2 | 86 | target_device.rt_board_id = board_id_kw41z; |
Pawel Zarembski |
0:01f31e923fe2 | 87 | } |
Pawel Zarembski |
0:01f31e923fe2 | 88 | } |
Pawel Zarembski |
0:01f31e923fe2 | 89 | |
Pawel Zarembski |
0:01f31e923fe2 | 90 | // Let the target run |
Pawel Zarembski |
0:01f31e923fe2 | 91 | target_set_state(RUN); |
Pawel Zarembski |
0:01f31e923fe2 | 92 | } |