1
  • Currently I'm trying to load hello_world.bin to cortex m4 from u-boot in Google coral dev

What I've tried?

  • Bring up Coral dev target
  • SDK for i.MX8MQ
    • Download SDK from https://mcuxpresso.nxp.com/
    • For processor 'MIMX8MQ6xxxJZ' (auto selects Boards - EVK-MIMX8MQ)
    • Build hello_world.bin for Cortex M4 (TCM based). Uses UART2 in BOARD_InitBootPins
$ tar -xzf SDK_2.8.0_MIMX8MQ6xxxJZ.tar.gz
$ cd boards/evkmimx8mq/demo_apps/hello_world/armgcc
$ export ARMGCC_DIR=<path to>/gcc-arm-none-eabi-9-2020-q2-update/
$ export PATH=$PATH:<path to>/gcc-arm-none-eabi-9-2020-q2-update/bin
$ ./build_debug.sh 
$ ls debug/hello_world.bin 
  • Load hello_world.bin from u-boot
    • I've placed my bin in tftpboot location.
Hit any key to stop autoboot:  0 
u-boot=> tftp 0x7e0000 192.168.0.33:/tftpboot/coral/boot/hello_world.bin
Using ethernet@30be0000 device
TFTP from server 192.168.0.33; our IP address is 192.168.0.133
Filename '/tftpboot/coral/boot/hello_world.bin'.
Load address: 0x7e0000
Loading: ####
         2.3 MiB/s
done
Bytes transferred = 16700 (413c hex)
u-boot=> bootaux 0x7e0000
## Starting auxiliary core at 0x007E0000 ...
  • But I'm not able to see any output on the second terminal ttyUSB1
  • Expected output should be Hello World on the second terminal

What I've Observed

  • In Coral-Dev-Board-baseboard-schematic.pdf
    • According to Baseboard block diagram, UART2/3 is connected to MicroUSB via converter
      • But UART1(ttymxc0) is also available on micro USB
      • After kernel boot UART3(ttymxc0) is available on micro USB
    • But after kernel boot, I noticed UART3 to be available on second enumerated port
    • For example,
// On coral dev
root@wishful-zebra:~# ls -las /dev/ttymxc*
0 crw------- 1 mendel tty     207, 16 Aug 20 03:45 /dev/ttymxc0
0 crw-rw---- 1 root   dialout 207, 17 Aug 20 03:05 /dev/ttymxc1
0 crw-rw---- 1 root   dialout 207, 18 Aug 20 03:40 /dev/ttymxc2

root@wishful-zebra:~# stty -echo raw speed 115200 < /dev/ttymxc2
115200
root@wishful-zebra:~# echo "test" > /dev/ttymxc2 

// prints 'test' on /dev/ttyUSB1 host side
Welcome to minicom 2.7.1

OPTIONS: I18n 
Compiled on Aug 13 2017, 15:25:34.
Port /dev/ttyUSB1, 23:55:15

Press CTRL-A Z for help on special keys

test

Question

  • How to load firmware to Cortex M4 on Google Coral Dev?
  • Which i.MX SDK port to use for Google Coral Dev?
  • What are the UARTs available on the micro USB?
  • Which UART is used for Cortex M4 in Google Coral Dev
ChethanSuresh
  • 123
  • 1
  • 6

2 Answers2

2

Here are the instructions to boot the imx8m M4 and run the TFLite Micro Hello World (outputs a sine wave) on it: https://coral.googlesource.com/mcuxpresso_sdk/+/refs/heads/master/boards/evkmimx8mq/demo_apps/hello_world_tflite/.

you'll need to sync the project repo and rebuild linux-imx and uboot-imx.

Output from the M4 core will be visible on the second UART that enumerated when you connected your serial port via USB.

Manoj
  • 853
  • 1
  • 7
  • 28
  • Thank you. Above ref repository works. Except that copying bin to `/boot` directory and setting `m4enabled` did not work for me. Loading bin and `bootaux` works as mentioned in i.MX8 ref manuals. – ChethanSuresh Aug 23 '20 at 15:29
  • @ChehtanSuresh Did you also try the freeRTOS example given at https://coral.googlesource.com/mcuxpresso_sdk/+/refs/heads/master/boards/evkmimx8mq/rtos_examples/freertos_hello/ ? – Manoj Aug 27 '20 at 05:51
  • yes I tried the `multicore_examples/rpmsg_lite_str_echo_rtos` from the same repository. I hope it's fine to capture the steps below. – ChethanSuresh Sep 06 '20 at 10:40
1
  • As mentioned in the above accepted answer, we can use the mcuxpresso_sdk to build bin/elf for the Coral Dev CM4.
  • Additionally I'd to capture details to use the multicore_example,rtos_example from the Coral repo.
  • Also I'd like to add points on rpmsg/remoteproc support for imx8mq in linux kernel v4.14, the required patches adn dts support for imx8mq.

FreeRTOS SDK example - Boot CM4 from u-boot

  • SDK source for Coral Dev
  • hello_world_tflite example works without any changes.
    • Why? in main.c the BOARD_InitPins function is called which configures the UART pins for the CM4 console (in pin_mux.c)
  • This configuration is not applied for other examples. Therefore, I copied files board.h, board.c, clock_config.c, clock_config.h, pin_mux.c, pin_mux.h from hello_world_tflite to other example projects.
  • And BOARD_InitPins() must be called
  • Example for rtos_examples/freertos_hello
$ cd mcuxpresso_sdk/boards/evkmimx8mq/rtos_examples/freertos_hello/

// copy board files from hello_word_tflite example
$ cp -rf ../../demo_apps/hello_world_tflite/[pin_mux.* board.* clock_config.*] ./

