Download firmware to FRDM-MCXN947

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Download firmware to FRDM-MCXN947

2,846件の閲覧回数
HS4
Contributor I

I have FRDM-MCXN947, I am able to download the firmware on the board by doing these steps:

Connect USB cable to HS-USB port (J11)

Press and hold the ISP button (SW3)

Press and release Reset Button (SW1)

Release ISP Button (SW3) and using blhost.exe to download the firmware.

 

Now, I dont want to do the above manual steps and want it using python script.

How to set device in ISP mode using script ?

Can we use McuBoot from Mboot Api to erase and write memory instead of blhost

 

I checked https://community.nxp.com/t5/LPC-Microcontrollers/Flashing-Erasing-boards-using-SPSDK-integrated-wit... but it also says to use blhost

ラベル(1)
0 件の賞賛
返信
6 返答(返信)

2,821件の閲覧回数
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @HS4 

If you do not want to use the ISP pin, you can consider using the runBootloader API to enter ISP mode based on the designated ISP interface mode. 

Alice_Yang_0-1730196769476.png

If you also do not want to use blhost and prefer to write your own script, I'm sorry,  I don't know how to use Python scripts for this purpose. But you can refer to the "14 In-System Programming" section of the Reference Manual (RM) for development.

 

BR

Alice

 

 

 

0 件の賞賛
返信

2,817件の閲覧回数
HS4
Contributor I

No, I didnt mean writing my own script in instead of blhost , I wanted to know can we use mboot api MBoot Module API — SPSDK documentation . The interfaces present in McuBoot class can be used to flash erase (https://spsdk.readthedocs.io/en/latest/api/mboot.html#spsdk.mboot.mcuboot.McuBoot.flash_erase_all )or write (https://spsdk.readthedocs.io/en/latest/api/mboot.html#spsdk.mboot.mcuboot.McuBoot.load_image ) . 

0 件の賞賛
返信

2,785件の閲覧回数
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @HS4 

The MBoot Module API implements communication with the MCU Bootloader, not the BOOT ROM in the MCUXN947. The MCU Bootloader is a secondary bootloader provided in the SDK examples.

 

BR

Alice

0 件の賞賛
返信

2,727件の閲覧回数
HS4
Contributor I

Hi @Alice_Yang ,

I am doing this :

from spsdk.mboot.interfaces.usb import MbootUSBInterface
from spsdk.mboot.mcuboot import McuBoot

def send_firmware_to_device(data: bytes):
    devices = MbootUSBInterface.scan()
    if not devices:
        exit(1)

    # Assuming the first device is my target
    device = devices[0]
    print("device",device)
    try:
        device.open()
        address = 0x00000000
        # Create an instance of McuBoot
        mboot = McuBoot(device)

        response = mboot.write_memory(address, data)
        if response:
            print("Firmware loaded successfully.")
        else:
            print("Failed to load firmware.")

        mboot.reset()
    except Exception as e:
        print(f"An error occurred: {e}")
    finally:
        # Ensure the device is closed after operations
        device.close()      

    return 

 

But I get this error when I run the code : 

device identifier='usb', device=USB COMPOSITE DEVICE (0x1FC9, 0x014F)path=b'\\\\?\\hid#vid_1fc9&pid_014f#7&2cc9c3d2&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}' sn=''
RX: Mboot: Data aborted by sender
Failed to load firmware.
HID device 'b'\\\\?\\hid#vid_1fc9&pid_014f#7&2cc9c3d2&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}'' opening failed.

0 件の賞賛
返信

2,671件の閲覧回数
MarekVitula
NXP Employee
NXP Employee

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

2,684件の閲覧回数
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @HS4 

Could you please check whether your chip has entered ISP  mode?

Firstly, please confirm that your PC can communicate with the chip successfully in ISP mode.

 

BR

Alice

0 件の賞賛
返信