Jump to content

UART with NanoPi M4


Jeffer

Recommended Posts

Hi, 

I'm currently woking on transmitting image data by UART connection with the NanoPi M4,

but I couldn't send data from '/dev/ttyS4',  which is offered as for UART connection.

I used pyserial in python to use UART but no change has been detected the pin #19 by the oscilloscope.

Do I have to enable the UART somehow?

If I can use UART with NanoPi M4, I would say this machine is so fantastic. 

Link to comment
Share on other sites

Thank you so much for the prompt reply and sorry, I really don't know why but after a while I tried and it succeeded.

 

Actually I have one more problem now...

I have tried to control the GPIO with wiringpi in python3 by following the procedure below.

http://wiki.friendlyarm.com/wiki/index.php/WiringPi-Python_for_RK3399#Install_WiringPi_in_Python3 

 

but the command, 

$ wget http://112.124.9.243:8888/wiringpi/friendlyelec-rk3399/wiringpi-2.44.4-py3.6-linux-aarch64.egg

doesn't work because my NanoPi M4 can't connect to the address 112.124.9.243:8888.

Is there anyway to control GPIO on NanoPi M4 such as RPi.GPIO?

Link to comment
Share on other sites

1 hour ago, Nao said:

but the command, 

$ wget http://112.124.9.243:8888/wiringpi/friendlyelec-rk3399/wiringpi-2.44.4-py3.6-linux-aarch64.egg

doesn't work because my NanoPi M4 can't connect to the address 112.124.9.243:8888.

Why ? Do you have issue with networking itself ? Can you "ping 112.124.9.243" ?

 

1 hour ago, Nao said:

Is there anyway to control GPIO on NanoPi M4 such as RPi.GPIO?

There are many ... But the simpliest, although a bit deprecated, is using "sysfs", here is an example which blinks the GPIO1_C2 :

echo 50 > /sys/class/gpio/export 
echo out > /sys/class/gpio/gpio50/direction 
echo 1 > /sys/class/gpio/gpio50/value 
echo 0 > /sys/class/gpio/gpio50/value 

 

Link to comment
Share on other sites

15 hours ago, martinayotte said:

echo 50 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio50/direction echo 1 > /sys/class/gpio/gpio50/value echo 0 > /sys/class/gpio/gpio50/value

Thank you, it worked!

I really appreciate it :)

 

15 hours ago, martinayotte said:

Why ? Do you have issue with networking itself ? Can you "ping 112.124.9.243" ?

I tried this now again, and it can connect to the server, think there were some miss-spelling.

 

And I thought I could finally use wiringpi, but after I tried to do

easy_install wiringpi-2.44.4-py3.6-linux-aarch64.egg

this raised error 

Traceback ....

 

..

File "/usr/local/lib/python3.6/dist-packages/setuptools-33-1.1.-py3.6.egg/setuptools/archive_util.py", Milne 11, in <module>

ImportError: cannot import name 'ContextualZipFile'

 

I googled this error and people say I just need to erase the word "ContextualZipFile" in the file of archive_util.py

But I couldn't find archive_util.py in the directory which was shown by the error message.

Now I don't know what to do with it...

 

Also I tried to use SPI with SpiDev, not in wiringpi, but I cannot use it....

not like UART, do I have to enable SPI somehow?? 

 

Link to comment
Share on other sites

4 hours ago, Nao said:

I googled this error and people say I just need to erase the word "ContextualZipFile" in the file of archive_util.py

In my case, it was installing without errors, but trying to use it at runtime gave me this error :

Oops: Unable to determine board revision from /proc/cpuinfo

So, this wiringpi library seems to be useless for now ...

 

4 hours ago, Nao said:

Also I tried to use SPI with SpiDev, not in wiringpi, but I cannot use it....

not like UART, do I have to enable SPI somehow??

Since we don't have "spidev" overlay yet for RK3399, you would need to manually edit the main DT to add it and making sure that UART4 is disabled, since SPI1 and UART4 sharing the same pins.

 

Link to comment
Share on other sites

On 12/29/2018 at 1:01 AM, martinayotte said:

So, this wiringpi library seems to be useless for now ...

yes, first I tried to use wiringpi with the default configuration but got the same error message, and followed the instruction given here 

