AVR GCC port

ChibiOS public support forum for topics related to the Atmel AVR family of micro-controllers.

Moderator: tfAteba

Vik
Posts: 23
Joined: Mon Apr 15, 2013 9:30 pm

Re: AVR GCC port

Post by Vik »

Hi Giovanni, thanks for this.

PM sent. SPI support (based on Fabio Utzig's work) pushed into my tree in the meantime (https://github.com/viktorradnai/ChibiOS)

I modified the driver so it also works in slave mode which has the benefit that you can use two devices to test each other.

I don't think everything will work out of the box but I had two Arduinos talking to each other in polled mode using the small demo in testhal/AVR/SPI. Feedback is welcome as usual :)

Cheers,
Vik
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: AVR GCC port

Post by Giovanni »

The current SPI driver model does not support a slave mode, that kind of enhancement is necessarily a non-standard extension. I think a separate slave SPI driver model should be created but this is a task for ChibiOS 3.0.

Giovanni
Vik
Posts: 23
Joined: Mon Apr 15, 2013 9:30 pm

Re: AVR GCC port

Post by Vik »

Giovanni wrote:The current SPI driver model does not support a slave mode, that kind of enhancement is necessarily a non-standard extension. I think a separate slave SPI driver model should be created but this is a task for ChibiOS 3.0.


Actually the changes required to support slave mode on the AVR are really trivial. I didn't need to change the API so far, just added an extra configuration value in the SPIConfig struct. In the low level driver there is a switch-case statement containing 3 lines (setting data direction and a bit in a register). The only gotcha I've found is that the user should not call spiSelect() / spiUnselect() in slave mode.

By the way, have you got any plans to support multiple slaves on SPI? Something like an array of port and pin values, so you could have multiple slaves on the SPI bus without doing spiStart with a different config each time you want to talk to a different one?

Cheers,
Vik
utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Has thanked: 1 time
Been thanked: 20 times

Re: AVR GCC port

Post by utzig »

Hi Viktor,

I think it would better to halt this for now. I agree it should work for AVRs because the CS signal is done in HW and you have configured it to work as slave, so hopefully when you call spiSend it sends data on the MISO pin instead of MOSI as is done in the master. I'm not sure we'll be able to replicate this for every architecture though and we should investigate it before doing these more profound semantic HAL changes.
Vik
Posts: 23
Joined: Mon Apr 15, 2013 9:30 pm

Re: AVR GCC port

Post by Vik »

Hi Fabio,

The multi-slave stuff is really a question / feature request for 3.0. I have a project that would need it but it should be doable by using pal instead.

Slave support is pretty much all I wanted to get working as it gives me a very convenient way of testing the driver. That's now done and working without stepping on anything in the shared code. Btw, I'm on #chibios if you want to have a quick chat about this :)

Cheers,
Vik
Post Reply