Author Topic: How to enable SPI controller for A20 outside of linux?  (Read 2453 times)

Offline mMerlin

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
How to enable SPI controller for A20 outside of linux?
« on: April 15, 2016, 10:17:33 pm »
I have a software project that is to use an A20-OLinuXino-MICRO-4GB https://www.olimex.com/Products/OLinuXino/A20/A20-OLinuXino-MICRO-4GB/ board, not a Cubie, but that uses the same Allwinner A20 dual core Cortex-A7 processor SoC, so most information at this level should be the same.  I have no control of which board to use, so suggestions about alternates are not helpful.  Someone else is designing/building the associated electronics.

I tried doing the work from linux, but even with maximum priority, PTHREAD_EXPLICIT_SCHED and SCHED_FIFO, I could not prevent interrupts of a time critical section of control code (need to process every 10 microseconds, but got 40 microsecond gaps about 40 times a second).

With above constraint, suggestions to access SPI and UART from linux are not helpful either.  The timing constraints on the second thread (whole cpu core being dedicated to it), mean that regular linux is not currently a viable alternative.  Maybe a full real time linux would do the job, but I do not have the resources to get that built, just to see if it *might* work.

Current development environment:
Gentoo 4.3.3-hardened-r4
crossdev --kernel =3.18 --libc =2.21-r2 --binutils =2.24-r3 --gcc =4.8.5 \
Building u-boot http://linux-sunxi.org/Mainline_U-Boot does not currently work with 5.x versions of gcc, so not too much room to move there.

So moved to writing as standalone code that is to be started from u-boot.  No extra delays there, but now I am missing something to configure other modules of the core.  When I try to initialize and configure SPI or UART devices (other than UART0, which is used for the u-boot console), all registers report zero, and stay there even after setting them.  It acts as if there is nothing (no hardware) there.  UART0 has reasonable/expected values, and configuring standard GPIO pins (input and output) works fine.  Configuring the multiplexed GPIO pins to be used by SPI or UART also appear to work, but the modules stubbornly refuse to admit they exist.

Sample code, Makefile, and output for attempting to talk to the SPI modules can be found in the post at:
https://www.olimex.com/forum/index.php?topic=5191.msg21599#msg21599
Note that the sample uses include files from the build of u-boot
The main documentation used to create that code is at
https://github.com/allwinner-zh/documents/blob/master/A20/A20_User_Manual_v1.4_20150510.pdf

Has anyone worked with A20 or similar chips, and figured out how to get access to the capabilities outside of linux?
Does someone know where to get some better documentation about programming at that level?  The user manual I have has lots of information about register addresses, offsets, bit masks, but nothing in the way of code examples.  I expect that a simple standalone C (or even assembler) example, that configured any of the (device) modules, and setup an interrupt to handle it, would be SO helpful in figuring out the rest.

I actually got the SPI communications to work by bit-banging the I/O pins.  That is not going to work for the UART, and SPI looks like a simpler case to work on first.

I've been programming for a lot of years on big systems, and some on very small (6502, 8085, arduinio) systems, but no real experience with development in this kind of environment.  I'm not a kernel programmer, or anything close.
--ĀµMerlin