Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.

Upstream: https://github.com/ARMmbed/DAPLink

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?

UserRevisionLine numberNew contents of line
Pawel Zarembski 0:01f31e923fe2 1 #
Pawel Zarembski 0:01f31e923fe2 2 # DAPLink Interface Firmware
Pawel Zarembski 0:01f31e923fe2 3 # Copyright (c) 2016-2017, ARM Limited, All Rights Reserved
Pawel Zarembski 0:01f31e923fe2 4 # SPDX-License-Identifier: Apache-2.0
Pawel Zarembski 0:01f31e923fe2 5 #
Pawel Zarembski 0:01f31e923fe2 6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
Pawel Zarembski 0:01f31e923fe2 7 # not use this file except in compliance with the License.
Pawel Zarembski 0:01f31e923fe2 8 # You may obtain a copy of the License at
Pawel Zarembski 0:01f31e923fe2 9 #
Pawel Zarembski 0:01f31e923fe2 10 # http://www.apache.org/licenses/LICENSE-2.0
Pawel Zarembski 0:01f31e923fe2 11 #
Pawel Zarembski 0:01f31e923fe2 12 # Unless required by applicable law or agreed to in writing, software
Pawel Zarembski 0:01f31e923fe2 13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Pawel Zarembski 0:01f31e923fe2 14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Pawel Zarembski 0:01f31e923fe2 15 # See the License for the specific language governing permissions and
Pawel Zarembski 0:01f31e923fe2 16 # limitations under the License.
Pawel Zarembski 0:01f31e923fe2 17 #
Pawel Zarembski 0:01f31e923fe2 18
Pawel Zarembski 0:01f31e923fe2 19 import mbed_lstools
Pawel Zarembski 0:01f31e923fe2 20 import threading
Pawel Zarembski 0:01f31e923fe2 21 import time
Pawel Zarembski 0:01f31e923fe2 22 import pyocd
Pawel Zarembski 0:01f31e923fe2 23
Pawel Zarembski 0:01f31e923fe2 24 should_exit = False
Pawel Zarembski 0:01f31e923fe2 25 exit_cond = threading.Condition()
Pawel Zarembski 0:01f31e923fe2 26 print_mut = threading.RLock()
Pawel Zarembski 0:01f31e923fe2 27 global_start_time = time.time()
Pawel Zarembski 0:01f31e923fe2 28
Pawel Zarembski 0:01f31e923fe2 29
Pawel Zarembski 0:01f31e923fe2 30 def _get_time():
Pawel Zarembski 0:01f31e923fe2 31 return time.time() - global_start_time
Pawel Zarembski 0:01f31e923fe2 32
Pawel Zarembski 0:01f31e923fe2 33
Pawel Zarembski 0:01f31e923fe2 34 def sync_print(msg):
Pawel Zarembski 0:01f31e923fe2 35 with print_mut:
Pawel Zarembski 0:01f31e923fe2 36 print(msg)
Pawel Zarembski 0:01f31e923fe2 37
Pawel Zarembski 0:01f31e923fe2 38
Pawel Zarembski 0:01f31e923fe2 39 def hid_main(thread_index, board_id):
Pawel Zarembski 0:01f31e923fe2 40 global should_exit
Pawel Zarembski 0:01f31e923fe2 41 count = 0
Pawel Zarembski 0:01f31e923fe2 42 try:
Pawel Zarembski 0:01f31e923fe2 43 device = pyocd.probe.pydapaccess.DAPAccess.get_device(board_id)
Pawel Zarembski 0:01f31e923fe2 44 while not should_exit:
Pawel Zarembski 0:01f31e923fe2 45 device.open()
Pawel Zarembski 0:01f31e923fe2 46 info = device.vendor(0)
Pawel Zarembski 0:01f31e923fe2 47 info = str(bytearray(info[1:1 + info[0]]))
Pawel Zarembski 0:01f31e923fe2 48 assert info == board_id
Pawel Zarembski 0:01f31e923fe2 49 device.close()
Pawel Zarembski 0:01f31e923fe2 50 if count % 100 == 0:
Pawel Zarembski 0:01f31e923fe2 51 sync_print("Thread %i on loop %10i at %.6f - %s - board %s" %
Pawel Zarembski 0:01f31e923fe2 52 (thread_index, count, _get_time(),
Pawel Zarembski 0:01f31e923fe2 53 time.strftime("%H:%M:%S"), board_id))
Pawel Zarembski 0:01f31e923fe2 54 count += 1
Pawel Zarembski 0:01f31e923fe2 55
Pawel Zarembski 0:01f31e923fe2 56 except:
Pawel Zarembski 0:01f31e923fe2 57 sync_print("Thread %i exception board %s" % (thread_index, board_id))
Pawel Zarembski 0:01f31e923fe2 58 with exit_cond:
Pawel Zarembski 0:01f31e923fe2 59 should_exit = 1
Pawel Zarembski 0:01f31e923fe2 60 exit_cond.notify_all()
Pawel Zarembski 0:01f31e923fe2 61 raise
Pawel Zarembski 0:01f31e923fe2 62
Pawel Zarembski 0:01f31e923fe2 63
Pawel Zarembski 0:01f31e923fe2 64 def main():
Pawel Zarembski 0:01f31e923fe2 65 global should_exit
Pawel Zarembski 0:01f31e923fe2 66 lstools = mbed_lstools.create()
Pawel Zarembski 0:01f31e923fe2 67 mbed_list = lstools.list_mbeds()
Pawel Zarembski 0:01f31e923fe2 68 for thread_index, mbed in enumerate(mbed_list):
Pawel Zarembski 0:01f31e923fe2 69 msd_thread = threading.Thread(target=hid_main,
Pawel Zarembski 0:01f31e923fe2 70 args=(thread_index, mbed['target_id']))
Pawel Zarembski 0:01f31e923fe2 71 msd_thread.start()
Pawel Zarembski 0:01f31e923fe2 72
Pawel Zarembski 0:01f31e923fe2 73 try:
Pawel Zarembski 0:01f31e923fe2 74 with exit_cond:
Pawel Zarembski 0:01f31e923fe2 75 while not should_exit:
Pawel Zarembski 0:01f31e923fe2 76 exit_cond.wait(1)
Pawel Zarembski 0:01f31e923fe2 77 except KeyboardInterrupt:
Pawel Zarembski 0:01f31e923fe2 78 pass
Pawel Zarembski 0:01f31e923fe2 79 should_exit = True
Pawel Zarembski 0:01f31e923fe2 80
Pawel Zarembski 0:01f31e923fe2 81 sync_print("Exiting")
Pawel Zarembski 0:01f31e923fe2 82
Pawel Zarembski 0:01f31e923fe2 83
Pawel Zarembski 0:01f31e923fe2 84 if __name__ == "__main__":
Pawel Zarembski 0:01f31e923fe2 85 main()