博客專欄

EEPW首頁 > 博客 > 嵌入式 ARM 平臺 libsoc 開發(fā)示例

嵌入式 ARM 平臺 libsoc 開發(fā)示例

發(fā)布人:toradex 時間:2019-05-14 來源:工程師 發(fā)布文章

By Toradex秦海

1). 簡介

在之前的一篇文章中已經(jīng)介紹過如何基于嵌入式Linux部署libsoc支持 本文就繼續(xù)基于NXP IMX6平臺演示基于libsoc分別對GPIOI2CPWM以及SPI進(jìn)行開發(fā)示例。

 

本文所演示的ARM平臺同樣來自于Toradex 基于NXP iMX6 ARM處理器的Apalis iMX6 ARM嵌入式平臺。  

 

2. 準(zhǔn)備

a). Apalis iMX6Q ARM核心版配合Apalis Evaluation Board載板,連接調(diào)試串口UART1(載板X29)到開發(fā)主機方便調(diào)試。更多關(guān)于Apalis iMX6配合Apalis Evaluation Board載板的說明請參考Datasheet開發(fā)上手指南。

 

b). Apalis iMX6Q ARM核心版配合Ixora載板,連接調(diào)試串口UART1(載板X22)到開發(fā)主機方便調(diào)試。 更多關(guān)于Apalis iMX6配合Ixora載板的說明請參考Datasheet開發(fā)上手指南。

 

c). Apalis iMX6Q 安裝Toradex Linux BSP V2.8b5,系統(tǒng)中已經(jīng)默認(rèn)包含了本文測試所需要的libsoc相關(guān)庫支持,詳細(xì)安裝方法請參考這里,編譯libsoc相關(guān)demo所需要的SDK配置請參考簡介中提到的之前文章說明,本文不再贅述。

 

 

3). GPIO 測試示例

a). 基于Apalis Evaluation Board測試,硬件連接配置如下,基于C代碼的GPIO測試請參考這里,本文是基于libsoc來重新測試。

X4 GPIO05 <-> X34 SW5

X4 GPIO06 <-> X34 LED1

 

b). 源代碼請參考如下,實現(xiàn)功能就是按鍵交替點亮和關(guān)閉LED燈。

https://github.com/simonqin09/libsoc-examples/blob/master/gpiotest/gpiointtest.c

 

c). Makefile 請參考如下,直接下載的libsoc官方示例里面包含的Makefile需要進(jìn)行一些修改,這里也將修改的patch附上。

./ Makefile

https://github.com/simonqin09/libsoc-examples/blob/master/gpiotest/Makefile

./ Patch file

https://github.com/simonqin09/libsoc-examples/blob/master/gpiotest/libsoc-examples_Makefile.patch

 

d). 測試運行結(jié)果如下:

-----------------------

root@apalis-imx6:~# ./gpiointtest

Waiting for interrupt. Press 'q' and 'Enter' at any time to exit

LED turns on

Interrupt occurred 1 times

LED turns off

Interrupt occurred 2 times

-----------------------

 

 

4). PWM 測試示例

a). 基于Apalis Evaluation Board測試,硬件連接配置如下, 基于C代碼的PWM測試請參考這里,本文是基于libsoc來重新測試。

X4 GPIO05 <-> X34 SW5

X4 PWM1 <-> X34 LED1

 

b). 源代碼和Makefile請參考如下,實現(xiàn)功能就是程序運行后,PWM50%占空比輸出,通過按鍵讓PWM輸出占空比按照50%75%,25% 交替調(diào)整。

https://github.com/simonqin09/libsoc-examples/blob/master/pwmtest/pwmtest.c

https://github.com/simonqin09/libsoc-examples/blob/master/pwmtest/Makefile

 

PWM2PWM3也都可以測試,只是PWM3默認(rèn)被ov5640_mipi驅(qū)動占用,需要修改device tree釋放。

 

d). 測試運行結(jié)果如下:

-----------------------

root@apalis-imx6:~# ./pwmtest

Waiting for interrupt. Press 'q' and 'Enter' at any time to exit

Interrupt occurred 1 times

PWM Duty set to 75%

Interrupt occurred 2 times

PWM Duty set to 25%

Interrupt occurred 3 times

PWM Duty set to 50%

Interrupt occurred 4 times

PWM Duty set to 75%

-----------------------

 

 

5). I2C 測試示例

a). 基于 Ixora 載板測試,針對載板上面連接到i2c-1的總線上面的EEPROM進(jìn)行讀寫,基于C代碼的詳細(xì)測試文檔可以參考這里,本文重新基于libsoc代碼進(jìn)行測試。

 

b). 源代碼和Makefile請參考如下,實現(xiàn)功能就是程序運行后,針對指定的page號碼寫入數(shù)據(jù),然后再讀取后驗證是否讀寫一致。

I2ctest.c - https://github.com/simonqin09/libsoc-examples/blob/master/i2ctest/i2ctest.c

