Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use MCU SDK in thud branch or most recent branch #75

Open
xlla opened this issue Nov 3, 2019 · 35 comments
Open

how to use MCU SDK in thud branch or most recent branch #75

xlla opened this issue Nov 3, 2019 · 35 comments

Comments

@xlla
Copy link

xlla commented Nov 3, 2019

in original firmware, we use tty channels and sysfs nodes to coummunicate with the MCU.
in thud branch, the /dev/ttymcuX is missing, sysfs node /sys/devices/platform/intel_mcu does not exist, only a shell script and a firmware exist
/etc/intel_mcu/mcu_fw_loader.sh
/lib/firmware/intel_mcu.bin

so how can develop a MCU application and upload/debug it ?

@htot
Copy link
Member

htot commented Nov 3, 2019

According to @andy-shev

The MCU is not supported right now until forward ported

@xlla
Copy link
Author

xlla commented Nov 4, 2019

alright.

@xlla xlla closed this as completed Nov 4, 2019
@andy-shev
Copy link
Contributor

andy-shev commented Nov 5, 2019

And for the record I'm not willing to enable it at all. It has a lot of problems, in particular with pin control since the original (Linux kernel) solution is not compatible with upstream.

@xlla
Copy link
Author

xlla commented Nov 22, 2019

what a pity that a 100Mhz quark MCU was abandoned.

@andy-shev
Copy link
Contributor

andy-shev commented Nov 22, 2019

what a pity that a 100Mhz quark MCU was abandoned.

Agree, and unfortunately I can't do anything about it. I can advise, though not recommend to follow it (waste of time for cancelled products if you are not Big Customer), to complain to Intel thru the official channels.

@htot
Copy link
Member

htot commented Nov 22, 2019

The idea was brilliant. Would have been great to run Zephyr on the MCU. Maybe it will return in a future product.

@xlla
Copy link
Author

xlla commented Nov 23, 2019

waste of time for cancelled products

Reasonably~but why we devoted ourself with enthusiasm to maintain this cancelled product(intel edison), and add many new features to it, such as new kernel, patched u-boot, ACPI, 64bit, etc.

@andy-shev
Copy link
Contributor

waste of time for cancelled products

Reasonably~but why we devoted ourself with enthusiasm to maintain this cancelled product(intel edison), and add many new features to it, such as new kernel, patched u-boot, ACPI, 64bit, etc.

First of all, just for fun and there also few more useful (for me personally as an Intel employee) giveaways.

@xlla
Copy link
Author

xlla commented Nov 23, 2019

me too, just for fun , haha~

@xlla
Copy link
Author

xlla commented Mar 9, 2020

@andy-shev as I was stuck in acpi,u-boot and kernel, I would like to port the old implement to current , could you mind to help me as a guides.

@xlla xlla reopened this Mar 9, 2020
@andy-shev
Copy link
Contributor

@xlla, simplest way is to take PSH "driver" as is from stock image (sources) and compile it in the new kernel environment. It should work like the original one. Somewhere I even had a patch, I can share (tell me your email for that). The pin muxing issue is there, though. That's why enabling pin muxing has much more priority over PSH, besides the fact the PSH is not convenient to use due to absence of Zephyr kernel for it.

@xlla
Copy link
Author

xlla commented Mar 17, 2020

@andy-shev sorry for the late reply, I have sent a email to you.
I have final rescued my development environment and migrate to a ssd, hope it will speed up build process.
I have prepare a workspace for kernel module development, plan to migrate module intel_mcu.

@andy-shev
Copy link
Contributor

I have sent you the patch (it's basically compound of what we used to have in stock kernel. Feel free to clean up and send a PR. Maybe @htot will include it in the kernel. (Note, it's not upstreamable material from my perspective, though you always may try to go directly to upstream with it)

@xlla
Copy link
Author

xlla commented Mar 19, 2020

I have compiled it into kernel, flash to ota partition and boot from sdcard.
it works but very lag.

Kernel command line: "tty1=console=ttyS2,115200n8 root=/dev/mmcblk1p1 rootfstype=ext4 systemd.unit=multi-user.target hardware_id=00"
Magic signature found

Starting kernel ...

Application available at (physical) address 0x04819000
    VRL mapped to 0xff217000
    App size = 11508 bytes

    App Authentication feature is disabled!
    Resetting IPC

*** Ready to receive application *** 

