Official STMicroelectronics Arduino Core STM32F4 HAL compatibility (#11006)
This commit is contained in:
committed by
Scott Lahteine
parent
4dbec774b5
commit
e0276d2f32
@@ -30,7 +30,7 @@
|
||||
* Adapted to the STM32F4 HAL
|
||||
*/
|
||||
|
||||
#ifdef STM32F4
|
||||
#if defined(STM32F4) || defined(STM32F4xx)
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Includes
|
||||
@@ -54,6 +54,7 @@ static SPISettings spiConfig;
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#if ENABLED(SOFTWARE_SPI)
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Software SPI
|
||||
// --------------------------------------------------------------------------
|
||||
@@ -81,8 +82,7 @@ void spiBegin(void) {
|
||||
#error SS_PIN not defined!
|
||||
#endif
|
||||
|
||||
SET_OUTPUT(SS_PIN);
|
||||
WRITE(SS_PIN, HIGH);
|
||||
OUT_WRITE(SS_PIN, HIGH);
|
||||
}
|
||||
|
||||
/** Configure SPI for specified SPI speed */
|
||||
@@ -90,14 +90,13 @@ void spiInit(uint8_t spiRate) {
|
||||
// Use datarates Marlin uses
|
||||
uint32_t clock;
|
||||
switch (spiRate) {
|
||||
case SPI_FULL_SPEED: clock = 20000000; break; // 13.9mhz=20000000 6.75mhz=10000000 3.38mhz=5000000 .833mhz=1000000
|
||||
case SPI_HALF_SPEED: clock = 5000000; break;
|
||||
case SPI_QUARTER_SPEED: clock = 2500000; break;
|
||||
case SPI_EIGHTH_SPEED: clock = 1250000; break;
|
||||
case SPI_SPEED_5: clock = 625000; break;
|
||||
case SPI_SPEED_6: clock = 300000; break;
|
||||
default:
|
||||
clock = 4000000; // Default from the SPI libarary
|
||||
case SPI_FULL_SPEED: clock = 20000000; break; // 13.9mhz=20000000 6.75mhz=10000000 3.38mhz=5000000 .833mhz=1000000
|
||||
case SPI_HALF_SPEED: clock = 5000000; break;
|
||||
case SPI_QUARTER_SPEED: clock = 2500000; break;
|
||||
case SPI_EIGHTH_SPEED: clock = 1250000; break;
|
||||
case SPI_SPEED_5: clock = 625000; break;
|
||||
case SPI_SPEED_6: clock = 300000; break;
|
||||
default: clock = 4000000; // Default from the SPI libarary
|
||||
}
|
||||
spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
|
||||
SPI.begin();
|
||||
@@ -128,7 +127,13 @@ uint8_t spiRec(void) {
|
||||
*/
|
||||
void spiRead(uint8_t* buf, uint16_t nbyte) {
|
||||
SPI.beginTransaction(spiConfig);
|
||||
SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte);
|
||||
|
||||
#ifdef STM32GENERIC
|
||||
SPI.dmaTransfer(0, const_cast<uint8_t*>(buf), nbyte);
|
||||
#else
|
||||
SPI.transfer((uint8_t*)buf, nbyte);
|
||||
#endif
|
||||
|
||||
SPI.endTransaction();
|
||||
}
|
||||
|
||||
@@ -156,10 +161,16 @@ void spiSend(uint8_t b) {
|
||||
void spiSendBlock(uint8_t token, const uint8_t* buf) {
|
||||
SPI.beginTransaction(spiConfig);
|
||||
SPI.transfer(token);
|
||||
SPI.dmaSend(const_cast<uint8_t*>(buf), 512);
|
||||
|
||||
#ifdef STM32GENERIC
|
||||
SPI.dmaSend(const_cast<uint8_t*>(buf), 512);
|
||||
#else
|
||||
SPI.transfer((uint8_t*)buf, (uint8_t*)0, 512);
|
||||
#endif
|
||||
|
||||
SPI.endTransaction();
|
||||
}
|
||||
|
||||
#endif // SOFTWARE_SPI
|
||||
|
||||
#endif // STM32F4
|
||||
#endif // STM32F4 || STM32F4xx
|
||||
|
||||
Reference in New Issue
Block a user