Skip to content

Latest commit

 

History

History
167 lines (108 loc) · 9.31 KB

getting_started_imx8mm.rst

File metadata and controls

167 lines (108 loc) · 9.31 KB

Getting started using i.MX 8M Mini Cortex-M / FreeRTOS / lwIP

In this tutorial, the P-Net Profinet device stack and its sample application runs on the i.MX 8M Mini EVK board. The i.MX 8M Mini EVK has four Cortex-A53 and one Cortex-M4. The current tutorial describes how to run the application on Cortex-M4. If you want to run the P-Net Profinet device stack on the Cortex-A53 cores, please follow the Linux tutorial.

A Windows PC will be used as a PLC (Programmable Logic Controller = IO controller) running Codesys soft PLC.

Additional information about this setup can be found in the NXP AN13933.

Hardware and software requirements

Necessary hardware:

  • 1 i.MX 8M Mini as IO-device + 1 32GB SD card
  • 1 Windows PC as IO-controller
  • 1 Ethernet cable
  • 1 LED and 1 push button for testing a digital-out and a digital-in port on the i.MX 8M Mini running as IO-device.

Sources:

The p-net/samples/pn_dev directory in the P-Net repository contains the source code for this example. It also contains a GSD file (written in GSDML), which tells the IO-controller how to communicate with the IO-device.

Those parts of the sample application that are dependent on whether you run Linux or an RTOS are located in p-net/src/ports.

Board specific files can be found in the p-net/osal/src/freertos/iMX8MM directory. The osal directory will be downloaded during build.

Prerequisites

Hardware setup

  1. Connect the LED and the push button to the i.MX 8M Mini, following the schematic on the left. For reference, the physical setup can be seen on the right side:

    illustrations/iMX8MMHwSetup.png
  2. Connect an ethernet cable between the i.MX 8M Mini EVK and the Windows PC.

  3. Connect the i.MX 8M Mini board to the Windows PC via USB cable between the DEBUG USB-UART connector and the PC USB connector.

    The ports will show with consecutive numbers in the Device Manager. Typically, the first port is allocated for Cortex-M4, while the second one is allocated for the Cortex-A53.

    Open both serial devices in your preferred serial terminal emulator (ex. PuTTY). Set the speed to 115200 bps, 8 data bits, 1 stop bit (115200, 8N1), and no parity.

Software setup

Windows PC setup

  1. Download and install the CODESYS Development System. Download the Windows-based software CODESYS Development System V3. For this demo, CODESYS Development System V3.5.19 is used.

  2. Implement the PLC Demo IO-Controller

    Note

    Keep in mind that the IP address of the PC's interface must be set manually in the same subnet with that of the i.MX 8M Mini. The IP address of the board is 192.168.11.3. If you want to replace this IP address, you can change the configuration in the osal/src/freertos/iMX8MM/Src/main.c file.

  3. In order to cross-compile the P-Net stack and its application in Windows, the WSL + Ubuntu 22.04 LTS must be configured and installed. Alternatively, a separate Ubuntu PC/virtual machine can be used.

  4. In Ubuntu, install the ARM embedded toolchain.

    mkdir ~/gcc_compiler
    cd ~/gcc_compiler
    wget -v https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2
    tar -xf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2
    

    Create a new system environment variable and name it ARMGCC_DIR. The value of this variable should point to the Arm GCC embedded toolchain installation path. For this example, the path is ~/gcc_compiler/gccarm-none-eabi-10.3-2021.10. Add the below line to ~/.bashrc file:

    export ARMGCC_DIR=~/gcc_compiler/gcc-arm-none-eabi-10.3-2021.10
    

    To reload bashrc settings, run:

    source ~/.bashrc
    

i.MX 8M Mini setup

  1. Download and flash the precompiled Real Time Edge Software image on the SD card.

    Note

    You can use any SD card writer tool, like Win32 Disk Imager or Balena Etcher to flash the precompiled image nxp-image-real-time-edge-imx8mm-lpddr4-evk.wic.

Build the application

  1. Clone the MCUXpresso SDK firmware

    MCUXpresso SDK is a comprehensive software enablement package designed to simplify and accelerate application development with Arm® Cortex®-M-based devices from NXP.

    You need to have both Git and West installed, then execute below commands to achieve the whole SDK delivery at revision MCUX_2.12.0 and place it in a folder named mcuxsdk:

    west init -m https://github.com/NXPmicro/mcux-sdk --mr MCUX_2.12.0 mcuxsdk
    cd mcuxsdk
    west update
    
  2. LwIP is not supported by default on the Cortex-M of i.MX 8M Mini EVK board. Some patches must be applied to add the lwIP support for i.MX 8M Mini.

    • Download the lwIP stack and place it into the mcuxsdk/middleware directory:

      cd ~/mcuxsdk/middleware
      git clone https://github.com/lwip-tcpip/lwip.git
      cd lwip
      git checkout 239918ccc173cb2c2a62f41a40fd893f57faf1d6
      
    • Download the imx8m_lwip_port.patch patch and apply it to the lwip directory. This fetches the port support for i.MX 8M (bare-metal lwIP and with FreeRTOS):

      cd ~/mcuxsdk/middleware/lwip
      wget https://raw.githubusercontent.com/nxp-imx-support/lwip_demo/master/imx8m_lwip_port.patch
      git apply --whitespace=nowarn imx8m_lwip_port.patch
      
  3. Download and compile the P-Net

    • Clone the source:

      cd
      git clone --recurse-submodules https://github.com/rtlabs-com/p-net.git
      
    • Configure the CPU, board and path to the cloned git repository:

      cd ~/p-net
      cmake -B build.imx8mm -DBOARD=iMX8MM \
              -DMCUXSDK_DIR=<path_to_mcuxsdk> \
              -DCMAKE_TOOLCHAIN_FILE="cmake/tools/toolchain/imx8mm.cmake" \
              -DCMAKE_BUILD_TYPE=ddr_release -DBUILD_TESTING=OFF -G "Unix Makefiles"
      cmake --build build.imx8mm
      
  4. When the build completes you can find the sample-app binary in build.imx8mm/pn_dev.bin.

Deploy and run the binary on the target

  1. Start the controller application.

  2. Copy the binary on the SD card

    Insert the SD card into the PC and copy the resulted binary pn_dev.bin on the first (FAT) partition of the SD card.

  3. Insert the SD card into the i.MX 8M Mini's slot, boot the board and stop the execution in U-Boot. To write and boot the binary from DDR, use the following commands:

    u-boot=> fatload mmc 1:1 0x80000000 pn_dev.bin
    u-boot=> dcache flush
    u-boot=> bootaux 0x80000000