Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPI Slave implementation for Photon and Electron (STM32F2) #882

Merged
merged 5 commits into from Mar 14, 2016

Conversation

avtolstoy
Copy link
Member

Implements #814 on Photon and Electron

Wiring SPI API changes:

  • void SPIClass::begin(SPI_Mode mode, uint16_t);
  • void SPIClass::onSelect(wiring_spi_select_callback_t user_callback);
  • void SPIClass::transferCancel();
  • int32_t SPIClass::available();

Basic usage example:
https://gist.github.com/avtolstoy/1bbd34a7e69f563d5d37

There are also two test applications in user/tests/wiring/spi_master_slave spi_master and spi_slave that showcase usage.

A couple of notes:

  • transfer() can be safely called before a Slave Select event occurs
  • transfer() can be safely provided with larger buffer size (transfer length). When Master deselects the Slave or application calls transferCancel() SPI peripheral will be disabled, transfer user callback will still be called to indicate end of DMA transfer, application can then check the actual transfer length by calling SPIClass::available()
  • Application can also track the state of pending transfer by calling SPIClass::available(), which will report actual number of bytes clocked in/out.
  • byte SPIClass::transfer(byte) is not supported in Slave mode

@@ -84,6 +91,9 @@ void HAL_SPI_DMA_Transfer(HAL_SPI_Interface spi, void* tx_buffer, void* rx_buffe
bool HAL_SPI_Is_Enabled_Old();
bool HAL_SPI_Is_Enabled(HAL_SPI_Interface spi);
void HAL_SPI_Info(HAL_SPI_Interface spi, hal_spi_info_t* info, void* reserved);
void HAL_SPI_Set_Callback_On_Select(HAL_SPI_Interface spi, HAL_SPI_Select_UserCallback cb);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add void* as a reserved parameter to these so we can extend later.

@m-mcgowan
Copy link
Contributor

Could you please rebase on develop and resolve the conflicts.

@m-mcgowan m-mcgowan added this to the 0.5.x milestone Mar 14, 2016
@avtolstoy
Copy link
Member Author

@m-mcgowan Done!

m-mcgowan added a commit that referenced this pull request Mar 14, 2016
SPI Slave implementation for Photon and Electron (STM32F2)
@m-mcgowan m-mcgowan merged commit 4af0049 into particle-iot:develop Mar 14, 2016
@m-mcgowan m-mcgowan mentioned this pull request Mar 17, 2016
17 tasks
avtolstoy added a commit to particle-iot/docs that referenced this pull request Mar 27, 2016
@rpbissonnette
Copy link

Hello.

My naive attempts at using the Photon SPI as a slave seem to stall after the first transfer. I see in the wiring tests I ought to be able to learn from that example. Using this invocation:

cd main make -d clean program-dfu PARTICLE_DEVELOP=1 PLATFORM=photon USE_SWD_JTAG=y MODULAR=y USE_SPI=SPI USE_CS=A2 TEST=wiring/spi_master_slave

My "USE_SPI=SPI USE_CS=A2 " didn't go where they should because it fails:

tests/wiring/spi_master_slave/spi_slave/spi_slave.cpp:11:2: error: #error Define USE_SPI
#error Define USE_SPI

When I just edit the two test programs to force in the defines:
`
#define USE_SPI SPI
#define USE_CS A2

#ifndef USE_SPI
#error Define USE_SPI
#endif

#ifndef USE_CS
#error Define USE_CS
#endif`

The sources compile without error - but the link phase fails with a multiple define problem:
../../../build/target/user/platform-6-m/tests/wiring/spi_master_slave//libuser.a(application.o):(.bss.SystemMode+0x0): multiple definition of SystemMode'
../../../build/target/user/platform-6-m/tests/wiring/spi_master_slave//libuser.a(application.o):(.bss.SystemMode+0x0): first defined here
collect2: error: ld returned 1 exit status
`
Could this because the Master/Slave are both trying to use the same libuser.a?

It should not matter, but I am using SuSE LEAP and my make is
GNU Make 4.0
which is breaking the build/test/build.bats expectation of 3.8.1

If anyone can help me get this test running I would be happy to add a setup readme to the directory.

I THINK this ought to be a very useful example as there seems to be more than enough confusion about using the Photo in slave mode.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants