winIDEA SDK
test_storage_erase.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5import isystem.connect as ic
6
7
8winidea_id = ''
9
10
11def test_erase():
12 connMgr = ic.ConnectionMgr()
13 connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
14
15 ideCtrl = ic.CIDEController(connMgr)
16 devName = "ST STM32F4xxxG_1024KB"
17 #Erase size equals size on one flash sector for this specific example target "ST STM32F4xxxG_1024KB"
18 eraseSize = 0x4000
19 optCtrl = ic.COptionController(connMgr, "/iOPEN/Data.UMI.Devices.Devices")
20 devIndex = optCtrl.index_of("Name",devName)
21 print("Index of the item whose 'Name' attribute has value " + devName + f": {devIndex}")
22
23 storageCtrl = ic.CStorageDeviceFactory.makeDevice(connMgr, ic.EStorageDevice_EmbeddedFlashDevice, devIndex)
24
25 print(f"Erasing entire device with index {devIndex}...")
26 storageCtrl.erase(ic.IConnectUMI.wProgDevice)
27
28 print(f"Erasing first {int(eraseSize)} bytes of a device with index {devIndex}...")
29 addUrl = f"/iOPEN/Data.UMI.Devices.Devices[{devIndex}].DeviceAddress"
30 add = ideCtrl.getOptionInt(addUrl)
31 storageCtrl.erase(ic.IConnectUMI.wProgDevice, add, int(eraseSize))
32
33
34if __name__ == "__main__":
35 test_erase()