Poky (Yocto Project Reference Distro) 2.7.3 edison ttyS2

cpu load up to 43% and keep on.

Mem: 161068K used, 816884K free, 576K shrd, 8356K buff, 104880K cached
CPU:   4% usr  54% sys   0% nic   0% idle  41% io   0% irq   0% sirq
Load average: 17.99 17.61 12.77 12/108 750
Mem: 161068K used, 816884K free, 576K shrd, 8356K buff, 104880K cached
CPU:   4% usr  52% sys   0% nic   0% idle  43% io   0% irq   0% sirq
Load average: 17.99 17.62 12.80 12/108 751
  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
   89     2 root     RW       0   0%  43% [irq/24-intel_ps]
  751   661 root     R     3764   0%   4% top
  656   655 root     S    26952   3%   0% (sd-pam)
    1     0 root     D    26156   3%   0% {systemd} /sbin/init tty1=console=ttyS2,115200n8 root=/dev/mmcblk1p1 rootfstype=ext4 systemd.unit=m
  498     1 root     S    22248   2%   0% /usr/sbin/rngd -f -r /dev/hwrng

dmesg flood with

[  509.134958] intel_psh_ipc 0000:00:16.0: Ignore message from channel 6
[  509.135010] intel_psh_ipc 0000:00:16.0: Ignore message from channel 6
[  509.135136] intel_psh_ipc 0000:00:16.0: Ignore message from channel 6
[  509.135206] intel_psh_ipc 0000:00:16.0: Ignore message from channel 6
[  509.135344] intel_psh_ipc 0000:00:16.0: Ignore message from channel 6
[  509.135473] intel_psh_ipc 0000:00:16.0: Ignore message from channel 6
[  509.135542] intel_psh_ipc 0000:00:16.0: Ignore message from channel 6
[  509.135593] intel_psh_ipc 0000:00:16.0: Ignore message from channel 6
[  509.135709] intel_psh_ipc 0000:00:16.0: Ignore message from channel 6
[  509.135763] intel_psh_ipc 0000:00:16.0: Ignore message from channel 6

intel_mcu node exist

root@edison:~# ls /sys/devices/platform/intel_mcu -al
total 0
drwxr-xr-x  4 root root    0 Mar 18 17:38 .
drwxr-xr-x 17 root root    0 Mar 18 17:38 ..
--w-------  1 root root 4096 Mar 18 17:44 control
lrwxrwxrwx  1 root root    0 Mar 18 17:46 driver -> ../../../bus/platform/drivers/intel_mcu
-rw-r--r--  1 root root 4096 Mar 18 17:46 driver_override
-r--------  1 root root 4096 Mar 18 17:42 fw_version
-rw-------  1 root root 4096 Mar 18 17:43 log_level
-r--r--r--  1 root root 4096 Mar 18 17:46 modalias
drwxr-xr-x  2 root root    0 Mar 18 17:46 power
lrwxrwxrwx  1 root root    0 Mar 18 17:38 subsystem -> ../../../bus/platform
drwxr-xr-x  5 root root    0 Mar 18 17:38 tty
-rw-r--r--  1 root root 4096 Mar 18 17:38 uevent

if I missing something or default mcu app try to send something that new kernel can't understand?

@xlla
Copy link
Author

xlla commented Mar 19, 2020

I upload a simple mcu app just read from tty and print debug info, to avoid involve any mux/pin.

I can't get any message from ttymcu0

root@edison:/mnt/sdcard/test# echo debug > /sys/devices/platform/intel_mcu/log_level 
-sh: echo: write error: Operation not permitted

root@edison:/mnt/sdcard/test# cat /sys/devices/platform/intel_mcu/log_level
cat: /sys/devices/platform/intel_mcu/log_level: Operation not permitted

root@edison:~# cat /dev/ttymcu0
^C

root@edison:~# echo "start" > /dev/ttymcu0 
root@edison:~# cat /dev/ttymcu0 
^C

root@edison:/mnt/sdcard/test# cat /proc/interrupts | grep intel_psh_ipc
 24:   33181819          0   IO-APIC  47-fasteoi   intel_psh_ipc

@xlla
Copy link
Author

xlla commented Mar 21, 2020

after clear interrupt flags, no more complain messages, cpu load drop to 0,

root@edison:~# cat /proc/interrupts | grep intel_psh_ipc
 24:          1          0   IO-APIC  47-fasteoi   intel_psh_ipc

root@edison:~#top
CPU:   0% usr   0% sys   0% nic  99% idle   0% io   0% irq   0% sirq

but still can't access log_level

root@edison:~# cat /sys/devices/platform/intel_mcu/log_level
cat: /sys/devices/platform/intel_mcu/log_level: Operation not permitted

root@edison:~# ls -al /sys/devices/platform/intel_mcu/log_level
-r--r--r-- 1 root root 4096 Mar 21 18:21 /sys/devices/platform/intel_mcu/log_level

@xlla
Copy link
Author

xlla commented Mar 22, 2020

I don't know how to debug kernel module.
after add many trace log, I finally found intel_mcu was load before intel_psh_ipc, so something not prepared correctly.
how to force load module_platform_driver A after module_pci_driver B?
should I move intel_mcu files from drivers/hwmon into drivers/platform/x86 , and change the appearance order in Makefile ?

@xlla
Copy link
Author

xlla commented Mar 22, 2020

Bingo!
after adjust those modules load senquence, I got it.
It is very exciting even just seen a few logs from MCU. @htot

mcu1

mcu2

root@edison:~# cat /sys/devices/platform/intel_mcu/log_level
debug

Many thanks to @andy-shev !

@htot
Copy link
Member

htot commented Mar 22, 2020

Don't forget to send a PR when you get stuff to work!

@xlla
Copy link
Author

xlla commented Mar 22, 2020

look carefully at those logs and compare with source code, the sequence was RANDOM!

@xlla
Copy link
Author

xlla commented Mar 22, 2020

@htot I will.
it now on bare status, I need to check every point with edison-mcusdk.
first of all, I want to config usb0 to 192.168.2.15 automatically, since each time mcusdk upload an app, it will reboot edison, then I lost usb ethernet.
I have created a service to do that, but failure on reboot.

root@edison:~# systemctl status network-gadget-init.service
● network-gadget-init.service - USB Ethernet gadget
   Loaded: loaded (/lib/systemd/system/network-gadget-init.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Mon 2020-03-23 00:17:16 CST; 41s ago
  Process: 573 ExecStart=/bin/sh -c  ifconfig usb0 192.168.2.15 netmask 255.255.255.0 (code=exited, status=255/EXCEPTION)
 Main PID: 573 (code=exited, status=255/EXCEPTION)

Mar 23 00:17:15 edison systemd[1]: Starting USB Ethernet gadget...
Mar 23 00:17:15 edison sh[573]: SIOCSIFADDR: No such device
Mar 23 00:17:15 edison sh[573]: usb0: ERROR while getting interface flags: No such device
Mar 23 00:17:15 edison sh[573]: SIOCSIFNETMASK: No such device
Mar 23 00:17:16 edison systemd[1]: network-gadget-init.service: Succeeded.
Mar 23 00:17:16 edison systemd[1]: Started USB Ethernet gadget.

should I wait some service then launch my service?
I don't know which service will prepare usg gadget.

or add this in to service unit file?

ExecStartPre=-/bin/sh -c "echo 'connect' > /sys/class/udc/dwc3.0.auto/soft_connect"

another question, when mcusdk upload an app, it will reboot edison; it seems edison must be reboot when mcu app upload, but I notice these is a service will upload mcu app, why that upload do not need a reboot?

root@edison:~# systemctl status mcu_fw_loader.service
● mcu_fw_loader.service - Daemon to load edison mcu app binary
   Loaded: loaded (/lib/systemd/system/mcu_fw_loader.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Mon 2020-03-23 00:17:16 CST; 16min ago
  Process: 582 ExecStart=/etc/intel_mcu/mcu_fw_loader.sh (code=exited, status=0/SUCCESS)
 Main PID: 582 (code=exited, status=0/SUCCESS)

Mar 23 00:17:15 edison systemd[1]: Started Daemon to load edison mcu app binary.
Mar 23 00:17:16 edison systemd[1]: mcu_fw_loader.service: Succeeded.

If I first power on edison, this service will upload mcu app, then edison need reboot immediately, and the app will upload again, and need another reboot.
should I disable this service , manual upload mcu app , do a reboot to do the test?

@htot
Copy link
Member

htot commented Mar 22, 2020

Network: https://edison-fw.github.io/meta-intel-edison/4.2-networking.html#gadget
The network should already be up, no service needed. The connection is made from the host side.

MCU problems: I don't now, never tried, not even with the factory firmware.

@xlla
Copy link
Author

xlla commented Mar 23, 2020

I have execute those commands in that article, and I found every time I reboot the Edison, only need manual call

ifconfig usb0 192.168.2.15 netmask 255.255.255.0

then usb ethernet would work.

Since I changed gadget protocol to RNDIS, on mac host, network was recognized automatically.
usb0

The network should already be up, no service needed

it was up when I login in, but not got an IP like this.

root@edison:~# ifconfig usb
usb0      Link encap:Ethernet  HWaddr aa:bb:cc:dd:ee:f0  
          inet6 addr: fe80::a8bb:ccff:fedd:eef0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:20285 errors:0 dropped:0 overruns:0 frame:0
          TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:828488 (809.0 KiB)  TX bytes:6518 (6.3 KiB)

would you tell me which service load /usr/bin/conf-gadget.sh, so I can let my service wait after it.

@xlla
Copy link
Author

xlla commented Mar 23, 2020

or another service had execute those command auto

connmanctl
enable gadget
services
connect gadget_aabbccddeef1_usb

each time I power on edison or reboot it, wifi and usb0 was got connected.

root@edison:~# connmanctl              
connmanctl> services
*AO wifissid                wifi_fc23456cc_6970617135_managed_psk
*   Wired                gadget_aabbccddeef0_usb
connmanctl> 

wifi was fine, since dhcp on router, but usb0 need manual assign IP.

@htot
Copy link
Member

htot commented Mar 23, 2020

but usb0 need manual assign IP.

No that is wrong. usb gets ip from host. But you need to tell host to have dhcp server (shared ip connection). Reed instructions again.

Also usb should have power enabled automatically.

@xlla
Copy link
Author

xlla commented Mar 24, 2020

to emulate the original Edison's behavior, I found it was called by udev rules, so I invoke my service from udev rules too, it works.

[  OK  ] Started Hostname Service.

Poky (Yocto Project Reference Distro) 2.7.3 edison ttyS2

edison login: root
Last login: Wed Mar 25 00:13:23 CST 2020 on ttyS2
root@edison:~# ifconfig usb0
usb0      Link encap:Ethernet  HWaddr aa:bb:cc:dd:ee:f0  
          inet addr:192.168.2.15  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a8bb:ccff:fedd:eef0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:59 errors:0 dropped:0 overruns:0 frame:0
          TX packets:43 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:19119 (18.6 KiB)  TX bytes:9168 (8.9 KiB)

root@edison:~# systemctl status  sys-subsystem-net-devices-usb0.device
● sys-subsystem-net-devices-usb0.device - Merrifield USB Device Controller (OTG)
   Loaded: loaded
   Active: active (plugged) since Wed 2020-03-25 00:16:19 CST; 38s ago
   Device: /sys/devices/pci0000:00/0000:00:11.0/dwc3.0.auto/gadget/net/usb0
root@edison:~# systemctl status [email protected][email protected] - USB Gadget ifconfig
   Loaded: loaded (/lib/systemd/system/[email protected]; static; vendor preset: enabled)
   Active: active (exited) since Wed 2020-03-25 00:16:20 CST; 1min 1s ago
  Process: 613 ExecStart=/sbin/ifconfig usb0 192.168.2.15 netmask 255.255.255.0 (code=exited, status=0/SUCCESS)
 Main PID: 613 (code=exited, status=0/SUCCESS)

Mar 25 00:16:19 edison systemd[1]: Starting USB Gadget ifconfig...
Mar 25 00:16:20 edison systemd[1]: Started USB Gadget ifconfig.

@htot
Copy link
Member

htot commented Mar 24, 2020

Sure, there may be multiple ways to do the same thing:

root@edison:~# connmanctl 
connmanctl> technologies 
..
/net/connman/technology/gadget
  Name = Gadget
  Type = gadget
  Powered = False
  Connected = False
  Tethering = False

connmanctl> enable gadget
connmanctl> connect gadget_aabbccddeef1_usb
  
connmanctl> services 
* O Wired                gadget_aabbccddeef1_usb

connmanctl> quit

root@edison:~# ifconfig
..
usb0      Link encap:Ethernet  HWaddr aa:bb:cc:dd:ee:f1  
          inet addr:10.42.0.221  Bcast:10.42.0.255  Mask:255.255.255.0
          inet6 addr: fe80::a8bb:ccff:fedd:eef1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST DYNAMIC  MTU:1500  Metric:1
          RX packets:340101 errors:0 dropped:218 overruns:0 frame:0
          TX packets:25306 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:509201080 (485.6 MiB)  TX bytes:2443903 (2.3 MiB)
..

root@edison:~# iperf3 --server

+---on host ------------

ferry@delfion:~$ iperf3 --client edison.local
Connecting to host edison.local, port 5201
[  5] local fe80::b87a:5bf5:7bd6:5ea4 port 52958 connected to fe80::a8bb:ccff:fedd:eef1 port 5201
[ ID] Interval           Transfer     Bitrate         Retr  Cwnd
[  5]   0.00-1.00   sec  24.9 MBytes   209 Mbits/sec    0   1.01 MBytes       

then after reboot it is already powered, but not connected. For that:

connmanctl> config gadget_aabbccddeef1_usb --autoconnect yes

connmanctl> services 
*A  Wired                gadget_aabbccddeef1_usb

A means autoconnect.

@xlla
Copy link
Author

xlla commented Mar 25, 2020

in my case, after reboot, no need do anything, it is Wired without "A" prefix.
my udev rules will config ip automatic, so does not need host run dhcp service.
as there is showed "Connected = False", I can do connection test successful.

root@edison:~# connmanctl
connmanctl> services
*AO ssid                wifi_xxxxx_managed_psk
*   Wired                gadget_aabbccddeef0_usb
    phone                 bluetooth_xxxx

connmanctl> technologies
/net/connman/technology/gadget
  Name = Gadget
  Type = gadget
  Powered = True
  Connected = False
  Tethering = False

root@edison:~# iperf3 --server
-----------------------------------------------------------
Server listening on 5201

on host

==> Pouring iperf3-3.7_1.high_sierra.bottle.1.tar.gz
🍺  /usr/local/Cellar/iperf3/3.7_1: 11 files, 380.4KB
rmbp:workspace-mcu xlla$ iperf3 --client 192.168.2.15
Connecting to host 192.168.2.15, port 5201
[  5] local 192.168.2.20 port 58492 connected to 192.168.2.15 port 5201
[ ID] Interval           Transfer     Bitrate
[  5]   0.00-1.00   sec  26.9 MBytes   226 Mbits/sec                  
[  5]   1.00-2.00   sec  27.0 MBytes   227 Mbits/sec                  
[  5]   2.00-3.00   sec  26.8 MBytes   225 Mbits/sec                  

@htot
Copy link
Member

htot commented Mar 25, 2020

That's right.

In fact you are 'manually assigning an address' but through a script. That means your host doesn't know the address edison or edison.local unless you also add it to /etc/hosts, right?

@xlla
Copy link
Author

xlla commented Mar 26, 2020

yes! that's the original Edison board's behavior, at that time, every tutorial and manual just use that special IP for edison usb ethernet. intel xdk/ mcusdk/iot all are try to connect edison use that IP.
I am lazy to change those app.

@htot
Copy link
Member

htot commented Mar 26, 2020

I see that's fine.

Can you create a PR for changing to rndis?

@xlla
Copy link
Author

xlla commented Mar 30, 2020

In my adventure, I'v change a lot of files to get things run, I don't know how to pick them out individually right now, may I create a PR with all of them, or create a clean PR when I have learned how to do that in the future.

I will push it here temporary in period.

@htot
Copy link
Member

htot commented Mar 30, 2020

I use qgit to visually select files to create a commit.

But I think Andy pointed out you can undo 1 commit with git reset HEAD~1, the files will be uncommited but not erased.

Each commit (git commit) will be done on the files that you added (git add).

https://www.atlassian.com/git/tutorials/saving-changes/git-commit

We really don't want to have a single commit with everything in it. It's impossible to understand / debug / rollback.

@andy-shev
Copy link
Contributor

The ProGit Book is very good and free: https://git-scm.com/book/en/v2

@htot
Copy link
Member

htot commented Mar 15, 2021

@xlla

In my adventure, I'v change a lot of files to get things run, I don't know how to pick them out individually right now, may I create a PR with all of them, or create a clean PR when I have learned how to do that in the future.

I will push it here temporary in period.

Are you still working on this?
There is quite some useful stuff in your branch like enable rndis. Did you get the mcu to work in the end?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants