2016년 12월 17일 토요일

Connecting the GPS Click board to Atmel SAMA5D3 Xplained board

In this blog, I'll introduce how to integrate the GPS Click board to Atmel SAMA5D3 Xplained board. To connect the GPS Click board to SAMA5D3 Xplained board, mikroBUS connector(Arduino UNO shield) is needed additionally.
Figure 0.1 GPS Click Board by MikroElektronika

 Figure 0.2 mikroBUS Arduino UNO shield

<Contents>
1. Introduction to GPS Click board and mikroBUS connector
2. Device drivers for UART
3. How to run the GSP application


1. Introduction to GPS Click board and mikroBUS connector
1.1 GPS L10 Click board
GPS click carries the LEA-6S high performance positioning engine from u-bloxGPS click is designed to run on a 3.3V power supply and communicate with the target MCU through UART or I2C interface. Data can also be acquired through a PC application using the onboard USB port. The click has an onboard connector that is compatible with both active and passive antennas.
GPS click can simultaneously track up to 16 satellites while searching for new ones. The LEA-6S module’s TTFF (time to fist fix) is less than one second — this is the measure of time necessary for a GPS receiver to get satellite signals and navigation data, and based on this information, calculate a position (a fix)
  • LEA-6 u-blox module
    • Navigate down to –162 dBm and –148 dBm coldstart
    • Power consumption in power save mode: 36mW
    • TTFF less than 1 second in Hot Start
    • Horizontal position accuracy 2.5m
  • UART and I2C interface
  • USB connector
  • 3.3V power supply
Figure 1.1 GPS Click with ublox module

Figure 1.2 GPS Click schematic with ublox engine

1.2 mikroBUS Form Factor
The MIKROE-1581 Arduino Uno click shield is an extension for Arduino Uno and any other Arduino compatible board. It's a simple shield with two mikroBUS host sockets that allow user to connect more than 75 different types of click boards to the Arduino. Quickly add functionalities like GSM, GPS, Wi-Fi, ZigBee, Bluetooth, or thunder detection, proximity and colour sensing and so on.
  • Two mikroBUS host connectors for attaching click boards
  • Arduino compatible connector on the opposite side
  • Shield is designed to stay within dimensions of Arduino Uno for smoother integration
  • Brings click board connectivity to a wide range of Arduino compatible boards

Figure 1.3 Pinout for mikroBUS Arduino UNO shield


Figure 1.4 Schematic for GPS click Board and mikroBUS Arduino UNO shield

Connecting the GPS Click board to the SAMA5D3 XPlained board requires using the Arduino UNO click shield adapter board(Figure 0.2). The adapter board makes the following connections:

<Table 1.1 Pin map for three boards>



2. Device drivers for UART
The GPS click board connects to the host platform via the mikroBUS connector. Communications with the GPS click, both configuration input and GPS message output, are by a simple asynchronous serial (UART) connection. By default, the serial port connection configuration between the SAMA5D3 Xplained and GPS click is 9600 bps, 8 bits by word, no parity, 1 stop bit, no hardware flow control. Data are "logic level" voltages (0V, 3.3V) and not RS-232 levels (-12V, +12V). The GPS click module requires a GPS antenna for proper operation.

In this chapter, an analysis for both UART device tree and device driver codes will be done.

2.1 Device Tree for UART
At first, let's check the device tree codes for PC29(UART RX0) and PC30(UART TX0) pins on SAMA5D3 Xplained board.

Code 2.1 pinctrl node for PIOC 29 and 30 in sama5d3.dtsi

Code 2.2 uart0 node in sama5d3.dtsi

Code 2.3 serial5 alias for uart0 in sama5d3.dtsi


Code 2.4 uart0 node in at91-sama5d3_xplained_pda4.dts

2.2 Device driver for UART
You can easily find the following uart device driver file with "atmel,at91sam9260-usart" compatible string which is mentioned int the sama5d3.dtsi file(See the Code 2.2).

drivers/tty/serial/atmel_serial.c

==============================================================
static int atmel_serial_probe(struct platform_device *pdev)
{
    struct atmel_uart_port *atmel_port;
    struct device_node *np = pdev->dev.of_node;
    struct atmel_uart_data *pdata = dev_get_platdata(&pdev->dev);
    void *data;
    int ret = -ENODEV;
    bool rs485_enabled;

    BUILD_BUG_ON(ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE - 1));

    if (np)
        ret = of_alias_get_id(np, "serial");
    else
        if (pdata)
            ret = pdata->num;

    if (ret < 0)
        /* port id not found in platform data nor device-tree aliases:
         * auto-enumerate it */
        ret = find_first_zero_bit(atmel_ports_in_use, ATMEL_MAX_UART);

    if (ret >= ATMEL_MAX_UART) {
        ret = -ENODEV;
        goto err;
    }

    if (test_and_set_bit(ret, atmel_ports_in_use)) {
        /* port already in use */
        ret = -EBUSY;
        goto err;
    }

    atmel_port = &atmel_ports[ret];
    atmel_port->backup_imr = 0;
    atmel_port->uart.line = ret;
    atmel_serial_probe_fifos(atmel_port, pdev);

    atomic_set(&atmel_port->tasklet_shutdown, 0);
    spin_lock_init(&atmel_port->lock_suspended);

    ret = atmel_init_port(atmel_port, pdev);
    if (ret)
        goto err_clear_bit;

    atmel_port->gpios = mctrl_gpio_init(&atmel_port->uart, 0);
    if (IS_ERR(atmel_port->gpios)) {
        ret = PTR_ERR(atmel_port->gpios);
        goto err_clear_bit;
    }

    if (!atmel_use_pdc_rx(&atmel_port->uart)) {
        ret = -ENOMEM;
        data = kmalloc(sizeof(struct atmel_uart_char)
                * ATMEL_SERIAL_RINGSIZE, GFP_KERNEL);
        if (!data)
            goto err_alloc_ring;
        atmel_port->rx_ring.buf = data;
    }

    rs485_enabled = atmel_port->uart.rs485.flags & SER_RS485_ENABLED;

    ret = uart_add_one_port(&atmel_uart, &atmel_port->uart);
    if (ret)
        goto err_add_port;

#ifdef CONFIG_SERIAL_ATMEL_CONSOLE
    if (atmel_is_console_port(&atmel_port->uart)
            && ATMEL_CONSOLE_DEVICE->flags & CON_ENABLED) {
        /*
         * The serial core enabled the clock for us, so undo
         * the clk_prepare_enable() in atmel_console_setup()
         */
        clk_disable_unprepare(atmel_port->clk);
    }
#endif

    device_init_wakeup(&pdev->dev, 1);
    platform_set_drvdata(pdev, atmel_port);
    /*
     * The peripheral clock has been disabled by atmel_init_port():
     * enable it before accessing I/O registers
     */
    clk_prepare_enable(atmel_port->clk);

    if (rs485_enabled) {
        atmel_uart_writel(&atmel_port->uart, ATMEL_US_MR,
                  ATMEL_US_USMODE_NORMAL);
        atmel_uart_writel(&atmel_port->uart, ATMEL_US_CR,
                  ATMEL_US_RTSEN);
    }

    /*
     * Get port name of usart or uart
     */
    atmel_get_ip_name(&atmel_port->uart);

    /*
     * The peripheral clock can now safely be disabled till the port
     * is used
     */
    clk_disable_unprepare(atmel_port->clk);

    return 0;

err_add_port:
    kfree(atmel_port->rx_ring.buf);
    atmel_port->rx_ring.buf = NULL;
err_alloc_ring:
    if (!atmel_is_console_port(&atmel_port->uart)) {
        clk_put(atmel_port->clk);
        atmel_port->clk = NULL;
    }
err_clear_bit:
    clear_bit(atmel_port->uart.line, atmel_ports_in_use);
err:
    return ret;
}
==============================================================

Actually any modification to device tree and device drivers for UART is not required because they are already prepared to work well. So, let's connect the GPS Click board to SAMA5D3 Xplained board carefully.

Figure 2.1 View to which GPS Click, mikroBUS and SAMA5D3 Xplained are integrated



3. How to run the GPS application
Now, we need a GPS application to run, so let's download a sample code from the following site.
https://www.element14.com/community/docs/DOC-69753/l/gps-click-l10-accessory-board

The code flow of this sample program is as follows.

Figure 3.1 The code flow of gps sample application

From now on, I'll summarize the steps to build this gps application under the BuildRoot environment.

<Directory for original source codes>
chyi@earth:~/Atmel/demo/GPS/gps_app$ ls -la
합계 36
drwxrwxr-x 2 chyi chyi  4096 12월 16 15:55 .
drwxrwxr-x 5 chyi chyi  4096 12월 16 15:50 ..
-rw-rw-r-- 1 chyi chyi   161 12월 16 15:55 Makefile
-rw-rw-r-- 1 chyi chyi 20772 12월 16 15:50 sam_gps_click.c
==============================================================