// freertos_hello.c -> main -> BOARD_InitBootPins() -> BOARD_InitPins()
// Update pin_mux.c, BOARD_InitBootPins() call BOARD_InitPins()
void BOARD_InitBootPins(void)
  {
+   BOARD_InitPins();
  }

$ cd armgcc
//compile your project
// copy release/freertos_hello.bin to your SDcard/emmc/tftpboot location 
// I use tftp

u-boot=> tftp 0x7e0000 192.168.0.33:/tftpboot/coral/boot/freertos_hello.bin
u-boot=> bootaux 0x7e0000 

// Open other emulated console and verify output

Load CM4 elf from Linux Remoteproc

Linux kernel support

Linux DTS support

  • This is my current dts smip from arch/arm64/boot/dts/freescale/fsl-imx8mq-phanbell.dts. (Add at the top of dts file)
/ {
  reserved-memory {
    #address-cells = <2>;
    #size-cells = <2>;
    ranges;

    m4_reserved: m4@0x80000000 {
      no-map;
      reg = <0 0x80000000 0 0x1000000>;
    };  
  };  
  imx8mq-cm4 {
         compatible    = "fsl,imx8mq-cm4";
         memory-region = <&m4_reserved>;
         syscon        = <&src>;
         clocks        = <&clk IMX8MQ_CLK_M4_ROOT>;
     };  
};
&rpmsg{
  /*  
   * 64K for one rpmsg instance:
   * --0xb8000000~0xb800ffff: pingpong
   */
  vdev-nums = <1>;
  reg = <0x0 0xb8000000 0x0 0x10000>;
  status = "okay";
};

&uart2{
    status="disabled";
};

&uart3{
    status="disabled";
};

Linux RPMsg support

  • I enabled the imx rpmsg module examples IMX_RPMSG_TTY and IMX_RPMSG_PINGPONG
  • Also enabled RPMSG_CHAR
  • Also CM4 application side rpmsg readme can be found here

  • With above listed changes to linux kernel and CM4 sdk application examples, we can use the remoteproc to laod elf to CM4 and use pmsg_lite_str_echo_rtos example to communicate between APU and M4

Example CM4 elf load using remoteproc

  • Load ddr build hello_world.elf using remoteproc. The elf file is expected to be in /lib/firmware of your coral rootfs. Copy to respective location.
$ cd /path/to/mcuxpresso_sdk/...../hello_world/armgcc
$ ./build_ddr_release.sh 
$ sudo cp ddr_release/hello_world.elf (sdcard/emmc/nfs rootfs)/lib/firmware/

// load firmware using remoteproc
root@coraldev:~# echo hello_world_tflite.elf > /sys/class/remoteproc/remoteproc0/firmware 
root@coraldev:~# echo start > /sys/class/remoteproc/remoteproc0/state 


[  109.365150] remoteproc remoteproc0: powering up imx-rproc
[  109.372949] remoteproc remoteproc0: Booting fw image hello_world_tflite.elf, size 295228
[  109.381399] remoteproc remoteproc0: filesz 0x240 memsz 0x240
[  109.387196] remoteproc remoteproc0: da 0x80000000 mem 0x240
[  109.392959] remoteproc remoteproc0: filesz 0x1ee78 memsz 0x1ee78
[  109.399094] remoteproc remoteproc0: da 0x80000240 mem 0x1ee78
[  109.405366] remoteproc remoteproc0: filesz 0x6f4 memsz 0x6f4
[  109.411181] remoteproc remoteproc0: da 0x8001f0b8 mem 0x6f4
[  109.416945] remoteproc remoteproc0: filesz 0x0 memsz 0x3ba8
[  109.422638] remoteproc remoteproc0: da 0x8001f7c0 mem 0x3ba8
[  109.428501] remoteproc remoteproc0: remote processor imx-rproc is now up

  • But sometimes I'm not able to view M4 UART console
  • Loading any other example than hello_world* I get bad phdr da 0x80000000 mem 0x240. This I'm not sure how to resolve
    • Maybe dts mem reg should be updated
    • Maybe wait for official support for imx8mq remoteproc
  • But basic learning and experiment works

Linux side rpmsg char driver example

  • Compile multicore_examples/rpmsg_lite_str_echo_rtos/armgcc with update board init pins
  • Load the bin from u-boot
  • After linux boots, up insmod the imx_rpmsg_tty.ko (need to enabled in menuconfig)
// Load cm4 
u-boot=> tftp 0x7e0000 192.168.0.33:/tftpboot/coral/boot/rpmsg_lite_str_echo_rtos_imxcm4.bin
u-boot=> bootaux 0x7e0000 

// on linux side
root@coraldev:~# insmod /lib/modules/4.14.98+/kernel/drivers/rpmsg/imx_rpmsg_tty.ko 
root@coraldev:~# ls -las /dev/ttyRPMSG30 
     0 crw-rw----    1 root     dialout   235,   0 Jan  1 04:52 /dev/ttyRPMSG30

root@coraldev:~# echo "hello from linux" > /dev/ttyRPMSG30 

// on CM4 console, other emulated ttyUSB1 
RPMSG String Echo FreeRTOS RTOS API Demo...

Nameservice sent, ready for incoming messages...
Get Message From Master Side : "hello world!" [len : 12]
Get Message From Master Side : "hello from linux" [len : 16]
Get New Line From Master Side

  • I've tried to update here everything I tried about using CM4 in coral dev
  • I'm still facing issues with remoteproc.
  • I hope some of these information are helpful for anyone stumbling across this post
ChethanSuresh
  • 123
  • 1
  • 6