Saturday, September 24, 2016

OrangePI PC with 4.8.x using buildroot

Finally got some time to get back to testing OrangePI-PC as a Flight Controller board.  The OrangePI-PC offers several advantages over the Pi Zero:
  • Multiple serial ports (3) 
  • Multiple USB ports (each have port has its own controller not a Hub)
  • Camera (Still working on that)
  • Cost is low around $12

I'm using standard buildroot with the orangePI defconfig, but using a different Linux kernel which has several patches for Ethernet, USB (slave), and thermal control (Which is big).   Using orange-pi-4.8 branch.

Also made a couple of code changes:
  • spidev 
static const struct of_device_id spidev_dt_ids[] = {
    { .compatible = "rohm,dh2228fv" },
    { .compatible = "lineartechnology,ltc2488" },
        { .compatible = "spidev" },

  • device tree: 
    • sun8i-h3-orangepi-pc.dts:
        spi0_pins_a: spi0@0 {
                allwinner,pins = "PC0", "PC1", "PC2";
                allwinner,function = "spi0";
                allwinner,drive = <SUN4I_PINCTRL_10_MA>;
                allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;

    spi0_cs0_pins_a: spi0_cs0@0 {
                allwinner,pins = "PC3";
                allwinner,function = "spi0";
                allwinner,drive = <SUN4I_PINCTRL_10_MA>;
                allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
        i2c0_pins_a: i2c0@0 {
        allwinner,pins = "PA11", "PA12";
            allwinner,function = "i2c0";
            allwinner,drive = <SUN4I_PINCTRL_10_MA>;
            allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;

&spi0 {
    pinctrl-names = "default";
    pinctrl-0 = <&spi0_pins_a>, <&spi0_cs0_pins_a>;
    status = "okay";
        spidev0: spidev@0 {
                #address-cells = <1>;
            #size-cells = <0>;
            compatible = "spidev";
        reg = <0>;
        spi-max-frequency = <50000000>;

&i2c0 {
    pinctrl-names = "default";
    pinctrl-0 = <&i2c0_pins_a>;
    status = "okay";

      • sun8i-h3.dtsi
        spi0: spi@01c68000 {
            compatible = "allwinner,sun6i-a31-spi";
            reg = <0x01c68000 0x1000>;
            interrupts = <GIC_SPI 65 IRQ_TYPE_LEVEL_HIGH>;
            clocks = <&ccu CLK_BUS_SPI0>, <&ccu CLK_SPI0>;
            clock-names= "ahb", "mod";
            resets = <&ccu RST_BUS_SPI0>;
            dmas = <&dma 23>, <&dma 23>;
            dma-names = "rx", "tx";
            status = "disabled";
            #address-cells = <1>;
            #size-cells = <0>;
        i2c0: i2c@01c2ac00 {
            compatible = "allwinner,sun6i-a31-i2c";
            reg = <0x01c2ac00 0x400>;
            interrupts = <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>;
            clocks = <&ccu CLK_BUS_I2C0>;
            resets = <&ccu  RST_BUS_I2C0>;
            status = "disabled";
            #address-cells = <1>;
#size-cells = <0>;
So, this adds a SPI interface and another I2C.

Next is to do some testing with SPI and I2C.

Also, still adding code to CleanFlight port to Linux.   Please post if you have any questions. 

Sunday, September 11, 2016

Cleanflight Fork

Finally had time to create a github project for CleanFlight fork.  Over the next few weeks will post changes to allow CleanFlight to compile on Linux . 

There are a couple targets:
  • PC - Allows CleanFlight to run on a PC and connect to a I/O processor
    • Helps in debugging and test with CleanFlight configurator
  • PI Zero
    • Connected a powered USB hub to the PI
      • Connected WIFI dongle
      • Connect I/O processor
  • Orange PI
    • Still working/waiting for some fixes to mainline, but will push forward with the basic camera.
Right now, working on creating a I/O processor board.  This will be a simple perf board wired up by hand.  The reason for doing this, simple and cheap.  The following sensors will be supported
  • GPS
  • Compass
  • PWM In for RC
  • PWM out to motors
  •  USB

The board for the PI Zero will also be a perf board.  But, it will use machine pin headers to keep the profile low.  This board will have just two sensors:

Wednesday, August 24, 2016

Cleanflight Confgurator

Finally got CleanFlight Configurator communicating to PI Zero with CleanFlight.  Basic setup:

  1. Chrome With CleanFlight Configurator
    1. socat to create a pty to TCP socket
    2. socat -d -d pty,raw,echo=0 tcp:
      1. socat will display which port it created, i.e /dev/pty/20 then take this device and use it for the serial port "URL" in cleanflight.
  2. PI Zero
    1. CleanFlight Port
      1. TCP server to accept MSP messages
      2. Pipe the MSP messages into Cleanflight

Gyro information was displayed in the Configurator, need to figure out why compass and accelerometer was not working. 

Also, need to connect I/O processor to Cleanflight to forward RX info and GPS status.

Friday, August 19, 2016

I/O processor status

Completed PWM input decode and sending results via USB.  For the first pass I'm using a HK-T6A transmitter/receiver.

Overall Status:

  • I/O processor:  GD32F103 (red pill board) 
    • Interprocess commuinication via USB complete
      • Receiver PWM decode
      • GPS decode
    • Next is to do PWM for motor control
      • Standard PWM out
      • Support one shot125
      • Need validate USB jitter and performance
        • Out should be less then a 1ms
        • In should be no more then 2ms
  • Cleanflight
    • Update IPC using USB
    • Add socat for CleanFlight Configuration Web Tool
      •  open a TCP/IP port in CleanFlight 
      • use socat on Linux to forward MSP packets.

Friday, July 15, 2016

CleanFlight port to PI Zero

Finally have MPU-9255 and MS5611 sensors working and a simple CLI on the command line.  It is simlar to CLI via serial port or CleanFlight configurator.

Here is the output:
Task list          max/us  avg/us rate/hz maxload avgload     total/ms
 0 -       SYSTEM      29       0       9    0.5%    0.5%         0
 1 -     GYRO/PID     748     145     848   63.9%   12.7%       743
 3 -       SERIAL      71       1      93    1.1%    0.5%         1
 5 -           RX       0       0   2147483647    0.5%    0.5%         0
Task list          max/us  avg/us rate/hz maxload avgload     total/ms
 0 -       SYSTEM      31       0       9    0.5%    0.5%         1
 1 -     GYRO/PID     886     176     801   71.4%   14.5%      5864
 3 -       SERIAL      73       1      88    1.1%    0.5%         9
 5 -           RX       0       0   2147483647    0.5%    0.5%         0

I'm going to switch to linenoise for controlling line processing to allow up and down errors etc. 

Need to fix how average is calculated, but making progress.  Need to reconnect the I/O processor to get GPS, pwm out, s.bus in, and S.Port.

The goal is to use socat where configurator is running to expose a virtual serial port and forward the packets to "LinuxFlight".

Still working on CPU performance and getting GPIO to trigger for gyro-sync.

Here is top:

Here is the CLI on the PI Zero:

The command line is using boost ASIO.  Goal is to add the socat protocol so configurator can still access and configure "LinuxFlight" ;)

Yes, I'm thinking of forking the code, due to the amount of changes to the core.  Right now, there are very minimal.

Sunday, July 10, 2016

Progress PI Zero Flight controller

I have BetaFlight ported to the PI Zero, but opted to move to CleanFlight due to the latest code check-in.  There are several APIs that are abstracted to make porting to Linux easier. The basic idea is to use LINUX #define to comment out micro-controller specific code and add XXX_linux.c drivers for SPI, I2C, serial, pwm, etc.   Still going to stick with boost ASIO for scheduler, still based on timers (timerfd). 

The SPI communication to the GD32F1 is progressing:
  • GPS handling, moved baud rate, GPS update rate to GD32F1
  • Simplifies command/processing and speed
  • Working on PWM decoding (PPM/PWM)
  • Working PWM encoding 4 outputs

Have SPI working with MPU-9255 at 8Mhz from the PI Zero.  

Still pending:
  • Cannot find any more "red" GD32F103 board might have to move to another board
  • Transmitter
    • Turnigry 9xr pro?
    • Radiolink at 10
      • The main difference between the two are:
        • Telemetry s.bus vs i2C 
        • Have to buy another receiver Radiolink to have s.bus and i2c telemetry (R9DS) which is another $13.
        • Radiolink is not open source but many ports and docs on decoding i2c for telemetry. 
        • Radiolink has sliders 9xr pro does not
        • HK shipping costs and pricing changes. 
        • Thoughts?

Sunday, June 5, 2016

Progress on I/O processor for PI Zero/Orange PI

Made progress this week on I/O processor:

  1. PI zero CPU usage is down to 2% 
    1. Using DMA 64 byte packets 
    2. Sending two packets for one transaction 20us apart
      1. SPI rx/tx buffers are sent each clock, so, two transactions are needed., first transaction is CMD (Write/Read) elements the second is the response with the read data.  
  2. Updated I/O processor to use FreeRTOS v9.0.0.0
    1. Fixed interrupt priority issue causing lockup
    2. Adding I2C for LCD
    3. Need to test GPS serial 
    4. Adding PWM generation 
Here is a trace of a single transaction (CMD)/Response.  It takes .261ms to complete a CMD.  The I/O processor can process the command and re-trigger the DMA in less then 30us (Channel 04)