How to use SPI ports AND retain Flashlib support

Technical questions regarding the XTC tools and programming with XMOS.
kster59
XCore Addict
Posts: 162
Joined: Thu Dec 31, 2009 8:51 am

How to use SPI ports AND retain Flashlib support

Post by kster59 »

At bootup the XMOS uses ports 1A/B/C/D. After boot up I can recycle 3 of these lines by raising CS high. However, I want to use flashlib sometimes and can't seem to reuse the ports AND retain flashlib support despite the fact I only want to use flashlib only rarely to perform on the fly firmware updates.

Is there any example for retaining flashlib and using the ABCD ports?


User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

Can you explain a little more what is preventing this from working, do you have little more detail as I am also interested in this approach.

regards
Al
kster59
XCore Addict
Posts: 162
Joined: Thu Dec 31, 2009 8:51 am

Post by kster59 »

If you use Flashlib then you must define:

//define ports
fl_SPIPorts SPI={ XS1_PORT_1A, XS1_PORT_1B, XS1_PORT_1C, XS1_PORT_1D, XS1_CLKBLK_5};

Then you cannot define the pins as ports that you can use yourself.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

If you mean you can't use the fl_SPIPorts in another thread, then can't you use the same thread to handle both SPI operations?

Alternatively for a separate thread you can drop down to C and pass the unsigned resource ids of the ports between threads (by passing them over a channel for example) as long as you ensure both threads don't use them at once.

regards
Al
kster59
XCore Addict
Posts: 162
Joined: Thu Dec 31, 2009 8:51 am

Post by kster59 »

I only intend to call the SPI parts from one thread.

To use the XMOS SPI libraries you must define:

typedef struct spi_slave_interface {
clock blk;
in port ss;
in buffered port:8 mosi;
out buffered port:8 miso;
in port sclk;
} spi_slave_interface;

Since the same ports are used in the flash structure, the compile won't let you go.

If we had source code for flashlib then this would be easy to modify.

Since we don't then I don't see how to use both.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

If we had source code for flashlib then this would be easy to modify.
I couldn't agree more and have no idea why the flashlib code has not been opened on github like most everything else. This has been requested before I believe but I cannot find the relevant thread.


PS there is an aurora of black magic around flash with Xmos because of the obscurity of the code, openness hear could clear a lot up for many folk.
PPS The side effect of a closed flashlib will likely be folks writing there own flash drivers which is the last thing Xmos or its community need.

Update here are some useful bonus links I found after a search
Opening the tools:
https://www.xcore.com/forum/viewtopic.p ... lash#p8555

Boeserbaer rolls his own:
https://www.xcore.com/forum/viewtopic.p ... lash#p7866

Using an SD card on the SPI ports possible?
https://www.xcore.com/forum/viewtopic.p ... ilit=flash

Re-using the SPI FLASH port:
https://www.xcore.com/forum/viewtopic.p ... lash#p7140


regards
Al
User avatar
Paolomio
Experienced Member
Posts: 64
Joined: Tue Oct 05, 2010 7:33 pm

Post by Paolomio »

You should be able to do this using xlinks in the manner I've shown here: https://www.xcore.com/projects/runtime- ... ion-xlinks. You'll need to disable the links before you use the ports for flash access, then reenable them (and re-connect) when you are done. It may take a little cooperative work with whatever is connected on the other end (which must also be running the same routines).

Paul