顯示具有 Embedded System 標籤的文章。 顯示所有文章
顯示具有 Embedded System 標籤的文章。 顯示所有文章

2014年4月15日 星期二

兩個device 利用 Uart 傳輸當中所必須注意到的問題

玩嵌入式系統當中,最一開始就要先解決傳輸問題,而最常見的就是將兩個device透過uart傳輸,傳輸過程中必須要注意一個小部份,就是"\n"換行符號,


假設說有device A, device B 而deviceA定義一個thread每一秒就會透過uart訊號傳出去,例如:

void uart_puts(void *p){
        while(1){
        printf("”Hello Device B");
        Delay(1000);
        }
}


而接收方Device B 透過下列程式去接收:

while(1){
  do
  {
   n = read(fd_uart, (void*)&c, 1);
   if (n < 0) {
    perror("Read failed - ");
    return -1;
   }else if (n == 0) /*indicates end of file*/
    printf("end of file\n");
   else{ /*n>0 means have received data.*/
    buf[cnt++] = c;
     
   }
  }
  while(n>0 && cnt<14 && c!='\n');
  buf[cnt]='\0';
  printf("%d bytes read : %s\n", cnt, buf);
                cnt = 0;
}


若是以上的方式的話,DeviceB的輸出結果並不會如期的一秒鐘顯示一次"Hello Device B",而是過了一段時間才會印出一大堆的"Hello Device B" ,  原因是因為在Device A之傳送端中,沒有加上"\n"換行符號,因為對於printf來說他會先輸出到你指定的裝置,但是會先暫存到buffer之中,直到他收到了換行符號,他才會刷新整個buffer,故此程式碼當中,沒有換行符號他就是一直塞buffer,直到緩衝區的大小滿了,才會刷新整個buffer,因此Device B才會一次出現一大堆的資料,只要在Device A中加上換行符號即可。


printf("”Hello Device B\n");


當然你也可以用標準方法,使用fflush函數,強制清空buffer且輸出buffer:

flush(stdin)刷新標準輸入緩衝區,把輸入緩衝區裡的東西丟棄   
fflush(stdout)刷新標準輸出緩衝區,把輸出緩衝區裡的東西打印到標準輸出設備上。



2014年3月11日 星期二

Share the folder using by NFS Server for the Beagleboard-xM

目的:
PC與BB-xM 共享同一個資料夾,如此一來,若是需要在PC上Cross-compile就可以直接將執行檔放置此目錄夾,然後BB-xM就直接執行此資料夾的執行檔即可,不用在那邊每次compile完,就在那邊拔sd卡,很蠢。

首先在PC上建立環境:
----------------------------------------------------------------------------------------------------------------------

$sudo apt-get install nfs-common
$sudo apt-get install nfs-kernel-server

接著要設定nfs存取的權限與相關設定:

 sudo vi /etc/exports

在這邊舉我的例子,在/etc/exports裡面加入這行:

/home/jack/Desktop/nfstemp *(rw,no_root_squash,no_all_squash,sync)

nfstemp就是你在PC上所要共享的資料夾,後面的*代表是所有人都可以存取此資料夾,你也可以不要使用*,直接指定只有某個ip(實體ip)才可以存取你這個資料夾,後面的設定說明如下:

rw : read-write
no_root_squash      :   如果你想要開放用戶端使用 root 身份來操作伺服器的檔案系統,那麼這
                                    裡就得要開 no_root_squash 才行(引述鳥哥私房菜)。
no_all_squash :        保留共享文件的UID和GID(default)
sync :                        代表資料會同步寫入到記憶體與硬碟中,而async 則代表資料會先暫存於                                     記憶體當中,而非直接寫入硬碟!





接著就是在BB-xM中的設定了 , 屬於Client端。
----------------------------------------------------------------------------------------------------------------------
首先先說下我的環境,OS : Angstrom   ,  Kernel : linux kernel 2.6.32
然後要建立一個空的資料夾來共享,我在這邊習慣都是跟PC一樣的資料夾名稱,
接著輸入:

