Raspberry Pi Compute Module 4 (CM4) I/O Board RTC 사용하기

환경

사용 방법

/etc/rc.local

#!/bin/bash

# Enable RTC device of Raspberry Pi CM4 module
echo "Loading kernel module for PCF85063 RTC module ..."
echo "pcf85063 0x51" > /sys/class/i2c-adapter/i2c-10/new_device
modprobe rtc-pcf85063

# Sync hardware clock to system clock
echo "Reading from HW clock ..."
hwclock --hctosys
echo "Done."

/lib/systemd/system/rc-local.service

...
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target

/etc/rc.local 권한 설정

sudo chmod +x /etc/rc.local

crontab

...
0 2 * * 6 /bin/bash -c 'service ntp stop; ntpd -gq; if [ "$?" -eq "0" ]; then hwclock --set --date="$(date "+%m/%d/%y %H:%M:%S")"; fi; service ntp start'

재부팅 후 dmesg로 결과 확인

...
[   15.200054] i2c i2c-10: new_device: Instantiated device pcf85063 at 0x51
[   15.262737] rtc-pcf85063 10-0051: registered as rtc0
[   15.264656] rtc-pcf85063 10-0051: setting system clock to 2022-03-17T06:13:33 UTC (1647497613)
...

참고자료

Raspberry Pi × LTE Hat – Raspberry Pi 4 Model B에 LTE Hat (SIM7600E-H 4G HAT)을 추가해서 LTE를 써보자!

※ 원본은 여기(링크)에 써놓고 이 게시물보다 더 주기적으로 업데이트합니다. 참고해주세요.

라즈베리파이에서 사용할 수 있는 LTE Cat-4 Hat으로 모바일 데이터를 사용해보자!‌

준비물

  • Raspberry Pi 4 Model B with 4GB RAM
  • USB Power Supply (5V 2.1A is sufficient)
  • SD Card (class 10 or more required for your mental health safety)
  • LTE Hat: SIM7600E-H LTE Cat.4 Hat
    • You should select specific model, because SIM7600X-series chipset varies by your country’s LTE wireless bandwidth. I’m currently testing it at South Korea, so I would use SIM7600E-H. See here

1단계 – Raspberry Pi OS 설치

  • Raspberry Pi OS 설치는 매우 간단하다. 여기를 참고해서 SD 카드에 Raspberry Pi OS 32bit를 설치하도록 하자. (일반 PC에 설치할 수 있는 Raspberry Pi OS도 있다! 헷갈리지 말자.)
  • 설치가 완료된 뒤에는, SIM7600E-H의 포장을 뜯어보도록 하자.

2단계 – SIM7600E-H HAT 장착

  • Raspberry Pi의 전원을 끄고 분리한다.
  • SIM카드 슬롯에 Full-Size SIM을 삽입한 뒤 SIM7600E-H Hat을 Raspberry Pi에 장착한다. (이 때, Raspberry Pi에 고정해버리면 SIM카드를 빼기 힘드므로 유의하자)
  • 같이 동봉된 짧은 USB Cable를 Raspberry Pi와 SIM7600E-H Hat의 ‘USB’ 포트에 연결한다.
  • 장착한 뒤 Raspberry Pi를 켠다.

3단계 – Raspberry Pi 세팅

  1. 라즈베리파이 내의 UART를 Disable한다.
[1] raspi-config를 실행한다.
[2] 세번째 “Interface Options”를 선택한다.
[3] “P6 Serial Port”를 선택한다.
[4] No를 선택한다.

4단계 – SIM7600E-H RNDIS 세팅

  • Raspberry Pi나 Jetson Nano 자체에 커널 모듈을 빌드하고 물리기 쉬운 일이 아니다. 머나먼 과정을 거치면 되긴 하지만 귀찮기 때문에, 모뎀을 RNDIS 모드로 변경해보도록 하자.
  • 모뎀을 RNDIS 모드로 변경하면, Android 스마트폰에서 USB 테더링을 연결하듯이 간단하게 작동시킬 수 있다.
  1. 먼저 Raspberry Pi가 SIM7600E-H와 잘 연결되었는지 확인하자. USB 디바이스 목록을 확인하여 ttyUSB가 연결되었는지 본다.
  2. 연결된 디바이스 네이밍이 어디에 매칭되는지 아래 정보에서 확인해보자. (출처: https://simcom.ee/documents/SIM5360/How%20to%20use%20linux%20driver.pdf)
  3. 이제 socat을 이용하여 ATCOM interface (줄여서 AT interface)에 연결해서 각종 명령어를 보내보자. 실질적으로 SIM7600E-H 보드와 통신하기 위해서는 AT Interface를 이용한다. 해당 인터페이스는 짧은 AT 명령어들로 통신하는 인터페이스이다.
  4. AT라는 테스트 명령어를 치고 Enter를 누르면 OK라고 뜬다. 정상적으로 연결되었다는 의미이다.
  5. 이제 아래와 같이 RNDIS 인터페이스 활성화 명령어를 입력한다. AT+CUSBPIDSWITCH=9011,1,1 > OK
  6. 이제 socat이 종료되고 칩셋이 재시작된다. 이를 조금만 더 기다리고 다시 시작하면 ip link를 했을때 아래처럼 usb 인터페이스가 뜬다. (보통은 usb0으로 뜨지만, 본인이 쓰는 Jetson Nano에는 usb0이 이미 있어서 usb1으로 할당되었다.)

5단계 – APN 설정

  • 사실 APN은 자동 설정이 가능하다. 여기서는 APN을 기지국으로부터 자동으로 가져오고 이를 사용해 LTE 네트워크에 연결하는 방법을 기술한다.
  1. 4-3단계와 같이 AT Interface에 연결한다.
  2. AT+CGDCONT? 명령어로 현재 사용되는 APN 프로필 리스트를 확인한다.
  3. +CGDCONT: 11은 프로필 ID를 나타낸다. 1부터 6까지 존재하는데, 여기서는 프로필 1번(셀룰러 네트워크 등록 과정에서 사용)과 프로필 6번(RNDIS 연결 과정)
  4. 기지국에서 APN을 자동으로 가져올 수 있도록 AT+CGDCONT=1,"IPV4V6","" 명령어와 AT+CGDCONT=6,"IPV4V6",""를 각각 입력하여 프로필을 비운다.
  5. AT+CGAUTH? 명령어로 현재 APN 인증 프로필을 확인한다.
  6. 마찬가지로 AT+CGAUTH=1,0, AT+CGAUTH=6,0 명령어로 인증 프로필을 비운다.
  7. 마지막으로 AT+CFUN=0 명령어로 SIM 카드를 껐다가, AT+CFUN=1 명령어로 다시 켠다.
  8. 이 뒤에는 인터넷이 정상 연결될 것이다. (다만 IP를 아직 받아오지 못한 상태이다.) 위 4, 5번 단계에 설정한 값들은 보드 자체의 NVRAM에 저장되므로 재시작하여도 RNDIS 모드나 APN 설정들을 다시 해줄 필요는 없다.

6단계 – DHCP 설정 및 Ping 테스트‌

  • 여기서는 1회성 DHCP를 설정해보도록 하자. 간단하다.‌
  1. dhclient -v usb0 (USB 디바이스명)으로 DHCP 클라이언트를 돌려서 IP를 할당한다.
  2. 이제 IP가 할당되었다. 이 후에 원하는대로 사용하면 될 것이다.
  3. 한번 ping 테스트를 해보자. ping -I usb0 명령어로 USB 인터페이스로 Ping을 날릴 수 있다. 통신사마다 다르겠지만, LGU+ 기준으로는 Ping이 잘 작동한다.
  4. 이제 이 위에 우리가 원하는 각종 Application을 얹어보자. 어디서든 인터넷 환경이 되기 때문에 가능성이 무궁무진하다(?)

Miscellaneous

각 통신사별 APN 설정 (출처)

[SKT 3G APN 설정] APN: web.sktelecom.com MMSC: http://omms.nate.com:9082/oma_mms MMS 프록시: smart.nate.com MMS 포트: 9093 MCC: 450 MNC: 05

[SKT LTE APN 설정] APN: lte.sktelecom.com MMSC: http://omms.nate.com:9082/oma_mms MMS 프록시: lteoma.nate.com MMS 포트: 9093 MCC: 450 MNC: 05

[KT 3G APN 설정] APN: alwayson.ktfwing.com MMSC: http://mmsc.ktfwing.com:9082 MMS 포트: 9093 MCC: 450 MNC: 08

[KT LTE APN 설정] APN: lte.ktfwing.com MMSC: http://mmsc.ktfwing.com:9082 MMS 포트: 9093 MCC: 450 MNC: 08

[LG U+ LTE APN 설정] APN: internet.lguplus.co.kr MMSC: http://omammsc.uplus.co.kr:9084 MMS 포트: 9084 MCC: 450 MNC: 06

[Tutorial] Building lastest raspberry pi kernel for 64-bit Ubuntu (20.10)

One of the great parts about running Ubuntu is that just about all the Ubuntu-isms you’ve learned for other platforms work here too. Start with these links:

https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel
https://wiki.ubuntu.com/KernelTeam/ARMK … ossCompile
https://wiki.ubuntu.com/KernelTeam/Kern … k_failures
https://askubuntu.com/questions/500095/ … er-version
https://bugs.launchpad.net/ubuntu/+sour … ug/1701756

What follows isn’t very polished, since came out of my notebook verbatim. This is how I built the kernel.

First uncomment the relevant line int /etc/apt/sources.list:

deb-src http://ports.ubuntu.com/ubuntu-ports focal-updates main restricted

Update the package database:

apt update

Get the kernel source package, as root in some place where you want it. Alternatively replace $(uname -r) with the version you want. This is probably easiest to do on the target:

apt-get source linux-image-$(uname -r)

If this is on a target, copy it to a dev machine.

Over on the dev machine, hack up your kernel as you please. Then in debian.raspi/changelog, edit the first version number from something like this:

linux-raspi (5.4.0-1019.21) focal; urgency=medium

to something like this:

linux-raspi (5.4.0-1019.21+g34950~20200925) focal; urgency=medium

Note that CONFIG_LOCALVERSION will break the Ubuntu scripts, and EXTRAVERSION in the highest level makefile doesn’t do anything interesting.

Set some environment variables:

export $(dpkg-architecture -aarm64); export CROSS_COMPILE=aarch64-linux-gnu-

Now change into the root directory of the source tree and clean the build area:

fakeroot debian/rules clean

Kick off a menuconfig session with script:

fakeroot debian/rules editconfigs

menuconfig insists on running once each for 32 and 64 bit builds of kernel.

Now build the kernel and associated packages. We skip checks that are likely to break because of a changed list of modules:

fakeroot debian/rules binary skipmodule=true skipabi=true

This will result in the following .deb packages being created in the level ABOVE the kernel source tree:

linux-buildinfo-5.4.0-1019-raspi_5.4.0-1019.21+g34950~20200925_arm64.deb
linux-headers-5.4.0-1019-raspi_5.4.0-1019.21+g34950~20200925_arm64.deb
linux-image-5.4.0-1019-raspi_5.4.0-1019.21+g34950~20200925_arm64.deb
linux-modules-5.4.0-1019-raspi_5.4.0-1019.21+g34950~20200925_arm64.deb
linux-raspi-headers-5.4.0-1019_5.4.0-1019.21+g34950~20200925_arm64.deb

After copying to the target, each of the relevant packages may be installed there with dpkg:

dpkg -i linux-headers-5.4.0-1019-raspi_5.4.0-1019.21+g34950~20200925_arm64.deb
dpkg -i linux-image-5.4.0-1019-raspi_5.4.0-1019.21+g34950~20200925_arm64.deb
dpkg -i linux-modules-5.4.0-1019-raspi_5.4.0-1019.21+g34950~20200925_arm64.deb
dpkg -i linux-raspi-headers-5.4.0-1019_5.4.0-1019.21+g34950~20200925_arm64.deb

[Tutorial] Installing OpenCV on Raspberry Pi 4B with Ubuntu 20.04

This guide will show how to install OpenCV 4.5.0 (latest) on Raspberry Pi 4B running Ubuntu Server 20.04, where architecture is ARM64 (aarch64) – which is unusal part.

but installing procedure never changes – thanks to CMake. We can build own library within Raspberry Pi with following tutorials.

OpenCV-aarch64

This is a guide to natively install OpenCV on aarch64/arm64 devices (Updated 2020-12-13, by @LimeOrangePie)

Pre-requisites

Your aarch64 device should have Ubuntu/Debian/Armbian OS flashed on it.

Steps

  1. Install dependencies
sudo apt-get install python3-dev python3-pip python3-numpy

sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev  libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev protobuf-compiler libgflags-dev libgoogle-glog-dev libblas-dev libhdf5-serial-dev liblmdb-dev libleveldb-dev liblapack-dev libsnappy-dev libprotobuf-dev libopenblas-dev libgtk2.0-dev libboost-dev libboost-all-dev libeigen3-dev libatlas-base-dev libne10-10 libne10-dev

pip3 install neon

sudo apt-get install libneon27-dev

sudo apt-get install libneon27-gnutls-dev
  1. Download Source
cd ~/

git clone https://github.com/opencv/opencv.git -b 4.5.0 --single-branch

git clone https://github.com/opencv/opencv_contrib.git -b 4.5.0 --single-branch
  1. Configuring OpenCV using cmake:

Put your username in place of [username] below for the path to opencv_contrib/modules

mkdir opencv_build

cd opencv_build

cmake -D CMAKE_BUILD_TYPE=RELEASE -D ENABLE_NEON=ON -D ENABLE_TBB=ON -D ENABLE_IPP=ON -D ENABLE_VFVP3=ON -D WITH_OPENMP=ON -D WITH_CSTRIPES=ON -D WITH_OPENCL=ON -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules/ ../opencv
  1. Compilation:
make -j${nproc}

sudo make install
  1. Testing:
python3
>>import cv2
>>

Repository: https://github.com/jungin500/OpenCV-aarch64

Original Repository: https://github.com/huzz/OpenCV-aarch64

(Reference) Build 64-bit kernel for Raspberry Pi 3, using native tools

Reference

Guide on how to build a 64-bit kernel for the Raspberry Pi 3 & 3+ boards, on device, using native 64-bit cross-compilation tools. Using kernel branch 4.14 at time of writing.

The SoC on the Raspberry Pi 3 & 3+ supports 64-bit ARM mode, unfortunately raspbian and the foundation does not provide 64-bit support or userland even if they are advertising the Pi 3 as a 64-bit platform.

There are 3 ways to get a 64-bit kernel compiled:

  1. Native build on another 64-bit ARM platform
  2. Cross-compilation on another platform
  3. Cross-compilation on the Pi 3 itself

This tutorial will explain how to do option number 3. (And will actually work just fine for option number 2 as they are pretty much the same).

Note: The tools should work just fine for building a 64-bit kernel for the Raspberry Pi 4 too. Unfortunately the author does not have Pi 4 at this time so kernel configuration, building and booting has not been tested and therefor has been omitted for now.

Note: You will need plenty of space when building as the sources and build results for both the tools and kernel takes quite a lot of space. Also a heat sink is highly recommended if building in parallel.

Time: Speed is relative. The Raspberry Pi 3 is fast or slow, depending on what you compare it to. Even so, it will take a while to build everything, for example C-compiler only gcc will about 85 minutes to build using non-parallel make on a Pi 3.

Install essential build tools and development packages

As we need to build the tools we need, that is aarch64 binutils and gcc, we need to install the required build tools first. Start by first installing required dependencies for compilation of these tools:

sudo apt-get install build-essential libgmp-dev libmpfr-dev libmpc-dev libisl-dev libncurses5-dev bc git-core bison flex

Build the cross compilation tools

To be able to cross-compile we need to build a couple of tools ourselves as they are not provided. These are aarch64 versions of binutils (assembler, linker) and gcc (C compiler). We will install these tools in their own prefix or path,

/opt/aarch64

We will also use out-of-source build directories to keep the sources clean. This is handy if you need to re-configure, re-build or start over without needing to clean the source tree.

Build and install Binutils

We will start with building the low-level tool, binutils. Binutils is basically an assembler and linker.

Download the latest binutils, (Tested with 2.29.1 at time of writing, feel free to try any later versions (2.30 is reported not to work!) when available)

wget https://ftp.gnu.org/gnu/binutils/binutils-2.29.1.tar.bz2

Untar the binutils archive

tar xf binutils-2.29.1.tar.bz2

Configure build and install

mkdir binutils-obj
cd binutils-obj
../binutils-2.29.1/configure --prefix=/opt/aarch64 --target=aarch64-linux-gnu --disable-nls
make -j4
sudo make install

Binutils is now installed, to be able to use it directly, add “/opt/aarch64/bin/” to your path:

export PATH=$PATH:/opt/aarch64/bin/

Build and install GCC

Next up is gcc, the C compiler. We will build a minimal compiler for C only and no userland support. This is enough to get a aarch64 kernel compiled.

Download latest stable gcc (Tested with 6.4.0 at time of writing, feel free to try any later version when available):

wget https://ftp.gnu.org/gnu/gcc/gcc-6.4.0/gcc-6.4.0.tar.xz

Untar the gcc archive

tar xf gcc-6.4.0.tar.xz

Next configure gcc and build gcc. We will configure the build for only a minimal C compiler, that is enough for building a kernel.

mkdir gcc-out
cd gcc-out
../gcc-6.4.0/configure --prefix=/opt/aarch64 --target=aarch64-linux-gnu --with-newlib --without-headers \
 --disable-nls --disable-shared --disable-threads --disable-libssp --disable-decimal-float \
 --disable-libquadmath --disable-libvtv --disable-libgomp --disable-libatomic \
 --enable-languages=c
make all-gcc -j4
sudo make install-gcc

Test that the cross gcc runs ok, run:

aarch64-linux-gnu-gcc -v

It should report something close to this is everything is ok:

Using built-in specs.

COLLECT_GCC=aarch64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/opt/aarch64/libexec/gcc/aarch64-linux-gnu/6.4.0/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../gcc-6.4.0/configure --prefix=/opt/aarch64 --target=aarch64-linux-gnu --with-newlib --without-headers --disable-shared --enable-languages=c
Thread model: posix
gcc version 6.4.0 (GCC)

If all is well, then you can continue to building the kernel itself!

Optional: libgcc

The C-only compiler we built above is enough for building a Linux kernel and is enough for this guide. But, if you would like to for example build and use u-boot, then you will need to build libgcc, a static library that contains shared code and various helper functions. Building and installing libgcc is fortunately easy, just do the following after building gcc:

make all-target-libgcc
make install-target-libgcc

Build the Linux kernel

Now you have a toolchain that is able to build 64-bit ARM kernels. So the next step is to download the Raspberry Pi kernel sources, configure them and build a 64-bit kernel and modules.

Download Linux kernel sources

Get the most up to date stable branch kernel sources (4.14 branch at time of writing) directly from the Raspberry Pi GitHub repository with

git clone --depth=1 -b rpi-4.14.y https://github.com/raspberrypi/linux.git
Keeping sources fresh

The Linux kernel is a moving target and evolves almost daily. To keep updated with latest changes, run the following command in the directory you checked out above:

git pull

Configure Linux kernel for 64-bit Raspberry Pi 3

We use output directory for kernel build so we can use the same source tree for other configuration (32-bit for example)

mkdir kernel-out
cd linux
make O=../kernel-out/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-  bcmrpi3_defconfig

The kernel build is now configured with a default configuration for a 64-bit Raspberry Pi kernel.

In case you need to customize the configuration (Add support for some specific hardware, trim out things you don't need or otherwise mess around with the configuration) run

make O=../kernel-out/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig

and adjust the configuration for your needs.

Build the kernel and modules

Next build the kernel and modules with:

make -j4 O=../kernel-out/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

If all goes well, as it should, you should now have a 64-bit kernel, modules and device tree built.

Keep up with kernel development

The Linux kernel evolves and so does the Raspberry Pi kernel too. To keep up with development changes you can ask git to download changes to your kernel source tree. To do that run the following command in the kernel source locations:

git pull

This will download any changes made to the kernel source.

Update kernel configuration

After pulling in changes I personally like to always run, just in case:

make -j4 O=../kernel-out/ ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- oldconfig

Next step:

Booting 64-bit kernel on Raspberry Pi 3

Changelog:

11/04/2018 – 13:15

  • Update to 4.14