Hi @HS4 ,
There are few issues with your script.
1. You have to erase the flash memory before writing, otherwise you get the "Memory cumulative error"
2. You have to call the mboot.reset() with reopen set to False. Because when you reset the chip with the application in the memory, it boots the application.
I would also suggest using the context manager ("with" statement) to operate the McuBoot. It takes care of closing the device.
I have verified it with the MCXN947 FRDM board with led_blinky application.
from spsdk.mboot.interfaces.usb import MbootUSBInterface
from spsdk.mboot.mcuboot import McuBoot
def send_firmware_to_device(data: bytes):
interfaces = MbootUSBInterface.scan()
if not interfaces:
exit(1)
# Assuming the first device is my target
print("device", interfaces[0])
try:
address = 0
# Use the with statement for McuBoot
with McuBoot(interfaces[0]) as mboot:
mboot.flash_erase_all()
response = mboot.write_memory(address, data)
if response:
print("Firmware loaded successfully.")
else:
print("Failed to load firmware.")
mboot.reset(reopen=False)
except Exception as e:
print(f"An error occurred: {e}")
Marek Vitula