1.bootloader 相当于极简化的uboot
2.app
明确升级文件的crc校验和传输次数,简单的升级结构
import serial, time
import ctypes
class IAP_H(ctypes.Structure):
_pack_ = 1
_fields_ = [
("magic", ctypes.c_uint32),
("filename", ctypes.c_char * 16),
("size", ctypes.c_uint32),
("chunk_counts", ctypes.c_uint32),
("crc", ctypes.c_uint16),
]
def view_iap(buffer: bytearray) -> IAP_H:
if len(buffer) < ctypes.sizeof(IAP_H):
raise ValueError("")
return IAP_H.from_buffer(buffer)
hdr = IAP_H(0x11223344, b"app.bin", 123456, 10, 0xBEEF)
raw = bytes(bytearray(ctypes.string_at(ctypes.addressof(hdr), ctypes.sizeof(hdr))))
ser = serial.Serial("COM3", 115200, bytesize=8, parity="N", stopbits=1, timeout=0.1)
count = 1
while True:
time.sleep(0.1)
if count == 1:
ser.write(raw)
count = 0
time.sleep(0.2)
print(ser.readline()
我是用的时固定的字节数中断传输,命令阶段固定30字,传输阶段跳到1K,在每个chunk 加入灯闪