Saturday, April 30, 2016

New quadcopter under development (Linux/Neo/OrangePI)



Finally have a new quadcopter design:

estimated cost: $215.00

If you notice, there is no Flight Controller; the last one was a Teensy 3.1 with BaseFlight; well this time it will be Linux as Flight Controller OS with micro-controller decoding PPM/PWM and generating the PWM out for the ESC.

Which board?  Udoo Neo will be the first one, the second board will be a Orange PI.  The goal is to use Linux with PREMPT enabled.  Did some initail testing with OrangePI with 4.6-rc4 and was able to generate a 50Hz square wave while running stress-ng, with no issues! 

Using the Neo first because has a A9/M4 the Orange PI will need an external micro-controller.  

So, how to port BaseFlight to Linux?  
  1. Basics
    1. I2C: will use /sys/class/i2c
    2. SPI: Not supported yet; will get into that little latter
    3. PWM: (M4 Neo, OrangePI micro-controller)
    4. PPM/PWM deocde: (M4, OrangePI micro-controller)
    5. Software/Framework
      1. Boost ASIO
        1. asio offers as async/event loop
          1. High performance timers
          2. Support for serial events
          3. Support for network events
          4. Add support for DIO interrupts
      2. Boost logging
        1. integrated
      3. BaseFlight
        1. has a single poll loop to process events
          1. Will move each of these events to asio event:
            1. Serial: for GPS / Baseflight configurator
            2. Timer: process loop for FC
            3. Network: External WIFI (NEW)

Why not use use Ardcopter or TauLabs?  This is a first pass and will be moving to one of them on the next round. Already have ported BaseFlight to Teensy 3.1; so already familiar with the code.

Which Kernel?  Right now, the Udoo Neo is 4.5 with some patches for RPMSG.  OrangePI, did some testing with 4.6-rc5; but waiting for more patches to go into mainline; so, 4.7.

BaseFlight has been ported to Linux; just debugging I2C; then pull apart main.c /loop and move to boost asio.  Will post the modifications in a few weeks.  Right now, getting Udoo Neo RPMSG working in 4.5.  

Thursday, April 21, 2016

Udoo Neo booting mainline v4.5

I've several projects going on with the Udoo Neo that required new version of the kernel; i.e adding several wifi adapters to create a router on different channels and mesh network.

Anyway, to get mainline working, need to move several of the udoo_neoo dt files and edit them.

Using mainline several issues arise:
- Support for HDMI driver; rpmsg, NTSC camera, etc.

For this project I just need rpmsg and NTSC camera.  So, over the next few weeks will be posting how and creating patch files using buildroot to create a bootable Linux image.

Sunday, February 21, 2016

TCP/IP over rpmsg OpenAMP with Udoo Neo

Finally got Ethernet driver for Linux completed using rpmsg and FreeRTOS LwIP working on the M4.  Curently the implementation is using Ethernet frames (includes destination/source MAC address and EtherType 14 bytes)  LwIP has iperf feature builtin for testing.  The MTU size is small (496-14)=482 bytes.  

Here is a code snippet:

static void
lwiperf_report(void *arg, enum lwiperf_report_type report_type,
  const ip_addr_t* local_addr, u16_t local_port, const ip_addr_t* remote_addr, u16_t remote_port,
  u32_t bytes_transferred, u32_t ms_duration, u32_t bandwidth_kbitpsec)
{
  LWIP_UNUSED_ARG(arg);
  LWIP_UNUSED_ARG(local_addr);
  LWIP_UNUSED_ARG(local_port);

  PRINTF("IPERF report: type=%d, remote: %s:%d, total bytes: %d, duration in ms: %d, kbits/s: %d\n",
    (int)report_type, ipaddr_ntoa(remote_addr), (int)remote_port, bytes_transferred, ms_duration, bandwidth_kbitpsec);
}