<BuildRoot Directory> $ cd ~/Atmel/buildroot/package
$ mkdir gps_app
$ cd gps_app

$ vi Config.in
Code 3.1 Config.in for gps application(package)

vi gps_app.mk
Code 3.2 gps_app.mk for gps application(package)

$ cd ..

vi Config.in
...
menu "Miscellaneous"
    source "package/aespipe/Config.in"
    source "package/bc/Config.in"
    source "package/clamav/Config.in"
    source "package/collectd/Config.in"
    source "package/domoticz/Config.in"
    source "package/empty/Config.in"
    source "package/gnuradio/Config.in"
    source "package/googlefontdirectory/Config.in"
    source "package/gr-osmosdr/Config.in"
    source "package/gsettings-desktop-schemas/Config.in"
    source "package/haveged/Config.in"
#test code - added by chunghan.yi@gmail.com - 12/16/2016
    source "package/gps_app/Config.in"
#-- --
    source "package/mcrypt/Config.in"
    source "package/mobile-broadband-provider-info/Config.in"
    source "package/qemu/Config.in"
    source "package/qpdf/Config.in"
    source "package/shared-mime-info/Config.in"
    source "package/snowball-init/Config.in"
    source "package/taskd/Config.in"
    source "package/wine/Config.in"
    source "package/xutil_util-macros/Config.in"
endmenu
...


$ cd ..
make menuconfig
Figure 3.2 buildroot menuconfig to select gps_app

make

or
$ make gps-app-rebuild

<Output> chyi@earth:~/Atmel/buildroot/output/build/gps_app-0.0.1$ ls -la
합계 512
drwxr-xr-x   2 chyi chyi   4096 12월 16 15:56 .
drwxr-xr-x 118 chyi chyi   4096 12월 16 15:56 ..
-rw-r--r--   1 chyi chyi 236701 12월 16 15:56 .br_filelist_after
-rw-r--r--   1 chyi chyi 236642 12월 16 15:56 .br_filelist_before
-rw-r--r--   1 chyi chyi      0 12월 16 15:56 .stamp_built
-rw-r--r--   1 chyi chyi      0 12월 16 15:56 .stamp_configured
-rw-r--r--   1 chyi chyi      0 12월 16 15:56 .stamp_rsynced
-rw-r--r--   1 chyi chyi      0 12월 16 15:56 .stamp_target_installed
-rw-r--r--   1 chyi chyi    161 12월 16 15:55 Makefile
-rwxr-xr-x   1 chyi chyi   9364 12월 16 15:56 sam_gps_click
-rw-r--r--   1 chyi chyi  20772 12월 16 15:50 sam_gps_click.c
==============================================================

OK, build is complete until now. Let's try NFS booting with this binary and run this application as follows.

<After rebooting>
sam_gps_click
  => But, this application does not print any message on the console.

Simply, this program opens the /dev/ttyS5 port with 9600, 8N1 attributes and sends the following GPS command to the same port.
$PMTK314,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*00
And then it waits to read some data from the /dev/ttyS5 port, but any data doesn't arrive. I have no GPS antenna now(actually I've attached an available Wi-Fi antenna instead). Is this truly a cause for this abnormal result ?

Oops, power was the true reason to this issue. I didn't connect 3.3V power between mikroBUS and SAMA5D3 Xplained board because I couldn't find a suitable male header in GPS Click product package. So I decided to use USB power for GPS click board like Figure 3.3. OK,the green LED for GPS click board is turned on.


Figure 3.3 USB power for GPS click board

Finally, the output of gps application starts to be printed to the console(Figure 3.4). But it seems that the correct output is not showed yet. Why ?

Figure 3.4 Output message from gps application

Hmm...
I rechecked the gps sample application codes and found that this code is not made for ublox gps module but Quectel gps module.

Now there are three things to do:
1) To read ublox GPS protocol specifications and rewrite gps application codes.
2) Soldering for GPS click board
  In figure 3.3, I used white Scotch tape to fix GPS click board on mikroBUS.
3) To purchase a GPS antenna



References
1. GPS_Click_QSG_103014.pdf - element 14
2. gps-click-l10-manual-v100.pdf - MikroElektronika
3. mikrobus-standard-specification-v200.pdf - MikroElektronika
4. http://docs.mikroe.com/GPS_click
5. LEA-6_DataSheet_(GPS.G6-HW-09004).pdf - ublox
6. u-blox6_ReceiverDescriptionProtocolSpec_(GPS.G6_SW-10018).pdf - ublox


Slowboot


댓글 2개: