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 serial
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 cdc_throughput_main(thread_index, serial_port):
Pawel Zarembski 0:01f31e923fe2 40 global should_exit
Pawel Zarembski 0:01f31e923fe2 41 ser = None
Pawel Zarembski 0:01f31e923fe2 42 try:
Pawel Zarembski 0:01f31e923fe2 43 count = 0
Pawel Zarembski 0:01f31e923fe2 44 while not should_exit:
Pawel Zarembski 0:01f31e923fe2 45 ser = serial.Serial(serial_port) # open serial port
Pawel Zarembski 0:01f31e923fe2 46 ser.baudrate = 115200
Pawel Zarembski 0:01f31e923fe2 47 ser.write("this is test data")
Pawel Zarembski 0:01f31e923fe2 48 ser.baudrate = 9600
Pawel Zarembski 0:01f31e923fe2 49 ser.write("more test data")
Pawel Zarembski 0:01f31e923fe2 50 ser.close()
Pawel Zarembski 0:01f31e923fe2 51
Pawel Zarembski 0:01f31e923fe2 52 if count % 10 == 0:
Pawel Zarembski 0:01f31e923fe2 53 sync_print("Thread %i on loop %10i at %.6f - %s - port %s" %
Pawel Zarembski 0:01f31e923fe2 54 (thread_index, count, _get_time(),
Pawel Zarembski 0:01f31e923fe2 55 time.strftime("%H:%M:%S"), serial_port))
Pawel Zarembski 0:01f31e923fe2 56 count += 1
Pawel Zarembski 0:01f31e923fe2 57
Pawel Zarembski 0:01f31e923fe2 58 except:
Pawel Zarembski 0:01f31e923fe2 59 sync_print("Error on thread %i serial port %s" %
Pawel Zarembski 0:01f31e923fe2 60 (thread_index, serial_port))
Pawel Zarembski 0:01f31e923fe2 61 if ser is not None:
Pawel Zarembski 0:01f31e923fe2 62 ser.close()
Pawel Zarembski 0:01f31e923fe2 63 with exit_cond:
Pawel Zarembski 0:01f31e923fe2 64 should_exit = 1
Pawel Zarembski 0:01f31e923fe2 65 exit_cond.notify_all()
Pawel Zarembski 0:01f31e923fe2 66 raise
Pawel Zarembski 0:01f31e923fe2 67
Pawel Zarembski 0:01f31e923fe2 68
Pawel Zarembski 0:01f31e923fe2 69 def main():
Pawel Zarembski 0:01f31e923fe2 70 global should_exit
Pawel Zarembski 0:01f31e923fe2 71 lstools = mbed_lstools.create()
Pawel Zarembski 0:01f31e923fe2 72 mbed_list = lstools.list_mbeds()
Pawel Zarembski 0:01f31e923fe2 73 for thread_index, mbed in enumerate(mbed_list):
Pawel Zarembski 0:01f31e923fe2 74 cdc_thread = threading.Thread(target=cdc_throughput_main,
Pawel Zarembski 0:01f31e923fe2 75 args=(thread_index, mbed['serial_port']))
Pawel Zarembski 0:01f31e923fe2 76 cdc_thread.start()
Pawel Zarembski 0:01f31e923fe2 77
Pawel Zarembski 0:01f31e923fe2 78 try:
Pawel Zarembski 0:01f31e923fe2 79 with exit_cond:
Pawel Zarembski 0:01f31e923fe2 80 while not should_exit:
Pawel Zarembski 0:01f31e923fe2 81 exit_cond.wait(1)
Pawel Zarembski 0:01f31e923fe2 82 except KeyboardInterrupt:
Pawel Zarembski 0:01f31e923fe2 83 pass
Pawel Zarembski 0:01f31e923fe2 84 should_exit = True
Pawel Zarembski 0:01f31e923fe2 85
Pawel Zarembski 0:01f31e923fe2 86 sync_print("Exiting")
Pawel Zarembski 0:01f31e923fe2 87
Pawel Zarembski 0:01f31e923fe2 88
Pawel Zarembski 0:01f31e923fe2 89 if __name__ == "__main__":
Pawel Zarembski 0:01f31e923fe2 90 main()