static void usrTask (void* param)
{
    struct rpmsg_endpoint *ept;
    int len;
    int result;

    vTaskSuspendAll();
    PRINTF("\r\n" VERSION " %s Task running... \r\n", __FUNCTION__);
    PRINTF("RPMSG Init as Remote\r\n");
    xTaskResumeAll ();

    result = rpmsg_rtos_init(0 /*REMOTE_CPU_ID*/, &rdev, RPMSG_MASTER, &app_chnl);
    assert(0 == result);
    vTaskSuspendAll();
    PRINTF("Name service handshake is done, M4 has setup a rpmsg channel [%d ---> %d]\r\n", app_chnl->src, app_chnl->dst);
    xTaskResumeAll ();
    
    
     lwipConfig();
     IP4_ADDR(&gw, 192,168,0,1);
     IP4_ADDR(&ipaddr, 192,168,0,2);
     IP4_ADDR(&netmask, 255,255,255,0);
     
    netif_add(&netif, &ipaddr, &netmask, &gw, NULL, rpmsg_init_drv, ethernet_input);
    PRINTF("INFO: %s %s %d \n",__FILE__,__FUNCTION__, __LINE__);

   netif_set_default(&netif);
   PRINTF("INFO: %s %s %d \n",__FILE__,__FUNCTION__, __LINE__);

   netif_set_up(&netif);
    PRINTF("INFO: %s %s %d \n",__FILE__,__FUNCTION__, __LINE__);

    ept = rpmsg_rtos_create_ept(app_chnl,USR_ENDPT);
    
    lwiperf_start_tcp_server_default(lwiperf_report, NULL);

running iperf:

# iperf -c 192.168.0.2
------------------------------------------------------------
Client connecting to 192.168.0.2, TCP port 5001
TCP window size: 23.8 KByte (default)
------------------------------------------------------------
[  3] local 192.168.0.1 port 50292 connected with 192.168.0.2 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.4 sec   896 KBytes   707 Kbits/sec
# iperf -c 192.168.0.2
------------------------------------------------------------
Client connecting to 192.168.0.2, TCP port 5001
TCP window size: 23.8 KByte (default)
------------------------------------------------------------
[  3] local 192.168.0.1 port 50293 connected with 192.168.0.2 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.4 sec   896 KBytes   709 Kbits/sec
# iperf -c 192.168.0.2
------------------------------------------------------------
Client connecting to 192.168.0.2, TCP port 5001
TCP window size: 23.8 KByte (default)
------------------------------------------------------------
[  3] local 192.168.0.1 port 50294 connected with 192.168.0.2 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.3 sec   896 KBytes   711 Kbits/sec

from the M4:
IPERF report: type=1, remote: 192.168.0.1:50292, total bytes: 917528, duration in ms: 10613, kbits/s: 688                                                         
IPERF report: type=1, remote: 192.168.0.1:50292, total bytes: 917528, duration in ms: 10613, kbits/s: 688          
IPERF report: type=1, remote: 192.168.0.1:50294, total bytes: 917528, duration in ms: 10609, kbits/s: 688                                                         
                                               




Udoo Neo using I2C with Linux and Python

On my current quadcopter the LED on the Teensy 3.1 is used for ARM/DISAM indicator for the transmitter.  It is an important feature, allows me to know if the transmitter controls are active, i.e. any movement of the controls will turn on the propellers.

It would be nice to provide some more information, i.e battery information, compass calibration etc and keeping the weight down, found the following I2C LCD

Found several examples from Adafruit and several examples using micropython.  I updated the example to use python-smbus and it is working. The display is also part of the multiWii code base.


Thursday, February 11, 2016

TCP/IP working over rpmsg Udoo Neo

After fixing some issues with the Linux Ethernet driver icmp messages are working; ie. ping  Here is the output:

64 bytes from 192.168.0.2: seq=16 ttl=255 time=155.408 ms
[   75.265223] rpmsg_ether_xmit tx 98 enpt 125
[   75.407927] rpmsg_ethernet_dev_ept_cb rx 98
64 bytes from 192.168.0.2: seq=17 ttl=255 time=151.219 ms
[   76.270780] rpmsg_ether_xmit tx 98 enpt 125
[   76.412822] rpmsg_ethernet_dev_ept_cb rx 98
64 bytes from 192.168.0.2: seq=18 ttl=255 time=155.193 ms
[   77.275430] rpmsg_ether_xmit tx 98 enpt 125
[   77.417460] rpmsg_ethernet_dev_ept_cb rx 98
64 bytes from 192.168.0.2: seq=19 ttl=255 time=150.969 ms
[   78.280982] rpmsg_ether_xmit tx 98 enpt 125
[   78.422822] rpmsg_ethernet_dev_ept_cb rx 98
64 bytes from 192.168.0.2: seq=20 ttl=255 time=154.991 ms
[   79.285741] rpmsg_ether_xmit tx 98 enpt 125
[   79.426708] rpmsg_ethernet_dev_ept_cb rx 98
64 bytes from 192.168.0.2: seq=21 ttl=255 time=150.756 ms

Yes, it slow, but I have a lot of logging messages. Progress... 

Saturday, January 30, 2016

Updated MQX 4.1.0 with rpmsg

Open-Amp and MQX 4.1.0

The latest release from NXP is a port of the FreeRTOS operating system to the imx6sx SOC and imx7 SOC.  This release has rpmsg/open-amp along with drives and examples.  Also, here is a good overview of open-amp located here.  MQX uses MCC; until now, spend a few days last week porting rpmsg delivered by NXP to MQX 4.1.0.  FreeRTOS example is portable to MQX.    The main difference in porting open-amp to MQX, is the ISR only posts the channel message to a queue instead of calling open-amp stack and processing the message in the ISR. There are still some open issues; but it is working.

At this time I don't know if it is possible to release the code due to all of the licensing issues; still need to see if it is possible;





Saturday, January 23, 2016

How to reload the same firmware on the Neo M4 without a reboot

Reloading M4 without rebooting on the UDOO Neo


Most of the time I have to modify and reload firmware on the M4 many times during a debug session, i.e adding debug code or features etc, and each time when reloading firmware the Neo must reboot each time.  This gets old; plus all of the time wasted.

So, what is causes the firmware not to be reloaded? Well that is simple, it is the memory protection setup on the RDC, one simple way to to reload firmware to turn off the RDC protection, another way, just add a compile option and not enable RDC memory protection.

For MQX, it is in the init_hardware.c file, function void rdc_init_memory(void) so, I added a simple #ifdef and allows the code to be reloaded.

void RDC_memory_init(void)
{
    uint32_t start, end;
#if defined(__CC_ARM)
    extern uint32_t Image$$VECTOR_ROM$$Base[];
    extern uint32_t Image$$ER_m_text$$Limit[];
    extern uint32_t Image$$RW_m_data$$Base[];
    extern uint32_t Image$$RW_m_data$$Limit[];

    start = (uint32_t)Image$$VECTOR_ROM$$Base & 0xFFFFF000;
    end = (uint32_t)(Image$$ER_m_text$$Limit + (Image$$RW_m_data$$Limit - Image$$RW_m_data$$Base));
    end = (end + 0xFFF) & 0xFFFFF000;
#else
    extern uint32_t __FLASH_START[];
    extern uint32_t __FLASH_END[];

    start = (uint32_t)__FLASH_START & 0xFFFFF000;
    end   = ((uint32_t)__FLASH_END + 0xFFF) & 0xFFFFF000;
#endif
#if _DEBUG_
#pragma message "Turned off memory protection"
#else
    RDC_SetMrAccess(RDC, rdcMrMmdc, start, end, (3 << (BOARD_DOMAIN_ID * 2)), true, false);    
#endif
}


When compiling just define _DEBUG_ and  load the app.