闪烁 USB 恢复引导头
闪烁 USB 恢复引导头
引导头
脚本允许闪烁不同的引导头。此示例仅关注 USB 恢复头,因为其他头不常用。
- 消除引导加载程序在空闲模式下的额外功耗
- 恢复到简单的仅 USB 设置,移除高级引导加载程序功能
覆盖引导加载程序意味着设备不再支持高级引导加载程序功能。只有在了解其含义的情况下才执行此操作。可以通过重新闪烁引导加载程序来撤销此操作。
演示
Command Line
1~/depthai-python/examples$ python3 flash_boot_header.py USB_RECOVERY
2Found device with name: 1.1
3Successfully flashed boot header!设置
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py源代码
Python
PythonGitHub
1import sys
2from typing import Callable, Tuple
3from enum import Enum
4import depthai
5
6FLASH = depthai.DeviceBootloader.Memory.FLASH
7
8def main():
9 if len(sys.argv) < 2:
10 print(f"Usage: {sys.argv[0]} [GPIO_MODE/USB_RECOVERY/NORMAL/FAST] [params]")
11 print("\tOptions:")
12 print(f"\t\t{sys.argv[0]} GPIO_MODE gpioModeNum")
13 print(f"\t\t{sys.argv[0]} USB_RECOVERY")
14 print(f"\t\t{sys.argv[0]} NORMAL [frequency] [location] [dummyCycles] [offset]")
15 print(f"\t\t{sys.argv[0]} FAST [frequency] [location] [dummyCycles] [offset]")
16 return 0
17
18 mode = sys.argv[1].lower()
19 flash_func = None
20
21 if mode == "gpio_mode":
22 # gpio mode header
23 if len(sys.argv) < 3:
24 print(f"Usage: {sys.argv[0]} GPIO_MODE gpioModeNum")
25 return 0
26
27 gpio_mode = int(sys.argv[2])
28 def flash_gpio(bl: 'depthai.DeviceBootloader') -> Tuple[bool, str]:
29 return bl.flashGpioModeBootHeader(FLASH, gpio_mode)
30 flash_func = flash_gpio
31
32 elif mode == "usb_recovery":
33 # usb recovery header
34 def flash_usb(bl: 'depthai.DeviceBootloader') -> Tuple[bool, str]:
35 return bl.flashUsbRecoveryBootHeader(FLASH)
36 flash_func = flash_usb
37
38 elif mode in ("normal", "fast"):
39 if len(sys.argv) != 2 and len(sys.argv) != 3 and len(sys.argv) <= 3:
40 print(f"Usage: {sys.argv[0]} NORMAL/FAST [frequency] [location] [dummyCycles] [offset]")
41 print(f"Usage: {sys.argv[0]} NORMAL/FAST [frequency]")
42 return 0
43
44 offset = -1
45 location = -1
46 dummy_cycles = -1
47 frequency = -1
48
49 if len(sys.argv) > 3:
50 if len(sys.argv) >= 3:
51 offset = int(sys.argv[2])
52 if len(sys.argv) >= 4:
53 location = int(sys.argv[3])
54 if len(sys.argv) >= 5:
55 dummy_cycles = int(sys.argv[4])
56 if len(sys.argv) >= 6:
57 frequency = int(sys.argv[5])
58 elif len(sys.argv) == 3:
59 frequency = int(sys.argv[2])
60
61 if mode == "normal":
62 def flash_normal(bl: 'depthai.DeviceBootloader') -> Tuple[bool, str]:
63 return bl.flashBootHeader(FLASH, frequency, location, dummy_cycles, offset)
64 flash_func = flash_normal
65 elif mode == "fast":
66 def flash_fast(bl: 'depthai.DeviceBootloader') -> Tuple[bool, str]:
67 return bl.flashFastBootHeader(FLASH, frequency, location, dummy_cycles, offset)
68 flash_func = flash_fast
69
70 # Find device and flash specified boot header
71 success, info = depthai.DeviceBootloader.getFirstAvailableDevice()
72
73 if success:
74 print(f"Found device with name: {info.name}")
75 bl = depthai.DeviceBootloader(info)
76
77 # Flash the specified boot header
78 if flash_func:
79 success, error_msg = flash_func(bl)
80 if success:
81 print("Successfully flashed boot header!")
82 else:
83 print(f"Couldn't flash boot header: {error_msg}")
84 else:
85 print("Invalid boot option header specified")
86 else:
87 print("No devices found")
88
89 return 0
90
91if __name__ == "__main__":
92 main()需要帮助?
请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。