In order to use microcom from busybox, issue:
microcom -s 9600 /dev/ttyAMA1
where -s sets the baudrate and /dev/ttyAMA1 sets the used device.
Break character is crtl+x
My Embedded Linux XP
quarta-feira, 20 de junho de 2018
terça-feira, 12 de junho de 2018
Changing IP address in a ArmV7l 3.18.20 embedded Linux distribution
To change the ip address in a ArmV7l 3.18.20 embedded Linux distro, follow these commands:
- In the embedded equip, check the inferface name using ifconfig. If you're changing the cabled interface, it should be named as eth0;
- Change the ip address with: sudo ifconfig eth0 192.168.201.105 netmask 255.255.255.0. Change the ip and netmask as needed;
- Display (route -n) and copy the gateway address of a computer with internet connection;
- Add the gateway to the device under configuration by using sudo route add default gw 192.168.201.253 eth0;
- Test the connection via ping google.com
- ifconfig
- ifconfig eth0 192.168.201.175 netmask 255.255.255.0
- (in the configured device) route -n
- route add default gw 192.168.201.253 eth0
- ping google.com
quinta-feira, 12 de fevereiro de 2015
offtopic: Running JLinkGDBServer + arm-none-eabi-gdb
Step 1) Run JLinkGDBServer and set device
(in JLinkGDBServer /bin folder, issue:) ./JLinkGDBServer -device STM32F103CB
Step 2) In a separated terminal, run arm-none-eabi-gdb and load .elf file
(in toolchain's /bin folder, issue:) ./arm-none-eabi-gdb file myprogram.elf
Step 3) In the newly opened arm-none-eabi-gdb prompt, issue the following cmds:
target remote: 2331
load
monitor reset
continue
Those steps are more than enough to verify if debugger is working properly. Eventual adaptations (JTAG, SWD) must be done if needed.
Reference: https://community.freescale.com/thread/317201
sexta-feira, 6 de fevereiro de 2015
How to use can bus in IMX6
Step 1) After configuring yocto, go to "edm1-cf-imx6_edm1-fairy_yocto-1.5-qt5_source_20140714/edm_yocto_qt5-20140714/build" folder and issue
bitbake libsocket2
bitbake canutils
Step 2) It will be created 9 rpm package in edm1-cf-imx6_edm1-fairy_yocto-1.5-qt5_source_20140714/edm_yocto_qt5-20140714/build/tmp/deploy/rpm/cortexa9hf_vfp_neon
a) canutils-4.0.6-r0.cortexa9hf_vfp_neon.rpm
b) canutils-dbg-4.0.6-r0.cortexa9hf_vfp_neon.rpm
c) canutils-dev-4.0.6-r0.cortexa9hf_vfp_neon.rpm
d) canutils-doc-4.0.6-r0.cortexa9hf_vfp_neon.rpm
e) libsocketcan2-0.0.9-r0.cortexa9hf_vfp_neon.rpm
f) libsocketcan-dbg-0.0.9-r0.cortexa9hf_vfp_neon.rpm
g) libsocketcan-dev-0.0.9-r0.cortexa9hf_vfp_neon.rpm
h) libsocketcan-doc-0.0.9-r0.cortexa9hf_vfp_neon.rpm
i) libsocketcan-staticdev-0.0.9-r0.cortexa9hf_vfp_neon.rpm
Step 3) Transfer packages a) and e) to IHM
Step 4) Install packages a) and e) in IHM
rpm -ivh canutils-4.0.6-r0.cortexa9hf_vfp_neon.rpm
rpm -ivh libsocketcan2-0.0.9-r0.cortexa9hf_vfp_neon.rpm
Step 5) canconfig can0 stop
Step 6) canconfig can0 bitrate 125000 sample-point 0.75
Step 7) canconfig start
Step 8) ifconfig can0 up
Step 9) cansend can0 -e -v -i 0x1CFEEEAB 01 12 23 45 56 67 78 89 90
bitbake libsocket2
bitbake canutils
Step 2) It will be created 9 rpm package in edm1-cf-imx6_edm1-fairy_yocto-1.5-qt5_source_20140714/edm_yocto_qt5-20140714/build/tmp/deploy/rpm/cortexa9hf_vfp_neon
a) canutils-4.0.6-r0.cortexa9hf_vfp_neon.rpm
b) canutils-dbg-4.0.6-r0.cortexa9hf_vfp_neon.rpm
c) canutils-dev-4.0.6-r0.cortexa9hf_vfp_neon.rpm
d) canutils-doc-4.0.6-r0.cortexa9hf_vfp_neon.rpm
e) libsocketcan2-0.0.9-r0.cortexa9hf_vfp_neon.rpm
f) libsocketcan-dbg-0.0.9-r0.cortexa9hf_vfp_neon.rpm
g) libsocketcan-dev-0.0.9-r0.cortexa9hf_vfp_neon.rpm
h) libsocketcan-doc-0.0.9-r0.cortexa9hf_vfp_neon.rpm
i) libsocketcan-staticdev-0.0.9-r0.cortexa9hf_vfp_neon.rpm
Step 3) Transfer packages a) and e) to IHM
Step 4) Install packages a) and e) in IHM
rpm -ivh canutils-4.0.6-r0.cortexa9hf_vfp_neon.rpm
rpm -ivh libsocketcan2-0.0.9-r0.cortexa9hf_vfp_neon.rpm
Step 5) canconfig can0 stop
Step 6) canconfig can0 bitrate 125000 sample-point 0.75
Step 7) canconfig start
Step 8) ifconfig can0 up
Step 9) cansend can0 -e -v -i 0x1CFEEEAB 01 12 23 45 56 67 78 89 90
quarta-feira, 4 de fevereiro de 2015
How to create a script to run in imx6 startup
Edit 1. changed startup and install scripts
Step 1) vim startup.sh
Step 2) Copy the following code and paste:
#!/bin/sh
main(){
install_modules
configure_modules
}
install_modules(){
install_pca9555
}
configure_modules(){
configure_pca9555
}
install_pca9555(){
insmod /home/root/Drivers/PCA953x/gpio-pca953x.ko
echo pca9555 0x27 > /sys/bus/i2c/devices/i2c-2/new_device
}
configure_pca9555(){
echo "248" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio248/direction
echo "0" > /sys/class/gpio/gpio248/value
sleep 1
echo "1" > /sys/class/gpio/gpio248/value
echo "240" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio240/direction
echo "241" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio241/direction
echo "242" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio242/direction
echo "243" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio243/direction
echo "244" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio244/direction
echo "245" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio245/direction
echo "246" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio246/direction
echo "247" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio247/direction
}
main
exit 0
Step 1) vim startup.sh
Step 2) Copy the following code and paste:
#!/bin/sh
main(){
install_modules
configure_modules
}
install_modules(){
install_pca9555
}
configure_modules(){
configure_pca9555
}
install_pca9555(){
insmod /home/root/Drivers/PCA953x/gpio-pca953x.ko
echo pca9555 0x27 > /sys/bus/i2c/devices/i2c-2/new_device
}
configure_pca9555(){
echo "248" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio248/direction
echo "0" > /sys/class/gpio/gpio248/value
sleep 1
echo "1" > /sys/class/gpio/gpio248/value
echo "240" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio240/direction
echo "241" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio241/direction
echo "242" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio242/direction
echo "243" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio243/direction
echo "244" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio244/direction
echo "245" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio245/direction
echo "246" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio246/direction
echo "247" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio247/direction
}
main
exit 0
Step 3) vim install.sh
Step 4) Copy the following code and paste:
#!/bin/sh
case $1 in
install)
echo "Installing startup modules"
cp ./startup.sh /etc/init.d
update-rc.d startup.sh start 20 0 1 2 3 4 5 6 .
;;
remove)
echo "Removing startup modules"
sudo update-rc.d -f startup.sh remove
echo 240 > /sys/class/gpio/unexport
echo 241 > /sys/class/gpio/unexport
echo 242 > /sys/class/gpio/unexport
echo 243 > /sys/class/gpio/unexport
echo 244 > /sys/class/gpio/unexport
echo 245 > /sys/class/gpio/unexport
echo 246 > /sys/class/gpio/unexport
echo 247 > /sys/class/gpio/unexport
echo 248 > /sys/class/gpio/unexport
rmmod gpio-pca953x
;;
*)
echo "Usage install or remove"
exit 1
;;
esac
exit 0
case $1 in
install)
echo "Installing startup modules"
cp ./startup.sh /etc/init.d
update-rc.d startup.sh start 20 0 1 2 3 4 5 6 .
;;
remove)
echo "Removing startup modules"
sudo update-rc.d -f startup.sh remove
echo 240 > /sys/class/gpio/unexport
echo 241 > /sys/class/gpio/unexport
echo 242 > /sys/class/gpio/unexport
echo 243 > /sys/class/gpio/unexport
echo 244 > /sys/class/gpio/unexport
echo 245 > /sys/class/gpio/unexport
echo 246 > /sys/class/gpio/unexport
echo 247 > /sys/class/gpio/unexport
echo 248 > /sys/class/gpio/unexport
rmmod gpio-pca953x
;;
*)
echo "Usage install or remove"
exit 1
;;
esac
exit 0
Step 5) chmod +x install.sh
Step 6) chmod +x startup.sh
Step 7) Reboot system.
Step 8) Check if everything is ok by issuing ls /sys/class/gpio
User should see gpiochip240 and gpio240-248 instantiated.
terça-feira, 3 de fevereiro de 2015
Creating a complete cross-compiler Makefile and cross-compiling a simple kernel module
Edit: When checking the statistics of posts, I saw people are actually reading my blog - in special this post. Due to the feedback given, I decided to write better and further explanatory information. Hope you can find this useful. Fávero
Obs: There are several commands enclosed by "". When typing in your terminal, just use the string, not the "". Example: "dmesg | tail -2" - when typing, use dmesg | tail -2.
Step 1) First of all, lets go to our home folder. To do so, type "cd". This will be our working directory for now.
Step 2) Create a folder called Drivers:
mkdir -p ./Documents/Drivers.
Step 3) Create a folder called "Aloha" inside new created folder "Drivers":
mkdir -p ./Documents/Drivers/Aloha
Step 4) Navigate to the new created folder:
cd ./Documents/Drivers/Aloha
Step 5) Create a file, using Vim, called aloha.c:
vim aloha.c
If you don't have vim, you can install it (using "sudo apt-get install vim") or you can use gedit to create and edite the file (to do so, use "gedit aloha.c" instead of the "vim aloha.c" command).
Step 6) Copy the text bellow to aloha.c and close this file. Basically, this is the core of a source driver file.
A brief explanation: When the driver is registered in your system, it will run this file. During the modules's initialization, the function "hello_init()" will be called and the message "Hello world!" will be showed in your system's messages.
Similarly, when unregistering the module, the function "hello_exit()" will be called.
<1> is the message's priority.
Step 7) Create a file name "Makefile":
vim Makefile
Step 8) Copy the text bellow to Makefile and close this file.
Obs: There are many ways to do this kind of Makefile, I'm proposing one of them. Surelly, there are far more code-capable people out there who can make this code even more general.
Basically, what it does is:
A) Define some variables:
- ARQ is a variable containing the name of the compiled architecture;
- COMPILER is a variable containing the direction to the toolchain's compiler. Note that is should point to /bin folder and you should suppress "-gcc" in the end of "arm-none-linux-gnueabi"
- KERNELVERSION is a variable containing the direction of the kernel's compiled source file. THIS IS REALLY IMPORTANT. When getting your kernel source file's, you should issue some make commands. To do so, I suggest you to search Google for "how to compile kernel's source files".
-KERNELSOURCE is a variable containing the direction of host's kernel version source files.
-PWD is a variable containing the direction of the working directory. What actually PWD contains is the result of the shell command "pwd". If you're curious, open a new shell instance and type pwd and see the magic happens.
B) Define make commands:
- 2pc: Used when you want to compile the module to work in your host's kernel.
- 2ihm: Used when you want to cross-compile the module to another architecture.
- clean2pc: Clean your pc's compiled files.
- clean2ihm: Clean your ihm's compiled files.
Step 9) Run "make 2pc" to compile the module using your hosts' kernel source files OR run "make 2ihm" to cross-compile the module using the other platform's kernel source files
OBS: If everything went OK, issue a "ls" in this folder. You'll be able to see "aloha.ko" file. This file is the compiled module. To install it in your pc (you have used make 2pc), use "insmod aloha.ko". To remove, "rsmod aloha.ko". To check if it worked, use "dmesg | tail -2". You'll see "Hello World! and Bye, cruel world" messages.
Step 10) If needed, to clean the cross-compiled's module, use make clean2ihm. To clean the host's module, use make clean2pc. Always issue clean before changing platform.
Obs: There are several commands enclosed by "". When typing in your terminal, just use the string, not the "". Example: "dmesg | tail -2" - when typing, use dmesg | tail -2.
Step 1) First of all, lets go to our home folder. To do so, type "cd". This will be our working directory for now.
Step 2) Create a folder called Drivers:
mkdir -p ./Documents/Drivers.
Step 3) Create a folder called "Aloha" inside new created folder "Drivers":
mkdir -p ./Documents/Drivers/Aloha
Step 4) Navigate to the new created folder:
cd ./Documents/Drivers/Aloha
Step 5) Create a file, using Vim, called aloha.c:
vim aloha.c
If you don't have vim, you can install it (using "sudo apt-get install vim") or you can use gedit to create and edite the file (to do so, use "gedit aloha.c" instead of the "vim aloha.c" command).
Step 6) Copy the text bellow to aloha.c and close this file. Basically, this is the core of a source driver file.
A brief explanation: When the driver is registered in your system, it will run this file. During the modules's initialization, the function "hello_init()" will be called and the message "Hello world!" will be showed in your system's messages.
Similarly, when unregistering the module, the function "hello_exit()" will be called.
<1> is the message's priority.
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void) {
printk("<1> Hello world!\n");
return 0;
}
static void hello_exit(void) {
printk("<1> Bye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
|
Step 7) Create a file name "Makefile":
vim Makefile
Step 8) Copy the text bellow to Makefile and close this file.
Obs: There are many ways to do this kind of Makefile, I'm proposing one of them. Surelly, there are far more code-capable people out there who can make this code even more general.
Basically, what it does is:
A) Define some variables:
- ARQ is a variable containing the name of the compiled architecture;
- COMPILER is a variable containing the direction to the toolchain's compiler. Note that is should point to /bin folder and you should suppress "-gcc" in the end of "arm-none-linux-gnueabi"
- KERNELVERSION is a variable containing the direction of the kernel's compiled source file. THIS IS REALLY IMPORTANT. When getting your kernel source file's, you should issue some make commands. To do so, I suggest you to search Google for "how to compile kernel's source files".
-KERNELSOURCE is a variable containing the direction of host's kernel version source files.
-PWD is a variable containing the direction of the working directory. What actually PWD contains is the result of the shell command "pwd". If you're curious, open a new shell instance and type pwd and see the magic happens.
B) Define make commands:
- 2pc: Used when you want to compile the module to work in your host's kernel.
- 2ihm: Used when you want to cross-compile the module to another architecture.
- clean2pc: Clean your pc's compiled files.
- clean2ihm: Clean your ihm's compiled files.
# Makefile
# Autor: Fávero Santos # Property: Quantum Eletrônica # Year: 2015 # Description: A model Makefile for future consultations # Chooses the used architecture ARQ:=arm #Chooses the used compiler COMPILER:=/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-none-linux-gnueabi- #Chooses the kernel sources for compilation KERNELVERSION:=/home/favero/Documents/IHM_imx6/KSource3/linux-3.0.35.imx-4.1.0-edm KERNELSOURCE:=/lib/modules/`uname -r`/build PWD:=$(shell pwd) # Name of the compiled file obj-m := aloha.o 2pc: $(MAKE) -C $(KERNELSOURCE) M=$(PWD) modules clean2pc: $(MAKE) -C $(KERNELSOURCE) M=$(PWD) clean 2ihm: $(MAKE) -C $(KERNELVERSION) ARCH=$(ARQ) CROSS_COMPILE=$(COMPILER) M=$(PWD) modules clean2ihm: $(MAKE) -C $(KERNELVERSION) M=$(PWD) clean |
Step 9) Run "make 2pc" to compile the module using your hosts' kernel source files OR run "make 2ihm" to cross-compile the module using the other platform's kernel source files
OBS: If everything went OK, issue a "ls" in this folder. You'll be able to see "aloha.ko" file. This file is the compiled module. To install it in your pc (you have used make 2pc), use "insmod aloha.ko". To remove, "rsmod aloha.ko". To check if it worked, use "dmesg | tail -2". You'll see "Hello World! and Bye, cruel world" messages.
Step 10) If needed, to clean the cross-compiled's module, use make clean2ihm. To clean the host's module, use make clean2pc. Always issue clean before changing platform.
Instatiating PCA9555 gpio expander in a imx-i2c bus
Obs. 1. You should get the latest PCA953x source file, found here, and compile it as a module (check all dependencies when doing it).
Edit: If needed, check Creating a complete cross-compile Makefile
Step 1) i2cdetect -l
Shows available i2c buses on the processor
Step 2) i2cdetect -y 2
Shows I2C devices' addresses connected to the 2 bus
Let's say address 0x27 is used by an unknown device
Step 3) i2cdump 2 0x27
Show the content of the device's register
If the amount and content of registers are the same as specified in the device's datasheet, the device on the address 0x27 is the one we are looking for.
Step 4) insmod pca953x
Install pca953x module
Step 5) echo pca9555 0x27 > /sys/bus/i2c/devices/i2c-2/new_device
Creates a device called pca9555 (adress 0x27) in i2c-2 bus
Step 6) It is possible to check if the installation went ok by issuing
dmesg | tail - 2
Step 7) A new gpio, called gpiochip240, should appear in /sys/class/gpio. Issue
cd /sys/class/gpio/gpiochip240 to verify
Step 8) The address 255 is refereed as I1.7 (base address is 240). So if you want to control, let's say, I1.0, you should use address 248.
Issue: echo "248" > /sys/class/gpio/export to create a gpio248 in /sys/class/gpio
Step 9) In order to configure as an output, issue echo "out" > /sys/class/gpio/gpio248/direction
Step 10) To control the output level, issue echo "1" > /sys/class/gpio/gpio248/value OR echo "0" > /sys/class/gpio/gpio248/value
References:
1) http://www.fabhub.net/entry.php?2184-PCA9535-and-the-Raspberry-Pi&goto=next
2) ftp://ftp.ts.fujitsu.com/pub/mainboard-oem-sales/Products/Mainboards/Industrial&ExtendedLifetime/D323x-S/IndustrialTools_D323x-S/Linux_SystemMonitoring&Watchdog&GPIO/GPIO_PCA9554a_Linux_X86-X64_HowTo.txt
Edit: If needed, check Creating a complete cross-compile Makefile
Step 1) i2cdetect -l
Shows available i2c buses on the processor
Shows I2C devices' addresses connected to the 2 bus
Step 3) i2cdump 2 0x27
Show the content of the device's register
If the amount and content of registers are the same as specified in the device's datasheet, the device on the address 0x27 is the one we are looking for.
Install pca953x module
Step 5) echo pca9555 0x27 > /sys/bus/i2c/devices/i2c-2/new_device
Creates a device called pca9555 (adress 0x27) in i2c-2 bus
Step 6) It is possible to check if the installation went ok by issuing
dmesg | tail - 2
Step 7) A new gpio, called gpiochip240, should appear in /sys/class/gpio. Issue
cd /sys/class/gpio/gpiochip240 to verify
Step 8) The address 255 is refereed as I1.7 (base address is 240). So if you want to control, let's say, I1.0, you should use address 248.
Issue: echo "248" > /sys/class/gpio/export to create a gpio248 in /sys/class/gpio
Step 9) In order to configure as an output, issue echo "out" > /sys/class/gpio/gpio248/direction
Step 10) To control the output level, issue echo "1" > /sys/class/gpio/gpio248/value OR echo "0" > /sys/class/gpio/gpio248/value
References:
1) http://www.fabhub.net/entry.php?2184-PCA9535-and-the-Raspberry-Pi&goto=next
2) ftp://ftp.ts.fujitsu.com/pub/mainboard-oem-sales/Products/Mainboards/Industrial&ExtendedLifetime/D323x-S/IndustrialTools_D323x-S/Linux_SystemMonitoring&Watchdog&GPIO/GPIO_PCA9554a_Linux_X86-X64_HowTo.txt
Assinar:
Postagens (Atom)