Skip to content

Commit 85094e0

Browse files
matthijskooijmanfpistm
authored andcommitted
Fix SPI pin matching check
This looks up the SPI module corresponding to each of pins passed and then uses `pinmap_merge_peripheral()` to merge this in a single pin. If not all pins map to the same SPI module, this should abort. The `pinmap_merge_peripheral` function returns NP to indicate a mismatch between the passed peripherals. However, when one of the arguments is already NP, this is not propagated into the function result, instead the other argument is simplly returned. In this case, the merging happens in two levels: First MISO and MOSI are merged, then SCK and SS are merged and finally the merged results are again merged. That means that if MISO and MISO mismatch, but SCK and SS match (or the other way around), the NP returned due to the mismatch is ignored and the final result is not NP, so no error is raised. This changes the code to also check the intermediate merge results for NP, to properly detect mismatches.
1 parent c670e31 commit 85094e0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: libraries/SPI/src/utility/spi_com.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb)
181181
obj->spi = pinmap_merge_peripheral(spi_data, spi_cntl);
182182

183183
// Are all pins connected to the same SPI instance?
184-
if (obj->spi == NP) {
184+
if (spi_data == NP || spi_cntl == NP || obj->spi == NP) {
185185
core_debug("ERROR: SPI pins mismatch\n");
186186
return;
187187
}

0 commit comments

Comments
 (0)