mount -o nolock 140.116.123.123:/home/jack/Desktop/nfstemp  nfstemp/
or

busybox mount -o nolock 140.116.123.123:/home/jack/Desktop/nfstemp  nfstemp/

前面的ip就是你要連結的server ip 然後存取他裡面的某個資料夾,並且共享他。

建議盡量寫一個script檔,不用每次都要輸入這些命令了。

#!/bin/sh                                                                     
#### this shell command is access host folder from NFS_server ####
busybox mount -o nolock 140.116.123.123:/home/jack/Desktop/nfstemp  nfstemp/

除此之外還可以將此script 在開機執行。

注意事項:當然BB-xM 也要給他網路囉....,同網域通常不會有什麼問題,可是如果是外網連進來共享就要考慮到有無防火牆,成大好像有。@@這就不關我的事情了,反正我只是為了在學校玩嵌入式方便用。



Reference:

  1. http://linux.vbird.org/linux_server/0330nfs.php
  2. http://hi.baidu.com/zzcqh/item/fa9ca6b6c2d2c977254b0914

2014年1月26日 星期日

Build beagleboard-xM of linux kernel and driver modules by 2.6.32 version


  • Build BB-xm's Linux Kernel by 2.6.32:
  • 日後都採用這個repositories , 穩定版本 , 裡面還有其他branch是不同的MCU!!

  1. $export ARCH=arm CROSS_COMPILE=arm-angstrom-linux-gnueabi-
  1. $make distclean
  1. $make  omap3_beagle_defconfig #(on the  arch/arm/configs )
  1. $make memuconfig
  1. $make uImage
  1. $make modules # if build the modules

Angstrom Cross Compiler ToolChain 新載點

網路上所有的Angstrom cross compiler toolchain 載點幾乎全都掛點了,
因此讓我緊張一下 , 好加在在我強大的Google Search 下 , 終於給我找到嚕~
-----------------------------------------------------------------------------------------------------------

Here

裡面還有很多其他版本的 ToolChain  ,  64bit(x86_64)  , 32bit(i686) .


2014年1月20日 星期一

[Angstrom] Beagleboard-xM 之開機初始化 , 腳本 (Script)

首先幾個認知:

  • 在/etc/init.d/    ->  這裡面是放置一些初始化的script ,是實體的,也就是所有初始化script原始script都放置在這裡,要注意的是使用者新增的script檔最好改一下權限。
                    $ chmod 755   yourscript.sh
  •  了解 /etc/rcS.d    、  /etc/rc0~6.d。  
                      其中rc?.d   是代表不同的runlevel ,相關說明如下:

                      rcS.d    ------>    在boot時階段所執行的script。
                      rc1.d    ------>    在單用戶模式時階段所執行的script。
                      rc3.d    ------>    在Console時階段所執行的script。
                      rc5.d    ------>   在圖形介面模式下的會執行的 script。

                      而裡面的SxxYOURSCRIPT.sh   ,    其中xx代表的是優先執行順序,越小越優先。

                      開頭的S是代表會執行的script ,  K代表是會kill掉的行程。

  • 記得在所有/etc/rcS.d 、 /etc/rc0~6.d 裡面的script 都要連結原始的script檔在/etc/init.d。
                     $ ln -s    SXXname    /etc/init.d/yourlinkscript.sh



Reference : 

2013年12月17日 星期二

Using Wi-Fi direct technology to implement smart phone connect Beagleboard-xM record

這是近期的挑戰 , 先說一下這個小目標 ,
我將利用Smart phone 連線  Beagleboard-xM,
利用Wi-Fi direct 方式來傳送影像。 拜託讓我成功吧 ~~




近期動作:
--------------------------------------------------------------------------------------------------------------------------

買TL-WN725N 回來build , 然後接上去看能不能連上

