---
# System prepended metadata

title: NXP
tags: [nxp, linux, yocto, 工作]

---

# NXP

平台:iMX-8M-Mini-EVK

## 目標一: 先使用現成的image啟動系統

## 目標二: 自行編譯系統
```bash=
DISTRO=fsl-imx-xwayland MACHINE=imx8mmevk source fsl-setup-release.sh -b build-xwayland
 
#bitbake imx-image-full
bitbake fsl-image-validation-imx
# fsl-image-qt5-validation-imx
bitbake meta-toolchain-qt5
sudo dd if=fsl-image-validation-imx-imx8mmevk.sdcard of=/dev/sdc bs=1M conv=fsync
```


[4.4.2](https://www.nxp.com/docs/en/user-guide/IMX_LINUX_USERS_GUIDE.pdf)
需要研究chap 8去了解的東西
1. QT->
1-1. 8.2 G2D-imx-samples
1-2. [ i.MX Graphics User’s Guide](https://www.nxp.com/docs/en/user-guide/IMX_GRAPHICS_USERS_GUIDE.pdf)
1-3 使用 **bitbake imx-image-full**產生的yocto linux image包含Qt5。
2. ethernet 
3. wifi
4. hdmi graphic output

要開機需要四個元件:

• Linux OS kernel image (zImage/Image)
• Device tree file (*.dtb)
• Bootloader image
• Root file system (i.e., EXT4)

---

[i.MX Linux® Release Notes](https://www.nxp.com/docs/en/release-note/IMX_LINUX_RELEASE_NOTES.pdf)

[i.MX Porting Guide](https://www.nxp.com/docs/en/user-guide/IMX_PORTING_GUIDE.pdf)

[i.MX Linux Reference Manual](https://www.nxp.com/docs/en/reference-manual/IMX_REFERENCE_MANUAL.pdf)

---

[Evaluation Kit for the i.MX 8M Mini Applications Processor](https://www.nxp.com/design/development-boards/i-mx-evaluation-and-development-boards/evaluation-kit-for-the-i-mx-8m-mini-applications-processor:8MMINILPD4-EVK#t768)

[Get Started with the i.MX 8M Mini EVK](https://www.nxp.com/document/guide/get-started-with-the-i-mx-8m-mini-evk:GS-iMX-8M-Mini-EVK)

[【ATU Book-i.MX8系列】 NXP i.MX8M Mini 環境建置
](https://www.wpgdadatong.com/tw/blog/detail?BID=B1134)

## 設定wifi

設定ESSID和密碼
```bash=
wpa_passphrase ESSID password >> /etc/wpa_supplicant.conf
```

若要在開機的時候啟動網路需在 **/etc/init.d** 裡面加入腳本**wifi**


```bash= wifi
## 可將以下兩行寫入根目錄底下的profile裡面讓他在每次開機打開終端的時候執行
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf -D nl80211 
udhcpc -i wlan0 

```

之後在用指令chmod調整執行權限
```bash=
chmod 755 /etc/init.d/wifi
```

最後在修改/etc/rc.local讓腳本可以在開機時候可以執行
```bash=
#在exit之前加入下面內容
/etc/init.d/wifi
```

## 藍芽

http://variwiki.com/index.php?title=IMX_Bluetooth_Obex

## toolchain

使用的是armv8 64bits的toolchain
https://www.linaro.org/downloads/

## gpio

[[gpio]Linux GPIO简单使用方式1-sysfs](https://www.cnblogs.com/aaronLinux/p/6684260.html)

## i2c

https://b8807053.pixnet.net/blog/post/347698301-linux-tool---%3A--i2c-tools-%E7%9A%84%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%EF%BC%8C-i2cdetect-%E3%80%81-i


https://www.kernel.org/doc/Documentation/i2c/dev-interface

遇到問題:Chip address out of range (0x03-0x77)!
選裝置時要注意要在範圍之內

## toolchain

[Build and install the QT5 toolchain](http://variwiki.com/images/archive/8/8d/20161228090959%21YoctoQtCreator.pdf)

[Yocto tips (16): Yocto 制作SDK分发Toolchain 脱离Yocto环境开发](https://blog.csdn.net/sy373466062/article/details/50387199)

自行編譯的toolchain會放在**build-xwayland-imx8mmevk/tmp/deploy/sdk/**裡面(編譯過程會由於缺乏一些標準函式庫而編譯失敗；linaro提供的順利編譯。)

安裝toolchain:
```bash=
source fsl-imx-xwayland-glibc-x86_64-meta-toolchain-qt5-aarch64-toolchain-4.14-sumo.sh
```

到安裝的路徑下指令設置相關環境變數
```bash=
source environment-setup-aarch64-poky-linux
```
之後gcc要用$CC替代

## Qt工具選項設定

[Setting up Qt Creator to build for i.MX6](/opt/fsl-imx-xwayland/4.14-sumo/sysroots/x86_64-pokysdk-linux/usr/bin/qt5/)

## GPIO I2C SPI操作

GPIO:
(gpio-1)*32+10
/sys/kernel/debug
soc datasheet

---
I2C:
**I2Cdetect 掃描到的是7bit的address**
[i2ctransfer(8)](https://manpages.debian.org/unstable/i2c-tools/i2ctransfer.8.en.html)

[linux I2C 裝置驅動學習筆記](https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/420608/)

[Linux系统下i2c工具 i2c-tool 的使用](https://www.cnblogs.com/raina/p/12068485.html)

[讓你的 Raspberry Pi 透過 I²C 讀取 eeprom](https://coldnew.github.io/f0528f55/)

---

SPI:
[linux spi子系統驅動開發筆記之例項（2）](https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/420629/)
[如果SPI正在如何检查?吗?](https://www.asapsell.com/community/thread/461426)

驅動開發:
[Linux 字元裝置驅動結構（一）—— cdev 結構體、裝置號相關知識解析](https://www.itread01.com/p/1372699.html)

[spidev介绍](https://blog.csdn.net/chinazhangzhong123/article/details/54707387)

[kernel menuconfig](https://community.nxp.com/thread/447031)

[Using SPI with Linux](https://armbedded.taskit.de/node/318)

[[5.add new spi driver]如何新增一個spi裝置的driver到imx 8m mini evk上](https://cuteparrot.pixnet.net/blog/post/228761321-%5B5.add-new-spi-driver%5D%E5%A6%82%E4%BD%95%E6%96%B0%E5%A2%9E%E4%B8%80%E5%80%8Bspi%E8%A3%9D%E7%BD%AE%E7%9A%84driver)


## uart
[UART和RS232/RS485的關係是什麼？](https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/586303/)

https://www.emcraft.com/som/imx-8m/using-imx-8m-uart-ports-in-linux

[Using a UART serial port from a linux shell](https://www.technexion.com/support/knowledgebase/using-a-serial-port-from-a-linux-shell/)

[How to open, read, and write from serial port in C?](https://stackoverflow.com/questions/6947413/how-to-open-read-and-write-from-serial-port-in-c)

[Linux Ubuntu stty 使用](https://www.itread01.com/content/1546281308.html)

[RS232 UART 的差別-最原始的通訊介面原來長這樣](https://www.strongpilab.com/rs232-uart-difference/)

[UART中的硬體流控RTS與CTS](https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/609463/)

[工程师详解串口：RS-232、RS-422、RS-485之间的区别](http://murata.eetrend.com/article/2018-08/1001944.html)

[ADM2582](https://www.analog.com/media/en/technical-documentation/data-sheets/adm2582e_2587e.pdf)

https://blog.csdn.net/cmoooo/article/details/18228305

https://stackoverflow.com/questions/22511225/sending-hex-bytes-to-serial-in-bash

[linux 串口uart的使用詳解](https://www.twblogs.net/a/5b8382042b71776c51e36146)

## device tree
[什麼是Device Tree?](http://blog.ittraining.com.tw/2016/12/device-tree.html)

[Device Tree Fundamental](http://devicetreememo.blogspot.com/2017/01/device-tree-fundamental.html)

## PID

https://scitechvista.nat.gov.tw/c/sTCB.htm

http://ca.gwinstek.com/index.php?view=custom1&d=5

https://zh.wikipedia.org/wiki/PID%E6%8E%A7%E5%88%B6%E5%99%A8

https://www.ni.com/zh-tw/innovations/white-papers/06/pid-theory-explained.html

https://tw.azbil.com/%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%a1%88/%e6%98%93%e8%a7%a3pid%e6%8e%a7%e5%88%b6%e7%9a%84%e6%95%85%e4%ba%8b1%e4%bd%95%e8%ac%82%e6%ba%ab%e5%ba%a6%e6%8e%a7%e5%88%b6/

## modbus

http://www.kce.2u.com.tw/download/MODBUS%20CRC16.pdf

https://cht.nahua.com.tw/index.php?url=https://cht.nahua.com.tw/software/crc16/&key=Modbus,%20RTU,%20CRC16&title=%E8%A8%88%E7%AE%97%20Modbus%20RTU%20CRC16

## 溫度IC

[LM75x Digital Temperature Sensor and Thermal Watchdog With Two-Wire Interface](https://www.ti.com/lit/ds/symlink/lm75b.pdf?ts=1600761853503&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FLM75B%253FCMP%253Dconv-poasamples)

https://cooling-tower.com.tw/solution-tw/skill-knowledre-tw/cooling-tower-knowledge-tw/what-is-the-wet-bulb-tw

```bash=
set xlabel 'timestamp'
set ylabel 'temerature'
set datafile separator","
plot "tmp_record.csv" using 2 title "data1" with linespoints linewidth 1
plot -persist 'record.csv' using 1:2 with lines

```

```bash=
#!/usr/bin/gnuplot -persist

set datafile separator ","
set output 'runtime.png'
set term png enhanced font 'Verdana,10'
plot 'record.csv' using 1:2 with lines title "record"
set output 'runtime2.png'
plot 'record2.csv' using 1:2 with lines title "record2"
```

linux c pipe programming
pipe,dup,popen
remote gdb


```bash= gcc -lpthread
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

// 子執行緒函數
void* child(void* data) {
  char *str = (char*) data; // 取得輸入資料
  while(1){
    if(*((int*)data)){
     printf("pressed\n");
    }
    else{
     printf("unpressed\n");
    }
    sleep(1);
  }
  pthread_exit(NULL); // 離開子執行緒
}

// 主程式
int main() {
  pthread_t t; // 宣告 pthread 變數
  int flag=0;
  pthread_create(&t, NULL, child, (void*)&flag); // 建立子執行緒

  // 主執行緒工作
  while(1) {
    scanf("%d",&flag);
  }

  pthread_join(t, NULL); // 等待子執行緒執行完成
  return 0;
}
```
使用xargs將參數列切成多數小段。

[C 語言 pthread 多執行緒平行化程式設計入門教學與範例](https://blog.gtwang.org/programming/pthread-multithreading-programming-in-c-tutorial/)

[OS - Ch4 多執行緒 Multithread Programming](https://mropengate.blogspot.com/2015/01/operating-system-ch4-multithread.html)

[How to Pass Command Line Arguments to Bash Script
](https://www.baeldung.com/linux/pass-command-line-arguments-bash-script)

https://hackmd.io/@sysprog/c-trick?type=view

http://puremonkey2010.blogspot.com/2012/08/linux-linuxps-statrsdtzx.html

https://man7.org/linux/man-pages/man2/pipe.2.html

https://man7.org/linux/man-pages/man3/mkfifo.3.html

https://man7.org/linux/man-pages/man7/fifo.7.html?fbclid=IwAR2arUyVucL3bKeyDZUL6OjKPPjJ-KipKYEAFsh0Zu7oqtfiR2s0N8B4fss#:~:text=A%20FIFO%20special%20file%20

https://b8807053.pixnet.net/blog/post/327113148-linux-%E4%BF%A1%E8%99%9Fsignal%E8%99%95%E7%90%86%E6%A9%9F%E5%88%B6

模糊控制(fuzzy controller)

http://www.mstarlabs.com/control/znrule.html

https://github.com/br3ttb/Arduino-PID-AutoTune-Library/blob/master/PID_AutoTune_v0/PID_AutoTune_v0.cpp

https://zh.wikipedia.org/wiki/PID%E6%8E%A7%E5%88%B6%E5%99%A8

https://zh.wikipedia.org/wiki/%E6%8B%89%E6%99%AE%E6%8B%89%E6%96%AF%E7%AE%97%E5%AD%90

[Linux下fork函數及pthread函數的總結](https://www.cntofu.com/book/46/linux_system/linuxxia_fork_han_shu_ji_pthread_han_shu_de_zong_j.md)


http://nano-chicken.blogspot.com/2014/07/linuxttyptypts.html

http://www.tcvs.tc.edu.tw/ftp/20130918111735.pdf

---
https://github.com/br3ttb?tab=repositories->auto tune and pid controller compute

https://github.com/br3ttb/Arduino-PID-AutoTune-Library/blob/master/PID_AutoTune_v0/PID_AutoTune_v0.cpp

https://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method

https://fenix.tecnico.ulisboa.pt/downloadFile/395139427476/Resumo%20Alargado%20-%20Auto-tuning%20de%20Controladores%20PID%20pelo%20m%C3%A9todo%20Relay.pdf

https://d1.amobbs.com/bbs_upload782111/files_36/ourdev_614499E39LAH.pdf


---

https://github.com/jackw01/arduino-pid-autotuner/blob/master/pidautotuner.cpp

https://github.com/jackw01/arduino-pid-control

https://github.com/cvra/pid

http://www.processcontrolstuff.net/wp-content/uploads/2015/02/relay_autot-2.pdf

file:///home/wonder-system/Downloads/QIR_ratna.pdf

https://www.scitepress.org/Papers/2014/50639/50639.pdf

https://warwick.ac.uk/fac/cross_fac/iatl/reinvention/archive/volume5issue2/hornsey

[Linux GPIO简单使用方式1-sysfs](https://www.cnblogs.com/aaronLinux/p/6684260.html)

```bash=max6678
#!/bin/bash

cs=/sys/class/gpio/gpio507/value
clk=/sys/class/gpio/gpio508/value
miso="cat /sys/class/gpio/gpio509/value"

function spiread(){
t=0
for i in {7..0}
do
  echo 0 > $clk
  usleep 10
  if [ $($miso) -eq 1 ]
  then
    t=$(($t|(1<<$i)))
  fi
  echo 1 > $clk
  usleep 10
done
echo $t
}

function readCelsius(){
echo 0 > $cs
usleep 10
v1=$(spiread)
printf "v1:0x%x\n" $v1
v2=$(spiread)
printf "v2:0x%x\n" $v2
echo 1 > $cs
v_final=$((($v1<<8)|$v2))
printf "v_final:0x%x\n" $v_final
if [ $(($v_final & 0x04)) -eq 4 ]
then
  echo error
  exit 5
fi
v_final=$(($v_final>>3))
echo $v_final*0.25 | bc
}

readCelsius
```

http://www.yjfloat.com.tw/en/omron/pdf/O/%E6%BA%AB%E5%BA%A6%E6%8E%A7%E5%88%B6%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%A6%82.pdf

## 濕度測量方法

使用兩個相同規格的溫度測量計，一隻包裹沾濕的物件，一隻則直接量測，藉由兩個再升溫中的誤差可推斷出空間中的濕度為何。
[參考資料](http://www.cf-photo.com.tw/eyc-tech/admin/upload/%E6%BA%AB%E6%BF%95%E5%BA%A6%E4%BB%8B%E7%B4%B9.pdf)

###### tags: `nxp` `linux` `yocto` `工作`