Difference between revisions of "Template:Compute Module 4 PoE 4G Board manual"

From Waveshare Wiki
Jump to: navigation, search
Line 119: Line 119:
 
Please check your PCIe device before you used [https://pipci.jeffgeerling.com/ Supported device testing] <br />
 
Please check your PCIe device before you used [https://pipci.jeffgeerling.com/ Supported device testing] <br />
 
Raspberry [https://github.com/geerlingguy/raspberry-pi-pcie-devices/tree/master/extras/cross-compile Kernel compiling]
 
Raspberry [https://github.com/geerlingguy/raspberry-pi-pcie-devices/tree/master/extras/cross-compile Kernel compiling]
 +
<!--
 +
==隔离GPIO/I2C==
 +
隔离GPIO输出为GPIO17 (BCM)和 GPIO27(BCM)<br />
 +
隔离GPIO输入为GPIO23 (BCM)和 GPIO24(BCM)<br />
 +
[[FILE:Compute Module 4 PoE 4G Board_8.png | 600px]]<br /><br />
 +
 +
隔离IO的逻辑电压设置<br />
 +
[[FILE:Compute Module 4 PoE 4G Board_10.png | 600px]][[FILE:Compute Module 4 PoE 4G Board_9.png | 600px]]<br /><br />
 +
 +
隔离I2C为GPIO2/3(BCM),I2C设备号I2C1,<br />
 +
[[FILE:Compute Module 4 PoE 4G Board_7.png | 600px]]<br />
 +
 +
 +
====【预期结果】====
 +
两个OUT 交替输出高和低电平<br>
 +
读取两个IN 的电平状态<br>
 +
<br>
 +
 +
====【python例程】====
 +
<pre>
 +
cd IO/python
 +
sudo python main.py
 +
</pre>
 +
 +
====【C例程】====
 +
<pre>
 +
cd IO/c
 +
make clean
 +
sudo make
 +
sudo ./main
 +
</pre>
 +
 +
<br/><br/>
 +
==隔离ADC==
 +
隔离ADC挂载在隔离I2C上, I2C地址为0x48<br />
 +
I2C默认关闭,开启I2C参考 <font color="#f000f0">开启I2C </font>章节<br />
 +
 +
===C===
 +
 +
cd ADC/c/
 +
sudo ./main
 +
 +
===python===
 +
 +
cd ADC/python/
 +
sudo python examples/main.py
 +
*执行指令运行程序
 +
===预期结果===
 +
<font color="#ff0000">  输出电压值 </font><br/>
 +
<br/>
 +
注意:ADC方案使用ADS1113芯片。内部自带基准电压2.048V,差分输入,输入电压范围:±2.048V<br/>
 +
 +
<br/><br/>
 +
==CAN==
 +
默认关闭,如需打开需要在config.txt中添加内容:<br>
 +
#打开编辑config.txt
 +
sudo nano /boot/config.txt
 +
#添加以下内容
 +
dtparam=spi=on
 +
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
 +
#重启
 +
reboot
 +
 +
重启之后执行:<br>
 +
dmesg | grep spi0
 +
[[file:Compute Module 4 PoE 4G Board_1.png | 600px]]
 +
执行:
 +
sudo ip link set can0 up type can bitrate 1000000
 +
sudo ifconfig can0 txqueuelen 65536
 +
ifconfig
 +
[[file:Compute Module 4 PoE 4G Board_2.png | 600px]]
 +
出现can0 设备号说明驱动成功<br>
 +
 +
===测试===
 +
安装can-utils:<br>
 +
sudo apt-get install can-utils
 +
接收数据
 +
candump can0
 +
发送数据
 +
cansend can0 000#11.22.33.44
 +
#其中11.22.33.44 是数据
 +
#如果需要发送其他数据可以使用继续添加例如
 +
# cansend can0 000#11.22.33.04.70
 +
#不可以使用英文和中文,两位一码格式添加
 +
 +
===例程===
 +
====【Python例程】====
 +
*进入对应的目录:
 +
*接收端运行receive.py:
 +
<pre>
 +
sudo python reveive.py
 +
</pre>
 +
*发送端运行send.py:
 +
<pre>
 +
sudo python send.py
 +
</pre>
 +
 +
本例程是基于python平台,确保以及安装了python-can库<br />
 +
在发送之前要先创建一个can设备,因为前面只是启用MCP2515内核:
 +
<pre>
 +
os.system('sudo ip link set can0 type can bitrate 100000')
 +
os.system('sudo ifconfig can0 up')
 +
</pre>
 +
*第一步:连接到CAN总线<br />
 +
<pre>
 +
can0 = can.interface.Bus(channel = 'can0', bustyp = 'socketcan_ctypes')
 +
</pre>
 +
*第二步:创建信息<br />
 +
<pre>
 +
msg = can.Message(arbitration_id=0x123, data=[0, 1, 2, 3, 4, 5, 6, 7], extended_id=False)
 +
</pre>
 +
*第三步:发送信息
 +
<pre>
 +
can0.send(msg)
 +
</pre>
 +
*最后同样要关闭can设备
 +
<pre>
 +
os.system('sudo ifconfig can0 down')
 +
</pre>
 +
*接收数据:
 +
<pre>
 +
msg = can0.recv(10.0)
 +
</pre>
 +
recv()中定义超时接收时间。<br />
 +
'''更多请参考:https://python-can.readthedocs.io/en/stable/interfaces/socketcan.html<br />'''
 +
<br />
 +
 +
====【C例程】====
 +
*阻塞接收,树莓派打开终端,运行:
 +
<pre>
 +
cd CAN/c/receive/
 +
make clean
 +
sudo make
 +
sudo ./can_receive
 +
</pre>
 +
*发送,树莓派打开终端,运行:
 +
<pre>
 +
cd CAN/c/receive/
 +
make clean
 +
sudo make
 +
sudo ./can_send
 +
</pre>
 +
 +
<br/><br/>
 +
==RS485/232==
 +
默认关闭,如需打开需要在config.txt中添加内容:<br>
 +
sudo nano /boot/config.txt<br>
 +
dtoverlay=uart3
 +
dtoverlay=uart5
 +
reboot
 +
ls /dev/ttyAMA*
 +
<br>
 +
RS232占用GPIO5/GPIO4(BCM编码4/5),设备号ttyAMA1<br>
 +
RS485占用GPIO13/GPIO12(BCM编码13/12),设备号ttyAMA2<br>
 +
===测试===
 +
sudo apt-get install minicom
 +
# RS232
 +
sudo minicom -D /dev/ttyAMA1
 +
#RS485
 +
sudo minicom -D /dev/ttyAMA2
 +
 +
==RTC  FAN==
 +
<font color="red">
 +
*注意事项:请在接通拓展板电源前接上风扇再完成测试,请不要在拓展板已通电即风扇控制芯片已经通电之后再接上风扇,否则会烧掉芯片!
 +
*注意事项:连接前请确认风扇电压和实际上连接的风扇供电
 +
</font>
 +
使用树莓派系统(2021-05-07-raspios-buster-armhf-full )<br/>
 +
<font color="#ff0000"> 注意 使用RTC禁止使用DSI和CSI  </font><br/>
 +
如果需要同时使用,将I2C切换到I2C1设备上(右边)<br/>
 +
[[file:Compute Module 4 PoE 4G Board_11.png | 500px]]<br/>
 +
<font color="#ff0000"> 切换之后所有程序或者驱动全部需要修改 </font><br/>
 +
<font color="#ff0000"> 例程默认使用I2C10(左边) </font><br/>
 +
<br/>
 +
 +
如果需要简单使用,或者需要添加到你程序中而不是内核中,参考C和Python例程参考 [[https://www.waveshare.net/wiki/CM4_RTC_FAN 点这里]]<br\>
 +
 +
===RTC===
 +
sudo nano /boot/config.txt
 +
#在最后添加
 +
dtparam=i2c_vc=on
 +
dtoverlay=i2c-rtc,pcf85063a,i2c_csi_dsi
 +
#在dtparam=audio=on前面添加# 号
 +
#dtparam=audio=on
 +
#保存退出,重启
 +
sudo reboot
 +
 +
====Hwclock简单使用====
 +
同步系统时钟 -> 硬件时钟
 +
sudo hwclock -w
 +
 +
同步硬件时钟 -> 系统时钟
 +
sudo hwclock  -s
 +
#需要关闭网络,或者关闭网络对时,负责会被改回去
 +
 +
设置硬件时钟时间:
 +
sudo hwclock --set --date="9/8/2021 16:45:05"
 +
 +
查看硬件时钟
 +
sudo hwclock -r
 +
 +
显示版本信息
 +
sudo hwclock --verbose
 +
 +
<br\>
 +
<br\>
 +
 +
===风扇===
 +
在上电的时候 风扇会转1秒,然后停止2秒,再转,这是正常现象<br\>
 +
风扇目前没有官方的配置方法,有一个第三方配置方法:https://github.com/neg2led/cm4io-fan<br\>
 +
此方法为第三方发布,不是官方发布,出现任何问题,概不负责!<br\>
 +
mkdir -p ~/src
 +
cd ~/src
 +
git clone https://github.com/neg2led/cm4io-fan.git
 +
cd cm4io-fan
 +
sudo chmod 777 install.sh
 +
sudo  ./install.sh
 +
#下面是对于config.txt的描述介绍
 +
#############################
 +
Name:  cm4io-fan
 +
Info:  Raspberry Pi Compute Module 4 IO Board fan controller
 +
Load:  dtoverlay=cm4io-fan,<param>[=<val>]
 +
Params: minrpm            RPM target for the fan when the SoC is below
 +
                            mintemp (default 3500)
 +
        maxrpm              RPM target for the fan when the SoC is above
 +
                            maxtemp (default 5500)
 +
        midtemp            Temperature (in millicelcius) at which the fan
 +
                            begins to speed up (default 50000)
 +
        midtemp_hyst        Temperature delta (in millicelcius) below mintemp
 +
                            at which the fan will drop to minrpm (default 2000)
 +
        maxtemp            Temperature (in millicelcius) at which the fan
 +
                            will be held at maxrpm (default 70000)
 +
        maxtemp_hyst        Temperature delta (in millicelcius) below maxtemp
 +
                            at which the fan begins to slow down (default 2000)
 +
  #############################
 +
或者 直接参考如下:
 +
dtoverlay=cm4io-fan,minrpm=500,maxrpm=5000,midtemp=45000,midtemp_hyst=2000,maxtemp=50000,maxtemp_hyst=2000
 +
温度高于45摄氏度开始加速,高于50摄氏度最高速
 +
 +
==CSI  DSI==
 +
CSI  和 DSI默认是关闭的,使用摄像头和DSI的时候会占用I2C-10、I2C-11、I2C-0 三个I2C设备<br>
 +
开机执行如下:<br>
 +
sudo apt-get install p7zip-full
 +
wget https://www.waveshare.net/w/upload/4/41/CM4_dt_blob.7z
 +
7z x CM4_dt_blob.7z -O./CM4_dt_blob
 +
sudo chmod 777 -R CM4_dt_blob
 +
cd CM4_dt_blob/
 +
#如果使用两个摄像头和DSI0 执行
 +
sudo  dtc -I dts -O dtb -o /boot/dt-blob.bin dt-blob-disp0-double_cam.dts
 +
#如果使用两个摄像头和DSI1 执行
 +
sudo  dtc -I dts -O dtb -o /boot/dt-blob.bin dt-blob-disp1-double_cam.dts
 +
#在使用任意DSI时,HDMI1没有图像输出,哪怕你没有连接DSI屏幕只要编译的对应的文件,那HDMI1就没有输出了
 +
#如果需要恢复,删除对应的dt-blob.bin 即可: sudo rm -rf /boot/dt-blob.bin
 +
#执行完毕 关闭电源 重启CM4
 +
 +
再连接摄像头和DSI屏幕:<br>
 +
1: 确保断电状态下连接<br>
 +
2: 使用[https://www.waveshare.net/shop/CM-DSI-ADAPTER.htm  CM-DSI-ADAPTER ]转接板连接Compute Module 4 PoE Board和DSI屏幕<br>
 +
3: 使用[https://www.waveshare.net/shop/RPi-Zero-v1.3-Camera-Cable.htm CSI转接线]转接板连接Compute Module 4 PoE Board和CSI摄像头<br>
 +
3: 连接电源<br>
 +
4: 等待几秒后屏幕启动<br>
 +
5: 如果无法启动,检查/boot/dt-blob.bin 是否存在,如果存在再次重启即可<br>
 +
6: 摄像头需要运行raspi-config,选择Interfacing Options->Camera->Yes->Finish-Yes,reboot系统,打开enable camera,然后重启即可保存修改。<br>
 +
 +
参考
 +
 +
测试树莓派摄像头
 +
查看接入的第一个摄像头画面:
 +
sudo raspivid -t 0 -cs 0
 +
查看接入的第二个摄像头画面:
 +
sudo raspivid -t 0 -cs 1
 +
 +
 +
 +
参考[https://www.raspberrypi.org/documentation/hardware/computemodule/cmio-camera.md  CSI相机]
 +
[https://www.raspberrypi.org/documentation/hardware/computemodule/cmio-display.md  DSI显示器]
 +
 +
-->

Revision as of 13:28, 10 September 2021

Writing Image

USB2.0

The USB interfaces are default disabled in CM4, you need to enable it by adding the following lines:the config.txt

dtoverlay=dwc2,dr_mode=host

USB TO UART

The USB to UART port is connected to GPIO14(BCM) and GPIO15(BCM) pins of CM4 with a converter.
You can connect the USB to UART port for login CM4 via serial.
The USB to UART port can also be used for power, in this case, you need to solder a 0ohm resistor to the pad for enabling the powering function.
Compute Module 4 PoE 4G Board 6.png

Buzzer/LED

Buzzer

The buzzer is connected to GPIO22(BCM), low active.

Compute Module 4 PoE 4G Board 4.png

LED

Two LEDs are integrated for users, the green one is connected to GPIO20(BCM)and the red one is connected to GPIO21(BCM), low active.

Compute Module 4 PoE 4G Board 5.png

4G/5G

To work with 4G/5G, you need to connect a wireless module to the M.2 B KEY for featuring corresponding functions. M.2 B KEY only extends USB2.0 interfaces, it doesn't support PCIe devices.
Compute Module 4 PoE 4G Board 3.png
SIM card is required to work with the 4G/5G module
This carrier board supports the 4G module by default, if you use it with 5G modules, some of the 5G functions are not supported.
If you use a 5G module, please check the [SIM8200EA-M2_5G HAT wiki] about how to set up 5G.

If you need to toggle the working status of the 4G module, you can control the GPIO6(BCM), set the GPIO6 to High for disabling the 4G module and set it to Low for enabling.
To toggle the working status of the 4G module, please add delay time for waiting for the operation to work.

SIM7600 M.2 module

Status of M.2 indicators:

M.2_NET M.2_STA
Red LED Green LED Status
Solid OFF Power OFF
Solid OFF Starting
Solid Solid SIM card is an invalid or weak signal
Solid Blink Working
OFF Blink/Solid Shutdowning

Before you configure the SIM7600 module, please make sure that the module is started normally.

sudo apt-get install minicom
sudo minicom -D /dev/ttyUSB2

Type the following command on the minicom

AT+CUSBPIDSWITCH=9011,1,1

Close the minicom and configure usb0

sudo dhclient -v usb0

About RNIDS networking, please refer to [Raspberry Pi networked via RNDIS RNIDS Networking method]
With the operations above, a USB0 port will be recognized.
If the network cannot work, please try to switch frequency with the following AT commands:

 AT+CNBP=0x0002000000400183,0x000001E000000000,0x0000000000000021
 AT+CNBP=0x0002000000400180,0x480000000000000000000000000000000000000000000042000001E200000095,0x0000000000000021

AT Commands

If the network cannot work, plaese check module with AT commands

sudo apt-get install minicom
sudo minicom -D /dev/ttyUSB2

Common AT commandsni

Command Description Return
AT AT test OK
ATE ATE1 enable echo
ATE0 disable echo
OK
AT+CGMI Check manfacture OK
AT+CGMM Check module type OK
AT+CGSN Check SN OK
AT+CSUB Check module version OK
AT+CGMR Check firmware version OK
AT+IPREX Configure hardwara baud rate +IPREX:
OK
AT+CRESET Reset module OK
AT+CSQ Check signal quanlity +CSQ: 17,99
OK
AT+CPIN? Check SIM status +CPIN: READY
AT+COPS? CHeck the current supplier +COPS:
OK
AT+CREG? Check network status +CREG:
OK
AT+CPSI? Check UE information
AT+CNMP Configure network mode:
2:Automatic
13:GSM only
38:LTE only
48 : Any modes but LTE
... ....
OK

For more AT commands, please refer to: AT_Command_V2.00
You can also refer to:SIMCom

PCIE

The PCIe interface is PCIe 2.0 X1, the maximum speed is 500Mb/s
Most of the PCIEx1 device is not supported by Raspberry Pi without a driver.
Please check your PCIe device before you used Supported device testing
Raspberry Kernel compiling