eeprom.c - https://github.com/simonqin09/libsoc-examples/blob/master/i2ctest/eeprom.c

eeprom.h - https://github.com/simonqin09/libsoc-examples/blob/master/i2ctest/eeprom.h

Makefile - https://github.com/simonqin09/libsoc-examples/blob/master/i2ctest/Makefile

 

d). 測試運行結(jié)果如下:

-----------------------

root@apalis-imx6:~# ./i2ctest 15

Writing to page starting at byte address: 0xf0

Waiting for data to be written

libsoc-i2c-debug: No such device or address

Waiting...

libsoc-i2c-debug: No such device or address

Waiting...

libsoc-i2c-debug: No such device or address

Waiting...

libsoc-i2c-debug: No such device or address

Waiting...

Data sucessfully written!

Reading page starting at byte address: 0xf0

data_write[0] = 0xf0 : data_read[0] = 0xf0 : Correct

data_write[1] = 0xf1 : data_read[1] = 0xf1 : Correct

data_write[2] = 0xf2 : data_read[2] = 0xf2 : Correct

data_write[3] = 0xf3 : data_read[3] = 0xf3 : Correct

data_write[4] = 0xf4 : data_read[4] = 0xf4 : Correct

data_write[5] = 0xf5 : data_read[5] = 0xf5 : Correct

data_write[6] = 0xf6 : data_read[6] = 0xf6 : Correct

data_write[7] = 0xf7 : data_read[7] = 0xf7 : Correct

data_write[8] = 0xf8 : data_read[8] = 0xf8 : Correct

data_write[9] = 0xf9 : data_read[9] = 0xf9 : Correct

data_write[10] = 0xfa : data_read[10] = 0xfa : Correct

data_write[11] = 0xfb : data_read[11] = 0xfb : Correct

data_write[12] = 0xfc : data_read[12] = 0xfc : Correct

data_write[13] = 0xfd : data_read[13] = 0xfd : Correct

data_write[14] = 0xfe : data_read[14] = 0xfe : Correct

data_write[15] = 0xff : data_read[15] = 0xff : Correct

-----------------------

 

6). SPI Master 測試示例

a). 基于Apalis Evaluation Board測試,需要配合Toradex另外一個基于NXP iMX7的平臺作為SPI slave進(jìn)行共同測試,關(guān)于硬件連接和SPI slave的配制和相關(guān)代碼請參考下面文章,本文是基于libsoc來測試 SPI Master 端。

https://www.toradex.com/zh-cn/blog/nxp-imx7-m4-he-xin-spi-slave-ce-shi

 

b). 源代碼和Makefile請參考如下,實現(xiàn)功能就是程序運行后,通過Apalis iMX6 SPI0.0 SPI slave寫入一組隨機數(shù)據(jù),然后再次通訊讀出剛才寫入的數(shù)據(jù)后確認(rèn)讀寫是否一致。

spitest.c - https://github.com/simonqin09/libsoc-examples/blob/master/spitest/spitest.c

Makefile - https://github.com/simonqin09/libsoc-examples/blob/master/spitest/Makefile

 

d). 測試運行結(jié)果如下:

-----------------------

root@apalis-imx6:~# ./spitest

Start to transfer!

data_send[0] = 0xca : data_read[0] = 0xca : Correct

data_send[1] = 0x03 : data_read[1] = 0x03 : Correct

data_send[2] = 0x01 : data_read[2] = 0x01 : Correct

data_send[3] = 0x56 : data_read[3] = 0x56 : Correct

data_send[4] = 0xb2 : data_read[4] = 0xb2 : Correct

data_send[5] = 0x64 : data_read[5] = 0x64 : Correct

data_send[6] = 0xf9 : data_read[6] = 0xf9 : Correct

data_send[7] = 0x34 : data_read[7] = 0x34 : Correct

data_send[8] = 0x91 : data_read[8] = 0x91 : Correct

data_send[9] = 0x84 : data_read[9] = 0x84 : Correct

data_send[10] = 0x19 : data_read[10] = 0x19 : Correct

data_send[11] = 0x0c : data_read[11] = 0x0c : Correct

data_send[12] = 0xb1 : data_read[12] = 0xb1 : Correct

data_send[13] = 0xd3 : data_read[13] = 0xd3 : Correct

data_send[14] = 0x1f : data_read[14] = 0x1f : Correct

data_send[15] = 0xf4 : data_read[15] = 0xf4 : Correct

-----------------------

 

 

7). 總結(jié)

如上述示例,通過基于iMX6測試了GPIOI2C,PWMSPI接口,對比C代碼,libsoc使用和配置起來更方便簡潔。

*博客內(nèi)容為網(wǎng)友個人發(fā)布,僅代表博主個人觀點,如有侵權(quán)請聯(lián)系工作人員刪除。

電路圖符號相關(guān)文章:電路圖符號大全




關(guān)鍵詞:

相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