Skip to content

Commit 73ec420

Browse files
Merge branch 'mitchmitchell-master'
2 parents e69cf8f + 096facf commit 73ec420

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

STM32F1/libraries/SPI/src/SPI.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,20 @@ SPIClass::SPIClass(uint32 spi_num)
120120

121121
// Init things specific to each SPI device
122122
// clock divider setup is a bit of hack, and needs to be improved at a later date.
123+
#if BOARD_NR_SPI >= 1
123124
_settings[0].spi_d = SPI1;
124125
_settings[0].clockDivider = determine_baud_rate(_settings[0].spi_d, _settings[0].clock);
125126
_settings[0].spiDmaDev = DMA1;
126127
_settings[0].spiTxDmaChannel = DMA_CH3;
127128
_settings[0].spiRxDmaChannel = DMA_CH2;
129+
#endif
130+
#if BOARD_NR_SPI >= 2
128131
_settings[1].spi_d = SPI2;
129132
_settings[1].clockDivider = determine_baud_rate(_settings[1].spi_d, _settings[1].clock);
130133
_settings[1].spiDmaDev = DMA1;
131134
_settings[1].spiTxDmaChannel = DMA_CH5;
132135
_settings[1].spiRxDmaChannel = DMA_CH4;
136+
#endif
133137
#if BOARD_NR_SPI >= 3
134138
_settings[2].spi_d = SPI3;
135139
_settings[2].clockDivider = determine_baud_rate(_settings[2].spi_d, _settings[2].clock);
@@ -550,12 +554,16 @@ void SPIClass::onReceive(void(*callback)(void)) {
550554
_currentSetting->receiveCallback = callback;
551555
if (callback){
552556
switch (_currentSetting->spi_d->clk_id) {
557+
#if BOARD_NR_SPI >= 1
553558
case RCC_SPI1:
554559
dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &SPIClass::_spi1EventCallback);
555560
break;
561+
#endif
562+
#if BOARD_NR_SPI >= 2
556563
case RCC_SPI2:
557564
dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &SPIClass::_spi2EventCallback);
558565
break;
566+
#endif
559567
#if BOARD_NR_SPI >= 3
560568
case RCC_SPI3:
561569
dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiRxDmaChannel, &SPIClass::_spi3EventCallback);
@@ -574,12 +582,16 @@ void SPIClass::onTransmit(void(*callback)(void)) {
574582
_currentSetting->transmitCallback = callback;
575583
if (callback){
576584
switch (_currentSetting->spi_d->clk_id) {
585+
#if BOARD_NR_SPI >= 1
577586
case RCC_SPI1:
578587
dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &SPIClass::_spi1EventCallback);
579588
break;
580-
case RCC_SPI2:
589+
#endif
590+
#if BOARD_NR_SPI >= 2
591+
case RCC_SPI2:
581592
dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &SPIClass::_spi2EventCallback);
582593
break;
594+
#endif
583595
#if BOARD_NR_SPI >= 3
584596
case RCC_SPI3:
585597
dma_attach_interrupt(_currentSetting->spiDmaDev, _currentSetting->spiTxDmaChannel, &SPIClass::_spi3EventCallback);
@@ -682,14 +694,18 @@ uint8 SPIClass::recv(void) {
682694
DMA call back functions, one per port.
683695
*/
684696

697+
#if BOARD_NR_SPI >= 1
685698
void SPIClass::_spi1EventCallback()
686699
{
687700
reinterpret_cast<class SPIClass*>(_spi1_this)->EventCallback();
688701
}
702+
#endif
689703

704+
#if BOARD_NR_SPI >= 2
690705
void SPIClass::_spi2EventCallback() {
691706
reinterpret_cast<class SPIClass*>(_spi2_this)->EventCallback();
692707
}
708+
#endif
693709
#if BOARD_NR_SPI >= 3
694710
void SPIClass::_spi3EventCallback() {
695711
reinterpret_cast<class SPIClass*>(_spi3_this)->EventCallback();

STM32F1/libraries/SPI/src/SPI.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ class SPISettings {
161161
Should move this to within the class once tested out, just for tidyness
162162
*/
163163
static uint8_t ff = 0XFF;
164+
#if BOARD_NR_SPI >= 1
164165
static void (*_spi1_this);
166+
#endif
167+
#if BOARD_NR_SPI >= 2
165168
static void (*_spi2_this);
169+
#endif
166170
#if BOARD_NR_SPI >= 3
167171
static void (*_spi3_this);
168172
#endif
@@ -411,8 +415,12 @@ class SPIClass {
411415

412416
void EventCallback(void);
413417

418+
#if BOARD_NR_SPI >= 1
414419
static void _spi1EventCallback(void);
420+
#endif
421+
#if BOARD_NR_SPI >= 2
415422
static void _spi2EventCallback(void);
423+
#endif
416424
#if BOARD_NR_SPI >= 3
417425
static void _spi3EventCallback(void);
418426
#endif

STM32F4/libraries/SPI/src/SPI.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ SPIClass::SPIClass(uint32 spi_num) {
124124
// SPI2: 1 / 0 / 3 - 1 / 0 / 4
125125
// SPI3: 1 / 0 / 0 (2) - 1 / 0 / 5 (7)
126126
/*****************************************************************************/
127+
#if BOARD_NR_SPI >= 1
127128
_settings[0].spi_d = SPI1;
128129
_settings[0].clockDivider = determine_baud_rate(_settings[0].spi_d, _settings[0].clock);
129130
#ifdef SPI_DMA
@@ -132,6 +133,8 @@ SPIClass::SPIClass(uint32 spi_num) {
132133
_settings[0].spiRxDmaStream = DMA_STREAM0; // alternative: DMA_STREAM2
133134
_settings[0].spiTxDmaStream = DMA_STREAM3; // alternative: DMA_STREAM5
134135
#endif
136+
#endif
137+
#if BOARD_NR_SPI >= 2
135138
_settings[1].spi_d = SPI2;
136139
_settings[1].clockDivider = determine_baud_rate(_settings[1].spi_d, _settings[1].clock);
137140
#ifdef SPI_DMA
@@ -140,6 +143,7 @@ SPIClass::SPIClass(uint32 spi_num) {
140143
_settings[1].spiRxDmaStream = DMA_STREAM3; // alternative: -
141144
_settings[1].spiTxDmaStream = DMA_STREAM4; // alternative: -
142145
#endif
146+
#endif
143147
#if BOARD_NR_SPI >= 3
144148
_settings[2].spi_d = SPI3;
145149
_settings[2].clockDivider = determine_baud_rate(_settings[2].spi_d, _settings[2].clock);

0 commit comments

Comments
 (0)