5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
group-onsemi
Date:
Wed Jan 25 20:34:15 2017 +0000
Revision:
0:098463de4c5d
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-onsemi 0:098463de4c5d 1 """
group-onsemi 0:098463de4c5d 2 mbed SDK
group-onsemi 0:098463de4c5d 3 Copyright (c) 2011-2013 ARM Limited
group-onsemi 0:098463de4c5d 4
group-onsemi 0:098463de4c5d 5 Licensed under the Apache License, Version 2.0 (the "License");
group-onsemi 0:098463de4c5d 6 you may not use this file except in compliance with the License.
group-onsemi 0:098463de4c5d 7 You may obtain a copy of the License at
group-onsemi 0:098463de4c5d 8
group-onsemi 0:098463de4c5d 9 http://www.apache.org/licenses/LICENSE-2.0
group-onsemi 0:098463de4c5d 10
group-onsemi 0:098463de4c5d 11 Unless required by applicable law or agreed to in writing, software
group-onsemi 0:098463de4c5d 12 distributed under the License is distributed on an "AS IS" BASIS,
group-onsemi 0:098463de4c5d 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
group-onsemi 0:098463de4c5d 14 See the License for the specific language governing permissions and
group-onsemi 0:098463de4c5d 15 limitations under the License.
group-onsemi 0:098463de4c5d 16
group-onsemi 0:098463de4c5d 17
group-onsemi 0:098463de4c5d 18 http://www.nxp.com/documents/user_manual/UM10360.pdf
group-onsemi 0:098463de4c5d 19
group-onsemi 0:098463de4c5d 20 32.3.1.1 Criterion for Valid User Code
group-onsemi 0:098463de4c5d 21 The reserved Cortex-M3 exception vector location 7 (offset 0x1C in the vector table)
group-onsemi 0:098463de4c5d 22 should contain the 2's complement of the check-sum of table entries 0 through 6. This
group-onsemi 0:098463de4c5d 23 causes the checksum of the first 8 table entries to be 0. The boot loader code checksums
group-onsemi 0:098463de4c5d 24 the first 8 locations in sector 0 of the flash. If the result is 0, then execution control is
group-onsemi 0:098463de4c5d 25 transferred to the user code.
group-onsemi 0:098463de4c5d 26 """
group-onsemi 0:098463de4c5d 27 from struct import unpack, pack
group-onsemi 0:098463de4c5d 28
group-onsemi 0:098463de4c5d 29
group-onsemi 0:098463de4c5d 30 def patch(bin_path):
group-onsemi 0:098463de4c5d 31 with open(bin_path, 'r+b') as bin:
group-onsemi 0:098463de4c5d 32 # Read entries 0 through 6 (Little Endian 32bits words)
group-onsemi 0:098463de4c5d 33 vector = [unpack('<I', bin.read(4))[0] for _ in range(7)]
group-onsemi 0:098463de4c5d 34
group-onsemi 0:098463de4c5d 35 # location 7 (offset 0x1C in the vector table) should contain the 2's
group-onsemi 0:098463de4c5d 36 # complement of the check-sum of table entries 0 through 6
group-onsemi 0:098463de4c5d 37 bin.seek(0x1C)
group-onsemi 0:098463de4c5d 38 bin.write(pack('<I', (~sum(vector) + 1) & 0xFFFFFFFF))
group-onsemi 0:098463de4c5d 39
group-onsemi 0:098463de4c5d 40
group-onsemi 0:098463de4c5d 41 def is_patched(bin_path):
group-onsemi 0:098463de4c5d 42 with open(bin_path, 'rb') as bin:
group-onsemi 0:098463de4c5d 43 # The checksum of the first 8 table entries should be 0
group-onsemi 0:098463de4c5d 44 return (sum([unpack('<I', bin.read(4))[0] for _ in range(8)]) & 0xFFFFFFFF) == 0
group-onsemi 0:098463de4c5d 45
group-onsemi 0:098463de4c5d 46
group-onsemi 0:098463de4c5d 47 if __name__ == '__main__':
group-onsemi 0:098463de4c5d 48 bin_path = "C:/Users/emimon01/releases/emilmont/build/test/LPC1768/ARM/MBED_A1/basic.bin"
group-onsemi 0:098463de4c5d 49 patch(bin_path)
group-onsemi 0:098463de4c5d 50 assert is_patched(bin_path), "The file is not patched"