android wifi direct , 若smart phone 手機上內建的wifi direct 不能連 ,

可參考資料搜尋區的Wi-Fi Peer-to-Peer 裡面的socket 傳輸範例 , 來傳輸jpeg圖像。

相關driver 以及使用請優先參考 CodeMonkeyRicky 的系列影片以及相關Website.





2013.12.17
--------------------------------------------------------------------------------------------------------------------------


  • today I'm tried to build the  8188cu driver using  cross-compiler toolchain,
          but I encountered the error by "implicit declaration of function 'usb_autopm_disable'"

          the environment setting is following :
 
         EXTRA_CFLAGS += -DCONFIG_LITTLE_ENDIAN
ARCH := arm
SUB_ARCH := arm
CROSS_COMPILE = /home/jack/new/arm/4.3.2/bin/arm-none-linux-gnueabi-
KSRC ?= /home/jack/beagleboard-validation-linux
KVER := 2.6.32
          So , I will re-try build again by next time , I will refer to  CodeMonkeyRicky project,
          And using BB-xM's setting instead of  RPI's setting .







資料搜尋紀錄:
--------------------------------------------------------------------------------------------------------------------------

         List to Wi-Fi Direct API and introduction it .

           這裡有一些範例 , 利用android wifi direct api 再加上socket 傳輸
           達到jpeg影像傳輸. 不過這些都只提供android api  , 但是到時候很夠用。
           這個人參照了 CodeMonkeyRicky's Youtube video 以及github repository ninjablocks/rtl8192cu

           來實現 , 但是遇到了P2P UI 的問題 , 但是問題有解決。



  • CodeMonkeyRicky  , 此人看來已經完全成功我想要的 , 我將參考他的作法, 以下列出他的紀錄:
            其中第一個一定要仔細看  , 他列出的Reference 有教學 , 包括build 、 Git 等等
  1. Setting Up Wifi Direct on the Raspberry Pi with TL-WN725N (part 1)
  2. Remote Pi Camera Streaming Field Test #1
  3. Remote Pi Camera Streaming Field Test #2 (with Wifi Direct!)
  4. Raspberry Pi Camera Streaming Application (with real Pi camera!)
  5. Setting Up Wifi Direct on the Raspberry Pi with TL-WN725N (part 1)

 額外參考篇(未來可能會參考到):
         這裡蠻多人在討論 RPI to Android through WiFi Direct 


2013年11月25日 星期一

Arduino 與 Beagleboard-xM 之溝通 (USB to UART interface)


本專案是一個很簡單的應用 , 利用USB to UART 溝通界面 , 讓Arduino 與 bb-xM作字串傳輸,

如下圖所示:

而這裡的測試方法是由 , Arduino 每一秒發送一次字串訊號 , 
然後由bb-xM 的Read task thread 來作接受的動作 . 下列是分別的程式碼,


Arduino:

char incomingByte = 0;   // for incoming serial data
void setup(){
  Serial.begin(9600);
  delay(2000);
}
void loop(){
  Serial.println('a');      
  delay(1000); 
}

這裡要非常注意 , 一開始我只用Serial.print('a') 或是 Serial.write('a') , 但這樣會沒辦法正常送出去 , bb-xM也無法正常收到 , 後來我改用 在字元後面加一個換行符號 , 也就是改用Serial.println('a') 才能正常傳收。
為什麼會這個樣子呢?




Beagleboard-xM (部份c code , 其中一個Thread)

void *ReadFrom_Arduino_by_USB(void *argu)
{
 int res;
 char buf[256];
 while(1){
  if((uart_init_is_OK == YES) && (usb_init_is_OK == YES)){
    /*receive from usb*/
    res = read(fd_usb, buf, 255);
    buf[res]=0;
    printf("Arduino response:%s",buf);
  }
    /*else do not somthing*/  
 }
  return NULL;
}



收到字串之結果如下圖(bb-xM的畫面):

