SPI wont work on STM32F4 (?)

strawberrymaker
Wed Dec 23, 2015 10:34 pm
So im playing along with a stm32f4 chip (for a secret project, atleast for now) and im trying to get spi to work.

I tried already a minimal sketch (just #include <SPI.h>) and a little Sketch for the ILI9341 mentioned here

The minimal fails with following error code:


In file included from C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:32:0:
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.h:362:17: error: conflicting declaration 'SPIClass SPI'
extern SPIClass SPI;//(1);// dummy params
^
In file included from C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\cores\maple/wirish.h:49:0,
from C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.h:47,
from C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:32:
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\cores\maple/libmaple/HardwareSPI.h:276:20: error: 'SPI' has a previous declaration as 'HardwareSPI SPI'
extern HardwareSPI SPI;
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp: In member function 'uint8 SPIClass::dmaTransfer(uint8*, uint8*, uint16)':
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:380:63: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_attach_interrupt(dma_dev*, dma_stream, void (*)())'
dma_attach_interrupt(DMA1, DMA_CH3, &SPIClass::DMA1_CH3_Event);
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:385:82: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_setup_transfer(dma_dev*, dma_stream, volatile void*, volatile void*, volatile void*, uint32, uint32)'
receiveBuf, DMA_SIZE_8BITS, (DMA_MINC_MODE | DMA_TRNS_CMPLT));// receive buffer DMA
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:386:45: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_set_num_transfers(dma_dev*, dma_stream, uint16)'
dma_set_num_transfers(DMA1, DMA_CH2, length);
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:394:84: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_setup_transfer(dma_dev*, dma_stream, volatile void*, volatile void*, volatile void*, uint32, uint32)'
transmitBuf, DMA_SIZE_8BITS, (DMA_FROM_MEM | DMA_TRNS_CMPLT));// Transmit FF repeatedly
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:398:101: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_setup_transfer(dma_dev*, dma_stream, volatile void*, volatile void*, volatile void*, uint32, uint32)'
transmitBuf, DMA_SIZE_8BITS, (DMA_MINC_MODE | DMA_FROM_MEM | DMA_TRNS_CMPLT));// Transmit buffer DMA
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:400:45: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_set_num_transfers(dma_dev*, dma_stream, uint16)'
dma_set_num_transfers(DMA1, DMA_CH3, length);
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:402:26: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_enable(dma_dev*, dma_stream)'
dma_enable(DMA1, DMA_CH2);// enable receive
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:403:26: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_enable(dma_dev*, dma_stream)'
dma_enable(DMA1, DMA_CH3);// enable transmit
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:419:30: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_disable(dma_dev*, dma_stream)'
dma_disable(DMA1, DMA_CH3);
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:420:27: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_disable(dma_dev*, dma_stream)'
dma_disable(DMA1, DMA_CH2);
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp: In member function 'uint8 SPIClass::dmaSend(uint8*, uint16, bool)':
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:437:63: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_attach_interrupt(dma_dev*, dma_stream, void (*)())'
dma_attach_interrupt(DMA1, DMA_CH3, &SPIClass::DMA1_CH3_Event);
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:442:58: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_setup_transfer(dma_dev*, dma_stream, volatile void*, volatile void*, volatile void*, uint32, uint32)'
transmitBuf, DMA_SIZE_8BITS, flags);// Transmit buffer DMA
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:443:45: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_set_num_transfers(dma_dev*, dma_stream, uint16)'
dma_set_num_transfers(DMA1, DMA_CH3, length);
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:444:26: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_enable(dma_dev*, dma_stream)'
dma_enable(DMA1, DMA_CH3);// enable transmit
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:451:27: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_disable(dma_dev*, dma_stream)'
dma_disable(DMA1, DMA_CH3);
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp: In member function 'uint8 SPIClass::dmaSend(uint16*, uint16, bool)':
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:462:63: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_attach_interrupt(dma_dev*, dma_stream, void (*)())'
dma_attach_interrupt(DMA1, DMA_CH3, &SPIClass::DMA1_CH3_Event);
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:467:59: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_setup_transfer(dma_dev*, dma_stream, volatile void*, volatile void*, volatile void*, uint32, uint32)'
transmitBuf, DMA_SIZE_16BITS, flags);// Transmit buffer DMA
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:468:45: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_set_num_transfers(dma_dev*, dma_stream, uint16)'
dma_set_num_transfers(DMA1, DMA_CH3, length);
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:469:26: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_enable(dma_dev*, dma_stream)'
dma_enable(DMA1, DMA_CH3);// enable transmit
^
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\SPI\src\SPI.cpp:476:27: error: cannot convert 'dma_channel' to 'dma_stream' for argument '2' to 'void dma_disable(dma_dev*, dma_stream)'
dma_disable(DMA1, DMA_CH3);
^
Error compiling


martinayotte
Wed Dec 23, 2015 11:00 pm
Hi straw,

I’m using a lot the SPI under F4 for connecting both SdCard reader and also ENC28J60 Network adaptor.

For the HardwareSPI error, I’ve the commented “//extern HardwareSPI SPI;” at the end of HardwareSPI.h, because you can have 2 SPI declarations at the same time. (I think I forgot to commit this small change)