http://wiki.friendlyarm.com/wiki/index.php/WiringPi-Python_for_RK3399

and at the final command, easy_install, I got error and stopped.

 

On 12/29/2018 at 1:01 AM, martinayotte said:

ince we don't have "spidev" overlay yet for RK3399, you would need to manually edit the main DT to add it and making sure that UART4 is disabled, since SPI1 and UART4 sharing the same pins.

I'm sorry but what is "main DT"?

I know UART4 and SPI shares some pins so I thought somehow I had to disable UART but I couldn't find how 

Link to comment
Share on other sites

2 hours ago, Nao said:

I'm sorry but what is "main DT"?

Main DT is the file located in /boot/dtb/rockchip/rk3399-nanopi4-rev01.dtb.

You need to decompile it into DTS as rk3399-nanopi4-rev01.dts, edit it to change ' status="okay"; ' into ' status="disabled"; ' for the UART.

Then, for the SPI, you need to turn it ON with ' status="okay"; ', but also need to add SPIDEV into this node :

        spi@ff1c0000 {
			[ ... more stuff here ... ]
            status = "okay";
			spidev {
                compatible = "spidev";
                status = "okay";
                reg = <0>;
                spi-max-frequency = <10000000>;
            };
        };

To get proper DTC compiler which support symbols, grab it from here : http://ftp.debian.org/debian/pool/main/d/device-tree-compiler/device-tree-compiler_1.4.7-3_arm64.deb

 

To decompile, the command would be :

 

dtc -@ -I dtb -O dts -o rk3399-nanopi4-rev00.dts /boot/dtb/rockchip/rk3399-nanopi4-rev01.dtb

 

After edit, recompile it using this command :

 

dtc -@ -I dts -O dtb -o /boot/dtb/rockchip/rk3399-nanopi4-rev01.dtb rk3399-nanopi4-rev01.dts

 

Link to comment
Share on other sites

Thanks for the tips, 

I did what you wrote here exactly and rebooted my Nano Pi M4

 

After those process,

I checked if spi is active with lsmod but it returned no spi information.

I also checked 

ls /dev/spi* 

but this returns nothing.

 

I guess there is still something to do turn it on...

Could you please tell me what to do now?

 

->

so sorry, I realized that I edited a wrong dtb file.

now I found /dev/spidev32766.0 but lsmod doesn't return spi information...

also when I try to use SPI with WiringPi ( I got this worked and checked with GPIO on nano pi m4 ),

I got the error which says 

"unable to open SPI device: No such file or directory"

 

so I checked dmesg and found some error massage like 

"Failed to request TX DMA channel"

"Failed to request RX DMA channel"

 

 

These errors have something to do with the error in wiringpi or could you know a solution to this problem?

Link to comment
Share on other sites

6 hours ago, Nao said:

so sorry, I realized that I edited a wrong dtb file.

now I found /dev/spidev32766.0 but lsmod doesn't return spi information... 

also when I try to use SPI with WiringPi ( I got this worked and checked with GPIO on nano pi m4 ),

I got the error which says 

"unable to open SPI device: No such file or directory"

 

so I checked dmesg and found some error massage like 

"Failed to request TX DMA channel"

"Failed to request RX DMA channel"

 

First, can you tell us which kernel do you use, because on my NanoPCT4, it appears as /dev/spidev0.0, and is loading spidev which appears in lsmod, yours seems built-in the kernel ...

Second, test manually with this tool : https://github.com/torvalds/linux/blob/master/tools/spi/spidev_test.c

Compile it, attach a loopback wire between MISO and MOSI, then run as "spidev_test -D /dev/spidev32766.0" it should produce output like this :

spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF 
40 00 00 00 00 95 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
DE AD BE EF BA AD 
F0 0D 

If all those steps succeed, then you can continue trying WiringPi, because the error you got "unable to open SPI device: No such file or directory" is probably that it is trying to use /dev/spidev0.0 instead of your /dev/spidev32766.0.

For the DMA error, don't worry about them, I have them too, it is probably that the driver wish to use DMA which isn't setup, and then fallback to normal mode...

Link to comment
Share on other sites

23 hours ago, martinayotte said:

First, can you tell us which kernel do you use, because on my NanoPCT4, it appears as /dev/spidev0.0, and is loading spidev which appears in lsmod, yours seems built-in the kernel ..

the kernel is 4.4.162-rk3399

 

 

23 hours ago, martinayotte said:

Second, test manually with this tool : https://github.com/torvalds/linux/blob/master/tools/spi/spidev_test.c

Compile it, attach a loopback wire between MISO and MOSI, then run as "spidev_test -D /dev/spidev32766.0" it should produce output like this :


spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF 
40 00 00 00 00 95 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
DE AD BE EF BA AD 
F0 0D 

If all those steps succeed, then you can continue trying WiringPi, because the error you got "unable to open SPI device: No such file or directory" is probably that it is trying to use /dev/spidev0.0 instead of your /dev/spidev32766.0.

For the DMA error, don't worry about them, I have them too, it is probably that the driver wish to use DMA which isn't setup, and then fallback to normal mode...

I got only...

 

spi mode: 0x0

bits per word: 8

max speed: 500000 Hz (500 kHz)

 

So does this mean the spi is not working?

Link to comment
Share on other sites

19 minutes ago, Nao said:

I got only...

 

spi mode: 0x0

bits per word: 8

max speed: 500000 Hz (500 kHz)

 

So does this mean the spi is not working?

I've no idea ... I've never seen a /dev/spidevX appearing in /dev and spidev_test not working with it ...

Link to comment
Share on other sites

On 12/27/2018 at 6:29 AM, Nao said:

I'm currently woking on transmitting image data by UART connection with the NanoPi M4,

 

Find another way... and think it through what you want to do - uart and spi is low bandwidth here.

 

sending image data over UART is not efficient compared the available interfaces you do have at hand with this board.

Link to comment
Share on other sites

56 minutes ago, sfx2000 said:

Find another way... and think it through what you want to do - uart and spi is low bandwidth here.

 

sending image data over UART is not efficient compared the available interfaces you do have at hand with this board.

I know other method is better when it comes to sending a big data like an image.

But for some reasons, I have to work it with SPI, so I'll keep trying this

Link to comment
Share on other sites

On 12/30/2018 at 11:19 PM, martinayotte said:

Main DT is the file located in /boot/dtb/rockchip/rk3399-nanopi4-rev01.dtb.

I think there are 2 dtb and dts files (rev00 and rev01) by default but what is the deference between 00 and 01?

 

and I found that aliases in dts file does not include spi, while it sentences dis, ethernet, i2c and serial.

After I added the following, 

 

spi0 = "/spi@ff1c0000"

 

/dev/spidev0.0 appears but lsmod doesn't include spi...

 

I guess there is still something to do....

 

Link to comment
Share on other sites

4 hours ago, Nao said:

deference between 00 and 01?

 

00 is for the T4, 01 is for the M4 and 04 for the NEO4 ...

4 hours ago, Nao said:

/dev/spidev0.0 appears but lsmod doesn't include spi...

With "default" Legacy build, the SPIDEV is builtin the kernel while in NEXT or DEV Mainline it is built as module.

 

Link to comment
Share on other sites

Thank you very much for your patience..

 

Just in case, I show the result from dmesg | grep spi

 

Quote

[    1.560666] rockchip-spi ff1c0000.spi: Failed to request TX DMA channel

[    1.560679] rockchip-spi ff1c0000.spi: Failed to request RX DMA channel

[    1.560689] rockchip-spi ff1c0000.spi: no high_speed pinctrl state

[    1.561289] spidev spi0.0: buggy DT: spidev listed directly in DT

[    1.561365] WARNING: at drivers/spi/spidev.c:720

[    1.561421] PC is at spidev_probe+0x6c/0x1d8

[    1.561430] LR is at spidev_probe+0x68/0x1d8

[    1.564338] [<ffffff80086f86b0>] spidev_probe+0x6c/0x1d8

[    1.564348] [<ffffff80086f57c4>] spi_drv_probe+0x9c/0xb4

[    1.564433] [<ffffff80086f605c>] spi_add_device+0x12c/0x188

[    1.564443] [<ffffff80086f6424>] of_register_spi_device+0x2c0/0x2d8

[    1.564453] [<ffffff80086f78f8>] spi_register_master+0x448/0x484

[    1.564463] [<ffffff80086f7988>] devm_spi_register_master+0x54/0x94

[    1.564474] [<ffffff80086fac60>] rockchip_spi_probe+0x2ec/0x440

[    1.564568] [<ffffff80090f94f8>] rockchip_spi_driver_init+0x18/0x20

[    1.566326] rockchip-pinctrl pinctrl: pin gpio3-7 already requested by ff1c0000.spi; cannot claim for fe300000.ethernet

still struggling to get the spi worked 

Link to comment
Share on other sites

1 hour ago, Nao said:

still struggling to get the spi worked

BTW, I didn't pay attention before, but you seems to try using SPI0 and instead of SPI1, which is the one on the header. (SPI0 is only for SPIFlash)

 

Here is the output on my NanoPCT4 with loopback wire between MISO/MOSI on the header, which isn't far away from NanoPi-M4 :

root@nanopct4:~# dmesg | grep spi
[    3.447624] rockchip-spi ff1d0000.spi: Error applying setting, reverse things back
[    3.448750] rockchip-spi ff1d0000.spi: Failed to request TX DMA channel
[    3.449368] rockchip-spi ff1d0000.spi: Failed to request RX DMA channel
[    6.635403] /spi@ff1d0000/spidev@0: buggy DT: spidev listed directly in DT
[    6.635430] WARNING: CPU: 5 PID: 381 at drivers/spi/spidev.c:730 spidev_probe+0xfc/0x1d8 [spidev]
[    6.635432] Modules linked in: spidev(+) rockchip_io_domain nvmem_rockchip_efuse analogix_dp dw_hdmi rockchip_thermal rockchip_saradc drm_kms_helper drm drm_panel_orientation_quirks adc_keys pcie_rockchip_host(+) input_polldev ip_tables x_tables ipv6 btrfs libcrc32c xor zstd_decompress zstd_compress xxhash zlib_deflate raid6_pq realtek phy_rockchip_typec phy_rockchip_pcie rtc_rk808 dwmac_rk stmmac_platform stmmac
[    6.635461] pc : spidev_probe+0xfc/0x1d8 [spidev]
[    6.635465] lr : spidev_probe+0xfc/0x1d8 [spidev]
[    6.635502]  spidev_probe+0xfc/0x1d8 [spidev]
[    6.635511]  spi_drv_probe+0x7c/0xd8
[    6.635533]  __spi_register_driver+0x58/0x60
[    6.635536]  spidev_init+0x9c/0x1000 [spidev]
[    7.239160] Modules linked in: zstd zram brcmfmac snd_soc_rockchip_i2s snd_soc_rockchip_spdif snd_soc_rockchip_pcm fusb30x(C) rockchip_rga v4l2_mem2mem videobuf2_dma_sg videobuf2_memops videobuf2_v4l2 videobuf2_common cfg80211 videodev media rfkill brcmutil rockchipdrm spidev rockchip_io_domain nvmem_rockchip_efuse analogix_dp dw_hdmi rockchip_thermal rockchip_saradc drm_kms_helper drm drm_panel_orientation_quirks adc_keys pcie_rockchip_host input_polldev ip_tables x_tables ipv6 btrfs libcrc32c xor zstd_decompress zstd_compress xxhash zlib_deflate raid6_pq realtek phy_rockchip_typec phy_rockchip_pcie rtc_rk808 dwmac_rk stmmac_platform stmmac
root@nanopct4:~# ./spidev_test
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF 
40 00 00 00 00 95 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
DE AD BE EF BA AD 
F0 0D 

 

Link to comment
Share on other sites

On 2/6/2019 at 3:46 AM, martinayotte said:

BTW, I didn't pay attention before, but you seems to try using SPI0 and instead of SPI1, which is the one on the header. (SPI0 is only for SPIFlash)

I followed your suggestion below 

 

On 12/30/2018 at 11:19 PM, martinayotte said:

Then, for the SPI, you need to turn it ON with ' status="okay"; ', but also need to add SPIDEV into this node :


        spi@ff1c0000 {
			[ ... more stuff here ... ]
            status = "okay";
			spidev {
                compatible = "spidev";
                status = "okay";
                reg = <0>;
                spi-max-frequency = <10000000>;
            };
        };

but a change on spi@ff1c0000 showed the change at SPI0 not SPI1 so I thought I had to change the different one, such as spi@ff1d0000.

 

