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

SPI v3 implementation for stm32h7 #1468

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

slorquet
Copy link
Contributor

@slorquet slorquet commented Feb 6, 2023

Including reorganization of existing stm32 spi cores.

Rationale:

The old SPI code hierarchy was:
spi_common_v1 -> spi_common_all
spi_common_v2 -> spi_common_all

But the spiv3 changes a lot of small details, so most of the spi_common_all file cannot be reused without conditional compilation (which is not welcome if I understand correctly) : Many functions work with the same logic, but use same (or different) bits in different registers.

So only the really common code was kept in spi_common_all, and everything that is common to spiv1 and spiv2 was moved to a new file spi_v12, resulting in the new hierarchy:

spi_common_v1 -> spi_common_v12 -> spi_common_all
spi_common_v2 -> spi_common_v12 -> spi_common_all
spi_common_v3 -> spi_common_all

I tried to avoid this but it cannot be avoided because most of the bits that were in common regs in v1 and v2 are now in new registers.

I know that the copyright of the files is not correct and I have no idea what else to put there

I did my best not to add dumb mistakes but I am ready to change anything required to bring this upstream.

Thank you for your review.

void spi_enable_rx_dma(uint32_t spi);
void spi_disable_rx_dma(uint32_t spi);
void spi_set_standard_mode(uint32_t spi, uint8_t mode);
void spi_reset(uint32_t spi_peripheral);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only common function for all three spi !

@@ -0,0 +1,390 @@
/** @addtogroup spi_defines
*
* @author @htmlonly &copy; @endhtmlonly 2009 Uwe Hermann <uwe@hermann-uwe.de>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did not change this because I copied the file, but the contents is not written by me.

/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2023 Sebastien Lorquet <sebastien@lorquet.fr>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not fully correct. We need to include other contributors who almost got this correct.

lib/stm32/common/spi_common_v12.c Show resolved Hide resolved
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also not correct...

lib/stm32/common/spi_common_v3.c Outdated Show resolved Hide resolved
*/

int spi_init_master(uint32_t spi, uint8_t clkdiv, bool cpol, bool cpha,
bool lsbfirst, bool keepgpio)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

at least do we agree on this definition? should keepgpio be predefined here and modifiable by a pair of dedicated functions?

SPI_CFG2(spi) |= SPI_CFG2_LSBFRST;
} else {
SPI_CFG2(spi) &= ~SPI_CFG2_LSBFRST;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW why are these spi_init_master functions in all spi versions not calling the individual access routines?

@slorquet
Copy link
Contributor Author

slorquet commented Feb 6, 2023

I have fixed tab and space issues.

@slorquet
Copy link
Contributor Author

slorquet commented Feb 8, 2023

Please review again.

@slorquet
Copy link
Contributor Author

slorquet commented Mar 7, 2023

Wow, this pull request has become so cold it will start to freeze.

@josuah
Copy link

josuah commented Apr 19, 2023

What about a first shot only introducing spi_common_v3?

Before:
spi_common_v1 (+1/-1) -> spi_common_v12 (+123/-0) -> spi_common_all (+123/-123)
spi_common_v2 (+1/-1) -> spi_common_v12 (+123/-0) -> spi_common_all (+123/-123)
spi_common_v3 (+1/-1) -> spi_common_all (+123/-123)

After:
spi_common_v1 (+0/-0) -> spi_common_all (+0/-0)
spi_common_v2 (+0/-0) -> spi_common_all (+0/-0)
spi_common_v3 (+123/-0)

In practice, given as you said,there is only spi_reset that is common to all, this would not be so hard to handle as an edge case.

The the patch would be very small: just addition of the extra code, maintaining the v1/v2 unchanged, easier to review, and then merging (the difficult part) could be done separately?

Hope that this helps in deciphering why these changes would get blocked from merging in silence.

@slorquet
Copy link
Contributor Author

slorquet commented Jun 6, 2023

first shoot or not this project is dead.

@josuah
Copy link

josuah commented Jun 7, 2023

If only I had the time to...

  1. fork
  2. write a coding style covering the content of each port: how the code and API (both #defines and C functions) should be structed
  3. rewrite all the code to match that coding style
  4. build something like the redcuttle project to test libopencm3 on silicon for all ports
  5. offer a lightweight patch to everyone using libopencm3 to move over to that fork
  6. once done, offer that fork to be the new version of libopencm3.

@josuah
Copy link

josuah commented Jun 7, 2023

This would be all about "breaking everything" while refactoring without the risk of breaking the projects relying on libopencm3, much alive themself with commits every weeks.

@slorquet
Copy link
Contributor Author

note: project still dead a year or so later.

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.

None yet

3 participants