2013年12月25日 星期三

Build nrf9160dk projects on Zephyr OS and SEGGER Embedded Studio

Zephyr OS is RTOS - The Application bind with kernel and drivers into a image

##########################Zephyr Project 2.5.99###############################
################for console build projects
################
Refer to:
https://infocenter.nordicsemi.com/pdf/nRF9160_DK_HW_User_Guide_v1.0.pdf
https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/getting_started/index.html
http://fatalfeel.blogspot.com/2019/12/ai-with-cuda-install-step-and-yolov3-in.html
https://apt.kitware.com/
https://docs.zephyrproject.org/latest/boards/arm/nrf9160dk_nrf9160/doc/index.html

ubuntu 16.04 default python3 is 3.5
ubuntu 18.04 default python3 is 3.6
install python 3.7.9 + pip3

1. install python 3.7
http://fatalfeel.blogspot.com/2019/12/ai-with-cuda-install-step-and-yolov3-in.html
search install python 3.7 + pip3 + labelimg + yolov3
follow step 1~9

2.
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null

a. For Ubuntu Focal Fossa (20.04)
sudo apt-add-repository 'deb httpshttps://github.com/NordicSemiconductor/pc-nrfconnect-ppk://apt.kitware.com/ubuntu/ focal main'     

b. For Ubuntu Bionic Beaver (18.04)
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'

c. For Ubuntu Xenial Xerus (16.04)
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ xenial main'

sudo apt update
#If show NO_PUBKEY DE19EB17684BA42D
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DE19EB17684BA42D
sudo apt install cmake cmake-qt-gui
#cmake-qt-gui can read CMakeCache.txt easily

3.
sudo apt install --no-install-recommends git ninja-build gperf ccache dfu-util device-tree-compiler wget xz-utils file make gcc gcc-multilib g++-multilib libsdl2-dev

4.
pip3 install --force-reinstall --user -U west
gedit /etc/environment
#add in PATH line
/usr/lib/python3.7/site-packages/bin

5. install device name
cd ~
wget https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.12.3/zephyr-sdk-0.12.3-x86_64-linux-setup.run
chmod 755 ./zephyr-sdk-0.12.3-x86_64-linux-setup.run
./zephyr-sdk-0.12.3-x86_64-linux-setup.run -- -d /opt/zephyr-sdk-0.12.3
sudo cp /opt/zephyr-sdk-0.12.3/sysroots/x86_64-pokysdk-linux/usr/share/openocd/contrib/60-openocd.rules /etc/udev/rules.d
sudo udevadm control --reload

6. install command line tool (use gdown better than wget)
#check version in https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Command-Line-Tools/Download
sudo apt install gdebi
pip3 install gdown
cd ~
gdown https://www.nordicsemi.com/-/media/Software-and-other-downloads/Desktop-software/nRF-command-line-tools/sw/Versions-10-x-x/10-12-1/nRFCommandLineTools10121Linuxamd64.tar.gz
mkdir -p ./nRFCommandLineTools
tar -h -zxf ./nRFCommandLineTools10121Linuxamd64.tar.gz -C ./nRFCommandLineTools
cd nRFCommandLineTools
gdebi ./JLink_Linux_V688a_x86_64.deb
gdebi ./nRF-Command-Line-Tools_10_12_1_Linux-amd64.deb

gedit /etc/environment
#add in PATH
/opt/nrfjprog/nrfjprog
/opt/mergehex/mergehex
or
sudo ln -sf /opt/nrfjprog/nrfjprog /usr/local/bin/nrfjprog
sudo ln -sf /opt/mergehex/mergehex /usr/local/bin/mergehex

reboot

#test pass
west --version
nrfjprog --version

7.
west init --manifest-rev=master ./zephyrproject
https://github.com/NordicSemiconductor/pc-nrfconnect-ppk
cd ./zephyrproject
west update
west zephyr-export
pip3 install --user -r ./zephyr/scripts/requirements.txt

8. build a sample (it will auto find /opt/zephyr-sdk-0.12.3, no need set bin path)
#search board name /root/zephyrproject/zephyr/boards/arm/nrf9160dk_nrf9160/Kconfig.board
cd ~/zephyrproject/zephyr
west build -p auto -b nrf9160dk_nrf9160ns samples/basic/blinky
(if error you can remove ~/zephyrproject/zephyr/build and rebuild)

west flash

################nRF Connect SDK 1.5.1######################
################SEGGER Embedded Studio IDE build projects
################
Referto:
https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_installing.html

1.preinstall
same as Zephyr Project 2.5.99 step 1 to 14