I’ve also commented every thing related to DMA, because it was coming from F1 and I didn’t get chance to adapt it for F4 yet.

If you comments those the same way, is your sketch compile ?


strawberrymaker
Wed Dec 23, 2015 11:44 pm
Seems like the Last line of the HardwareSPI.h does something, but it wont work out really nice. Using a simple sketch, it compiles. But as soon as it start to use standard SPI commands (SPI.begin) it wont compile again. One example would be a ported Adafruit GFX Library (SSD1351).

Commented out:

C:\Users\Matjas\Documents\Arduino\libraries\Adafruit_SSD1351-STM32-master\Adafruit_SSD1351.cpp: In member function 'void Adafruit_SSD1351::spiwrite(uint8_t)':
C:\Users\Matjas\Documents\Arduino\libraries\Adafruit_SSD1351-STM32-master\Adafruit_SSD1351.cpp:41:9: error: 'SPI' was not declared in this scope
SPI.transfer(c);
^
C:\Users\Matjas\Documents\Arduino\libraries\Adafruit_SSD1351-STM32-master\Adafruit_SSD1351.cpp: In member function 'void Adafruit_SSD1351::begin()':
C:\Users\Matjas\Documents\Arduino\libraries\Adafruit_SSD1351-STM32-master\Adafruit_SSD1351.cpp:356:9: error: 'SPI' was not declared in this scope
SPI.begin();
^
Error compiling.


martinayotte
Thu Dec 24, 2015 12:04 am
Are you including SPI.h or HardwareSPI.h ?
Because the whole HardwareSPI from LeafLab is probably garbage, and SPI is the one to be used.

strawberrymaker
Thu Dec 24, 2015 12:18 am
in the Library, SPI.h is used, but in the SPI.h it includes wirish, which in the end includes HardwareSPI.

martinayotte
Thu Dec 24, 2015 12:51 am
Yes, you’re right, it is present in wirish.h.
But it is commented in the F1 wirish.h, especially that HardwareSPI.* don’t exist anymore in F1.

Oooohh ! Those “spaghetti” legacy code make me pulling my hairs !
That is probably why I didn’t do the small commit forgotten mentioned above : it is useless since all HardwareSPI.* are useless, SPI.* is using hardware anyway…
If we clear out the issue, maybe I will commit a complete delete of HardwareSPI.* soon… ;)

But that doesn’t resolve your issue, we need to pin-point why the error occurs, since the log you provided shows compile time error not link time (if it was link time, it would mean that you simply forgotten to declare “SPIClass SPI(1);” in your main sketch)

Maybe I will need to download Adafruit GFX to give it a try.


strawberrymaker
Wed Dec 30, 2015 12:19 am
Well I made progress. It compiles, buut im getting a reference error:
C:\Users\Matjas\AppData\Local\Temp\build108003128975008063.tmp\Adafruit SSD1351 library\Adafruit_SSD1351.cpp.o: In function `Adafruit_SSD1351::spiwrite(unsigned char)':
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\Adafruit_SSD1351-STM32-master/Adafruit_SSD1351.cpp:41: warning: undefined reference to `SPIClass::transfer(unsigned char) const'
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\Adafruit_SSD1351-STM32-master/Adafruit_SSD1351.cpp:69: warning: undefined reference to `SPI'
C:\Users\Matjas\AppData\Local\Temp\build108003128975008063.tmp\Adafruit SSD1351 library\Adafruit_SSD1351.cpp.o: In function `Adafruit_SSD1351::begin()':
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\Adafruit_SSD1351-STM32-master/Adafruit_SSD1351.cpp:356: warning: undefined reference to `SPIClass::begin()'
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\Adafruit_SSD1351-STM32-master/Adafruit_SSD1351.cpp:357: warning: undefined reference to `SPIClass::setDataMode(unsigned char)'
C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F4\libraries\Adafruit_SSD1351-STM32-master/Adafruit_SSD1351.cpp:443: warning: undefined reference to `SPI'

mrburnette
Wed Dec 30, 2015 1:00 am
strawberrymaker wrote:
<…>
I just made it your way again, somehow it worked this time.

martinayotte
Wed Dec 30, 2015 2:49 am
Hi Straw,

This seems a bit odd since it compiled but errors are at link time.
Could you provide the log for link time command line, it looks like SPI.o is not included there …
(BTW, which Arduino IDE are you using ? I hope it is not the famous buggy 1.6.6…)


strawberrymaker
Wed Dec 30, 2015 1:34 pm
Im on mobile ATM, will post it when im home. i already switched to 1.6.5, read the github issue

strawberrymaker
Wed Dec 30, 2015 9:52 pm
Here’s the full output
Seems like spi.c.o is included in there

martinayotte
Thu Dec 31, 2015 4:40 pm
This compile look a bit strange, it is compiling with __STM32F1__ along with the F1xxx code instead of F4xxx.

Did you choose the proper board variant?

C:\Users\Matjas\Documents\Arduino\hardware\Arduino_STM32\STM32F1\system/libmaple


Leave a Reply

Your email address will not be published. Required fields are marked *