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"Enabling 'allow erase' for device: {devIndex}")
26 url = f"/iOPEN/Data.UMI.Devices.Devices[{devIndex}].AllowErase"
27 ideCtrl.setOption(url, "True")
28
29 print(f"Erasing entire device with index {devIndex}...")
30 storageCtrl.erase(ic.IConnectUMI.wProgDevice)
31
32 print(f"Erasing first {int(eraseSize)} bytes of a device with index {devIndex}...")
33 addUrl = f"/iOPEN/Data.UMI.Devices.Devices[{devIndex}].DeviceAddress"
34 add = ideCtrl.getOptionInt(addUrl)
35 storageCtrl.erase(ic.IConnectUMI.wProgDevice, add, int(eraseSize))
36
37 print(f"Disabling 'allow erase' for device: {devIndex}")
38 ideCtrl.setOption(url, "False")
39
40
41if __name__ == "__main__":
42 test_erase()