Quick start guide for MicroPython on FRDM-MCXN947 board

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Quick start guide for MicroPython on FRDM-MCXN947 board

jana_t
NXP Employee
NXP Employee
3 0 1,569

Introduction 

 

FRDM-MCXN947 are compact, scalable development boards designed for rapid prototyping of MCX N94 MCUs. The board has several features built in and can also be easily expanded with off the shelf add-on boards from NXP and our ecosystem partner, making it a great platform for prototyping with MicroPython.

This document guides you through the initial steps of deploying and using MicroPython on this board. For more information on the FRDM-MCXN947 board, visit the FRDM Development Board for MCX N94/N54 MCUs web page. For additional information on MicroPython, visit the MicroPython web page.

FRDM-MCXN947 block diagram:

FRDM-MCXN947-BD.png

 

MicroPython firmware download 

The FRDM-MCXN947 has an onboard MCU-LINK debug probe. Used alongside the LinkServer utility, it can be used to upload MicroPython firmware to the board. 

To run MicroPython applications on the board you need to first download the MicroPython interpreter application into the board. The MicroPython firmware will be available on MicroPython download page soon, but for now you can use the early build firmware.bin attached to this article.

Using a simple LinkServer command line operation we can flash the firmware image onto the board. To do this, open the command line at the LinkServer location (C:\Path\to\linkserver\folder) and run the command to flash the image:

 

 

LinkServer flash MCXN947:FRDM-MCXN947 load C:\Path\to\firmware\firmware.bin --addr 0

 

 

For the LinkServer flash command, two parameters are required - Device and Board. In our case, the device is named MCXN947 and the board is FRDM-MCXN947.

To display the list of supported devices, use the command:

 

 

LinkServer devices

 

 

To filter through the list, use the command with the filter attribute:

 

 

LinkServer devices --filter MC

 

 

jana_t_1-1706793319858.png

If you dont see the FRDM-MCXN947 device on the list, update your LinkServer installation.

If the flashing operation fails, try performing a mass erase operation on the flash first, then repeat the programming operation:

LinkServer.exe flash MCXN947:FRDM-MCXN947 erase 
LinkServer flash MCXN947:FRDM-MCXN947 load C:\Path\to\firmware\firmware.bin --addr 0

Talking to the MicroPython App

Once the image is flashed, MicroPython becomes available on the device. You can connect to the device using any serial terminal, such as the PuTTY app.

In the device manager, let's identify the port number.

jana_t_2-1706793397447.png

In the PuTTY app, set the connection type to 'Serial', specify the correct number for the 'Serial Line', and set the speed to '115200'. After these configurations, you can click 'Open'.

jana_t_3-1706793416848.png

The Putty apps opens a connection the MicroPython on the board, and we can communicate with the board through REPL.

This is the time to get some information or try some commands to communicate with the board. You can now write MicroPython code into the serial terminal:

  • help(‘modules’) – writes out all modules that are on board and ready for use 
  • import math – imports module math for more difficult math operations  
  • print(math.sqrt(5)) – square root of 5 

jana_t_4-1706793525257.png

Developing using Visual Studio Code

There are many IDEs available for MicroPython. You can use Visual Studio Code with the RT-Thread extension to develop with MicroPython. Inside VS Code you can find the RT-thread Micropython extension and install it. This extension supports convenient connection mode (serial port, network, USB), REPL interactive environment. You dont want to have to type your application in each time to use it, and the extension provides not only language-aware editing, but also provides the ability to download your application.

jana_t_5-1706793580952.png

If you want to use the MicroPython autocompletion feature, you need to have at least python 3 installed and VS code python extension. Close and reopen VS Code after installing to ensure all the changes to project in the environment are complete.  

jana_t_6-1706793613155.png

In the left corner new tools will appear in the navigation. First, we must create a MicroPython project within which all subsequent operations should run. We click on the rectangle icon with plus in it, then a prompt will open in the upper part of the screen.  

jana_t_7-1706793638649.png

We want to create a new MicroPython project and a blank one.  

jana_t_8-1706793650493.png

After that we are asked to name the project and fill in a path where the project is supposed to be saved.   

jana_t_9-1706793668586.png

In the lower left corner, select the plug button to connect to the device. We already have the device number from the Device Manager. Ensure that no other app is connected to the device (such as Putty from what we were doing earlier).

jana_t_11-1706793721763.png

Make sure your VS Code terminal is PowerShell. A new prompt will appear with list of available devicesChoose the COM port for your board. Now that you are connected a terminal will open. 

a1.png

Now you can right click on the .py file to send it to the device, the result will be printed in the terminal. 

jana_t_12-1706794170152.png

Now to write your first program!

Create a new file in the workspace.

Below there is some demo code for making the RGB LED blink; copy the code from bellow and paste into the new file, right click, and upload.

 

 

import machine 
import utime 

red_led = machine.Pin("P0_10", machine.Pin.OUT ) 
blue_led = machine.Pin("P0_27", machine.Pin.OUT ) 
green_led = machine.Pin("P1_2", machine.Pin.OUT ) 
i = 0 

while True: 
    for i in range(8): 
        blue_led.value((i & ( 1 << 0 )) >> 0) 
        red_led.value((i & ( 1 << 2 )) >> 2) 
        green_led.value((i & ( 1 << 1 )) >> 1) 
        utime.sleep(1) 

 

 

More things to try...

For your inspiration, there are attached also MicroPython scripts for PWM modulation, RGB led (led_pwm.py) and temperature reading from the onboard sensor (p3t1755.py).

Have fun, and let us know what you think!

Tags (2)