2.
mkdir -p /opt/gn
wget -O gn.zip https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest
unzip gn.zip -d /opt/gn

3.
gedit /etc/environment
#add in PATH
/opt/gn

4. You must install version is [9-2019-q4-major] of the GNU Arm Embedded Toolchain.
gdown https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2

tar -h -vxf ./gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 -C /opt

5.
gedit /etc/environment
#add in the last
ZEPHYR_TOOLCHAIN_VARIANT="gnuarmemb"
GNUARMEMB_TOOLCHAIN_PATH="/opt/gcc-arm-none-eabi-9-2019-q4-major"

reboot

6.
mkdir -p ncs
cd ./ncs
west init -m https://github.com/nrfconnect/sdk-nrf --mr v1.5.1 ./
west update
west zephyr-export

7.
pip3 install --user -r zephyr/scripts/requirements.txt
pip3 install --user -r nrf/scripts/requirements.txt
pip3 install --user -r bootloader/mcuboot/scripts/requirements.txt

8. Install ses in root mode
cd ~
#check download link then get v534a
wget https://www.segger.com/downloads/embedded-studio/embeddedstudio_arm_nordic_linux_x64
--2022-09-18 00:31:59--  https://www.segger.com/downloads/embedded-studio/embeddedstudio_arm_nordic_linux_x64
Resolving www.segger.com (www.segger.com)... 194.245.121.208
Connecting to www.segger.com (www.segger.com)|194.245.121.208|:443...
HTTP request sent, awaiting response... 302 Found
Location: https://dl.a.segger.com/embedded-studio/EmbeddedStudio_ARM_Nordic_v568_linux_x64.tar.gz

#copy the location https://dl.a.segger.com/embedded-studio/ and change file name
wget https://dl.a.segger.com/embedded-studio/EmbeddedStudio_ARM_Nordic_v534a_linux_x64.tar.gz
tar -h -xvf ./EmbeddedStudio_ARM_Nordic_v534a_linux_x64.tar.gz -C /opt

ps: do not install arm_segger_embedded_studio_542a_linux_x64, it's bug
https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/gs_installing.html?highlight=zephyr_toolchain_variant%20gnuarmemb

9. #First run
/opt/arm_segger_embedded_studio_v534a_linux_x64_nordic/bin/emStudio
GNU ARM Embedded Toolchain Directory: /opt/gcc-arm-none-eabi-9-2019-q4-major
Projects = hello_word
board name = nrf9160dk_nrf9160ns

10.
https://license.segger.com/Nordic.cgi
#run
/opt/arm_segger_embedded_studio_v534a_linux_x64_nordic/bin/emStudio
Tools -> License Manager -> Activate Segger Embedded Studio
paste: License_SESxxxxxxxxxxxxxxxxxxxxxxxx

11. in emStudio
check toolchain directory
Tools -> options -> nrf connect
GNU ARM Embedded Toolchain Directory: /opt/gcc-arm-none-eabi-9-2019-q4-major
Zephyr Base: /root/ncs/zephyr

Tools -> options -> Building -> Echo Build Command Lines
[Yes]

Tools -> options -> Building -> Parallel Building Threads
[8]

Tools -> options -> Building -> Parallel Project Building
[Yes]

12.
right click [Solution hello_world] -> Rebuild
Done

13. get logs
connect target usb to PC
run
/opt/SEGGER/JLink_V688a/JLinkRTTViewerExe

14. main.c build in debug mode
gedit ~/ncs/zephyr/samples/basic/blinky/build_nrf9160dk_nrf9160ns/build.emProject
search c_only_additional_options in <project Name="app/libapp.a">
-Os change to -O0 and rebuild flash

PS: setting /etc/environment of stone's ubuntu OS
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/python3.7/site-packages/bin:/opt/nrfjprog/nrfjprog:/opt/mergehex/mergehex:/opt/gn"
PYTHONUSERBASE="/usr/lib/python3.7/site-packages"
ZEPHYR_TOOLCHAIN_VARIANT="gnuarmemb"
GNUARMEMB_TOOLCHAIN_PATH="/opt/gcc-arm-none-eabi-9-2019-q4-major"

############################firmware update#############################
############################
############################
refer to:
https://www.nordicsemi.com/Software-and-tools/Development-Kits/nRF9160-DK/Download#infotabs
https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Connect-for-desktop/Download
https://infocenter.nordicsemi.com/pdf/nRF_Connect_Programmer_User_Guide_v1.2.pdf

1.
from
https://nordicsemiconductor.github.io/pc-nrfconnect-docs/getting_started
https://nordicsemiconductor.github.io/pc-nrfconnect-docs/app_development
https://github.com/nodesource/distributions
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
apt install nodejs
npm -v
# 7.11.2
npm install -g npm
npm -v
# 7.13.0

2. easy install (AppImage version 3.3.1)
gdown https://www.nordicsemi.com/-/media/Software-and-other-downloads/Desktop-software/nRF-Connect-for-Desktop/3-3-1/nrfconnect331x8664.AppImage
chmod 755 ./nrfconnect331x8664.AppImage
./nrfconnect331x8664.AppImage
#if root account
./nrfconnect331x8664.AppImage --no-sandbox

3. manually install power profile
cd ~/.nrfconnect-apps/local
git clone --recursive https://github.com/NordicSemiconductor/pc-nrfconnect-ppk
(Tags: v2.1.0)
cd pc-nrfconnect-ppk
npm install
npm init -y  ###must do after install
npm run webpack
./nrfconnect331x8664.AppImage
#click
Power Profiler
local, v2.1.0

4. manually install programmer
git clone --recursive https://github.com/NordicSemiconductor/pc-nrfconnect-programmer
(Tags: v1.1.0)
cd pc-nrfconnect-programmer
npm install
npm init -y  ###must do after install
npm run webpack
./nrfconnect331x8664.AppImage
#click
Program a Nordic SoC with HEX files from nRF Connect
local, v1.1.0

5. (option install)
#check command
./nrfconnect331x8664.AppImage --appimage-help
./nrfconnect331x8664.AppImage --appimage-extract
mv ./squashfs-root /opt

/opt/squashfs-root/nrfconnect
#if you are in root mode add --no-sandbox
/opt/squashfs-root/nrfconnect --no-sandbox

install any app and create shortcut

if you are in root mode, right click shortcut select properties, add --no-sandbox in shortcut command
ex:
/opt/squashfs-root/nrfconnect --args --open-official-app pc-nrfconnect-programmer --source "official" --no-sandbox

6.
gdown https://www.nordicsemi.com/-/media/Software-and-other-downloads/Dev-Kits/nRF9160-DK/nRF9160-SiP-application-firmware/nrf9160dk_fw_2021-03-01_8e8c6089.zip
mkdir -p ~/pnrf9160dk_fw
unzip nrf9160dk_fw_2021-03-01_8e8c6089.zip -d ~/nrf9160dk_fw

img_app_bl/           Full application images, including bootloader. Updated only via debug probe.
img_fota_dfu_hex/     Application only. Use with nRFConnect for Desktop Programmer application.
img_fota_dfu_bin/     Application only. Binary format. For cloud update, mcumgr.
mfwnrf9160123.zip     Modem firmware, update via nRFConnect for Desktop Programmer application

7.
Set the PROG/DEBUG (SW10) switch on the nRF9160 DK to nRF91 (hardware)

8.run it, if you are in root mode add --no-sandbox
./nrfconnect361x8664.AppImage   
#or
./nrfconnect331x8664.AppImage --no-sandbox     
select programmer
select device select HEX
flash

ps:
If this doesn't work, try erasing the chip with nrfjprog first: nrfjprog -e/--erase. Hope this helps.

download:
1. EmbeddedStudio_ARM_Nordic_v534a_linux_x64.tar.gz
https://drive.google.com/file/d/1_01ZvdhHDCfNPh-EAtbWNAPEAjI7nxdX/view?usp=sharing
2. gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2
https://drive.google.com/file/d/1IK_2TCdbE950tjyhetHbeecNBEcpmHLs/view?usp=sharing
3. gn.zip
https://drive.google.com/file/d/1IvD6jGqVc1ZPjDkVSsdwEHunq2lR8-jp/view?usp=sharing

##############################Kernel config setting###########################
##############################
##############################
1. build debug version of zephyr and app, compile with -Og not -Os    
gedit ~/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_defconfig
#add in last line
CONFIG_DEBUG=y

#or

gedit ~/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160ns_defconfig
#add in last line
CONFIG_DEBUG=y
        
then open nrf connect project
2. theory explain:
~/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_defconfig
and
~/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160ns_defconfig
|
V
~/ncs/zephyr/boards/arm/nrf9160dk_nrf9160/Kconfig.defconfig
|
V
~/ncs/zephyr/Kconfig.zephyr
|
V
~/ncs/zephyr/CMakeLists.txt
|
V
~/ncs/zephyr/samples/hello_world/CMakeLists.txt
|
V
~/root/ncs/zephyr/samples/hello_world/build_nrf9160dk_nrf9160/zephyr/.config
|
V
~/ncs/zephyr/samples/hello_world/build_nrf9160dk_nrf9160/build.emProject

沒有留言:

張貼留言