2013年11月7日 星期四

Build the USB WIFI Dongle(N150UM) driver to BeagleBoard-xM(2.6.32 kernel)

由於8712u.ko  , 好不容易編譯好了結果 module 一直掛不起來,  只好換一個試試看,
我去商場買了一個USB WIFI Dongle (N150UM) , 圖如下:




相關產品規格去官網找就有了 , Driver for linux 可從底下載:
去裡面選擇:
要注意我們的這個Driver是 "RT3070" .

-----------------------------------------Starting Cross Compiler-----------------------------------------------

先說說我bb-xM的環境:
Kernel : 2.6.32
Rootfs : Angstrom 
值得注意的是 , 當初Build in Kernel 時 , 需要勾選wireless 以及Ralink rt27xx/rt28xx/rt30xx (USB) support這些選項 .


好了 ,  可以開始了 .

  • Step1. 設定wireless WPA 相關設定檔. 
vim os/linux/config.mk
# Support Wpa_Supplicant
HAS_WPA_SUPPLICANT=y
# Support Native WpaSupplicant for Network Maganger
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y


  • Step2.  modify platform for arm system from Makefile
ifeq ($(PLATFORM),PC)
# Linux 2.6
LINUX_SRC = /home/jack/beagleboard-validation-linux
# Linux 2.4 Change to your local setting
#LINUX_SRC = /usr/src/linux-2.4
LINUX_SRC_MODULE = /home/jack/beagleboard-validation-linux/drivers/net/wireless/
CROSS_COMPILE = /home/jack/angstrom_toolchain/usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-
CROSS_COMPILE = arm-none-linux-gnueabi-
endif

         請注意藍字的部份是針對我的kernel source包(Linux 2.6.32),
         以及cross-compiler toolchain path ,
         值得一提的是 , toolchain 用 arm-angstrom-linux-gnueabi-  也是可以的 , 所以我保留住                  angstrom的toolchain path , 但實際上我是用arm-none-linux-gnueabi- 來編的.
         若沒有 kernel source 包 請至下列網址下載:
         Jason Kridner’s Beagleboard validation 2.6.32 kernel
       


  • Step3.  resolve the CHIPSET changed bug
           #vim chips/rtm_chip.c    
           goto 470 line

#ifdef RT30xx

    if (IS_RT30xx(pAd))
    {
        if (IS_RT3390(pAd))
            ;//RT33xx_Init(pAd);                                              
        else
            RT30xx_Init(pAd);
    }
#endif /* RT30xx */

           
  • Step4. make start
  #sudo -s
             #make ARCH=arm   #Dont forget this .

     
        上述動作做完了之後會產生相關檔案 , 其最重要的是rtl3070sta.ko 以及 RT 2870STA.dat
         並將這兩個檔案透過NFS方式放置bb-xM



  • Step5. Insmod the module
             On the bb-xM:
    #mkdir –p /etc/Wireless/RT2870STA/    
    #cp RT2870STA.dat / etc/Wireless/RT2870STA/   
               (注意RT2870STA.dat一定要放置/etc/Wireless/RT2870STA/ 裡 , module 才會吃的到)
   #insmod rt3070sta.ko
       上述完整描述了從編譯到掛載, 如果掛載沒出現錯誤 也確定都可以開啟wifi, 那就成功了

        當然連線的操作就是搭配一下wireless tools ,
         如下操作:
          #ifconfig ra0 up
          #iwlist scan
          #iwconfig ra0 essid "Emily NCKU"
          可能會提示出要輸入密碼等等. 連線成功之後可以使用ping ip 來test看看封包有無遺失.




          Gj!!

          Refer to :
          1.http://blog.chinaunix.net/uid-28572323-id-3482376.html
          2.http://bbs.chinaunix.net/thread-1921952-1-1.html
          3. http://www.tamio.com.tw/tamio/component/phocadownload/category/61-totolink-n150um