After I edited spi@ff1d0000, I changed dts file to dtb and I rebooted my pi, then it never booted again...

I did the same thing with my backup file and got the same problem

Maybe this spi@ff1d0000 should not be abled..?

 

So how can I know which spi@***** represents SPI1? 

Link to comment
Share on other sites

4 minutes ago, martinayotte said:

Did you tried all other SPIs, spi@ff1e0000, spi@ff1f0000 and spi@ff200000 ?

Now I'm trying ... so please wait haha

 

 

Is it possible that I download the img file which you made or someone made to enable SPI?

Link to comment
Share on other sites

7 minutes ago, Nao said:

Is it possible that I download the img file which you made or someone made to enable SPI?

It is not for NanoPi-M4, as I mentioned I've use NanoPC-T4 ...

 

EDIT : I've just double checked on my T4 : SPI1 is really on spi@ff1d0000 ...

So, why your M4 doesn't boot after such changes ? Maybe you did some typo errors ?

Link to comment
Share on other sites

23 minutes ago, martinayotte said:

Do you have a USB-TTL Serial dongle to check logs during boot ?

Where does it failed ?

I have it.

Usually I use it for console but how can I check logs with it ?

In addition, I would like to know which UART is supposed to be "disable"

UART4 and SPI1 share GPIOs but since I don't know which is the one, I disabled all of the UARTs

 

the red light on nano pi m4 is on but the yellow one which is supposed to blink while booting does not appear anyway  

 

Link to comment
Share on other sites

3 minutes ago, Nao said:

Usually I use it for console but how can I check logs with it ?

I'm not sure to understand your question ...

Do you have this USB-TTL Serial attached to Serial Debug port of your M4 ?

Do you run on your PC "putty" or "picocom" ?

What are you seeing while it is booting ?

To make sure you see complete logs, make sure to have "verbosity=7" and "console=serial" in /boot/armbianEnv.txt !

There should be an error somewhere if it doesn't reach login prompt ...

Link to comment
Share on other sites

22 minutes ago, martinayotte said:

I'm not sure to understand your question ...

Do you have this USB-TTL Serial attached to Serial Debug port of your M4 ?

Do you run on your PC "putty" or "picocom" ?

What are you seeing while it is booting ?

To make sure you see complete logs, make sure to have "verbosity=7" and "console=serial" in /boot/armbianEnv.txt !

There should be an error somewhere if it doesn't reach login prompt ...

Sorry that I made you confused


I have it and I can use it

but since I don't know which UART in main DT represents the UART4 which share GPIO with SPI1, I disabled all of the UARTs anyway

So I thought all of the UARTs were OFF and thus never tried to see what was going on while booting...

 

just for information, nano pi m4 doesn't shoe its yellow light blinking while booting after I changed main DT to enable SPI1 

 

EDIT:

I run UART console with "screen" command on UNIX 

Link to comment
Share on other sites

6 minutes ago, Nao said:

but since I don't know which UART in main DT represents the UART4 which share GPIO with SPI1, I disabled all of the UARTs anyway

So I thought all of the UARTs were OFF and thus never tried to see what was going on while booting...

I'm talking about the Serial Debug port, a 4 pins header on the board, it is attached to UART2DBG_RX and UART2DBG_TX of the SoC, it should the serial@ff1a0000, put it back to "okay" ...

Then, attach the USB-TTL on this 4 pins header, and watch the boot log and try to find an error related to the fact that boot is hanging.

14 minutes ago, Nao said:

just for information, nano pi m4 doesn't shoe its yellow light blinking while booting after I changed main DT to enable SPI1

I don't care about this yellow led for now, it is not related to the issue ...

Link to comment
Share on other sites

34 minutes ago, martinayotte said:

I'm talking about the Serial Debug port, a 4 pins header on the board, it is attached to UART2DBG_RX and UART2DBG_TX of the SoC, it should the serial@ff1a0000, put it back to "okay" ...

Then, attach the USB-TTL on this 4 pins header, and watch the boot log and try to find an error related to the fact that boot is hanging.

Thank you so much 

I did all the things mentioned here and checked the boot logs.... then nothing appeared...

 

I attached a dts file which I edited again just in case  

rk3399-nanopi4-rev01.dts

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines