Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
generate_config.py
00001 # 00002 # DAPLink Interface Firmware 00003 # Copyright (c) 2009-2016, ARM Limited, All Rights Reserved 00004 # SPDX-License-Identifier: Apache-2.0 00005 # 00006 # Licensed under the Apache License, Version 2.0 (the "License"); you may 00007 # not use this file except in compliance with the License. 00008 # You may obtain a copy of the License at 00009 # 00010 # http://www.apache.org/licenses/LICENSE-2.0 00011 # 00012 # Unless required by applicable law or agreed to in writing, software 00013 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00014 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 # See the License for the specific language governing permissions and 00016 # limitations under the License. 00017 # 00018 00019 import struct 00020 import argparse 00021 from intelhex import IntelHex 00022 00023 CFG_KEY = 0x6b766c64 00024 # Must stay in sync with the structure cfg_setting 00025 # in the header file config_settings.h: 00026 # 32 - key 00027 # 16 - offset_of_end 00028 # 8 - auto_rst 00029 # 8 - automation_allowed 00030 # 8 - overflow_detect 00031 # 0 - 'end' member omitted 00032 FORMAT = '<LHBBB' 00033 FORMAT_LENGTH = struct.calcsize(FORMAT) 00034 MINIMUM_ALIGN = 1 << 10 # 1k aligned 00035 00036 00037 def create_hex(filename, addr, auto_rst, automation_allowed, 00038 overflow_detect, pad_size): 00039 file_format = 'hex' 00040 intel_hex = IntelHex() 00041 intel_hex.puts(addr, struct.pack(FORMAT, CFG_KEY, FORMAT_LENGTH, auto_rst, 00042 automation_allowed, overflow_detect)) 00043 pad_addr = addr + FORMAT_LENGTH 00044 pad_byte_count = pad_size - (FORMAT_LENGTH % pad_size) 00045 pad_data = '\xFF' * pad_byte_count 00046 intel_hex.puts(pad_addr, pad_data) 00047 with open(filename, 'wb') as f: 00048 intel_hex.tofile(f, file_format) 00049 00050 00051 def str_to_int(val): 00052 return int(val, 0) 00053 00054 00055 POWERS_OF_TWO = [2**num for num in range(0, 32)] 00056 parser = argparse.ArgumentParser(description='Configuration Creator') 00057 parser.add_argument("--addr", type=str_to_int, required=True, help="Address of configuration data") 00058 parser.add_argument("--auto_rst", type=int, required=True, choices=[0, 1], help="Auto reset configuration value") 00059 parser.add_argument("--automation_allowed", type=int, required=True, choices=[0,1], help="Allow automation from filesystem interaction") 00060 parser.add_argument("--overflow_detect", type=int, required=True, choices=[0,1], help="Enable detection of UART overflow") 00061 parser.add_argument("--pad", type=int, default=16, choices=POWERS_OF_TWO, metavar="{1, 2, 4,...}", help="Byte aligned boundary to pad region to") 00062 parser.add_argument("--output_file", type=str, default='settings.hex', help="Name of output file") 00063 00064 00065 def main(): 00066 args = parser.parse_args() 00067 print "Output file %s" % args.output_file 00068 print "Config Offset 0x%x" % args.addr 00069 if args.addr % MINIMUM_ALIGN != 0: 00070 print "WARNING! Configuration is not on a 1K boundary" 00071 if args.addr % args.pad != 0: 00072 print "WARNING! Configuration is not aligned to pad size" 00073 print "Settings:" 00074 print " auto_rst: %i" % args.auto_rst 00075 print " automation_allowed: %i" % args.automation_allowed 00076 print " overflow_detect: %i" % args.overflow_detect 00077 print "" 00078 create_hex(args.output_file, args.addr, args.auto_rst, 00079 args.automation_allowed, args.overflow_detect, args.pad) 00080 00081 if __name__ == '__main__': 00082 main()
Generated on Tue Jul 12 2022 15:37:18 by
1.7.2