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

TMOTORF7V2 BlackBox fix #7955

Merged
merged 3 commits into from
Apr 27, 2022
Merged

Conversation

erstec
Copy link
Collaborator

@erstec erstec commented Apr 10, 2022

Fix for #7953

On STM32F7 TMOTORF7V2 FC uses PB2 as MOSI for SPI3, it is unique for this FC only.

PB2 is on AF7, but all other SPI3 pins are on AF6.

As INAV maps one AF resource for all SPI pins used on exact SPI periphery, I've added "check-and-adjust" for mentioned conditions.
It will affect only SPI3, only if MOSI pin is PB2 and only for F7's and H7's as they are same in this aspect.

@@ -189,6 +189,11 @@ bool spiInitDevice(SPIDevice device, bool leadingEdge)
IOConfigGPIOAF(IOGetByTag(spi->sck), SPI_IO_AF_SCK_CFG_HIGH, spi->af);
}
IOConfigGPIOAF(IOGetByTag(spi->miso), SPI_IO_AF_MISO_CFG, spi->af);

// If MOSI pin for SPI3 is PB2 -> AF7, not AF6
if (spiDeviceByInstance(spi->dev) == SPIDEV_3 && IO_TAG(SPI3_MOSI_PIN) == IO_TAG(PB2)) {
Copy link
Member

Choose a reason for hiding this comment

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

Can't we do it in a different way that is driven by a target file? We should avoid hacks like this as long as possible

Copy link
Collaborator Author

@erstec erstec Apr 12, 2022

Choose a reason for hiding this comment

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

I think it can be, in this case target file will contain additional defines (any combination of MOSI_AF, MISO_AF and SCK_AF) and use them if not - uses defaults.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@DzikuVx
Reworked.
Now custom SPI AF's can be taken from target.h if provided. In case they are not - "old" defaults are used (for compatibility).
If custom definintions are used, all three (SCK, MISO, MOSI) should be provided together, otherwise preprocessor error will appear.

@erstec erstec requested a review from DzikuVx April 13, 2022 05:44
@DzikuVx DzikuVx added this to the 5.0 milestone Apr 14, 2022
@DzikuVx
Copy link
Member

DzikuVx commented Apr 16, 2022

@erstec could you please rebase on master? GH actions seems to be stuck over here

@DzikuVx DzikuVx merged commit bdefb09 into iNavFlight:master Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants