-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[RFC, WIP] drivers/periph_spi: improve API of spi_acquire #15904
Conversation
cpu/stm32/periph/spi.c
Outdated
@@ -26,6 +26,8 @@ | |||
* @} | |||
*/ | |||
|
|||
#include <assert.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one also have #include "assert.h"
on line 34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks ! Now I m going back to #16727.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some MCU have SPI peripherals on different clock bus so we must add a bus parameter to the two new functions.
Unfortunately this also break SPI_CLK_*HZ macros...
- adapted to the new API (RIOT-OS#15904) - arbitrary bus speed support (improves RIOT-OS#16811)
But since |
Misclicked |
tests/periph_spi: printing and testing SPI clock rates drivers/periph_spi: change API of spi_acquire (from RIOT-OS#15904) drivers/periph_spi: add the `bus` parameter to spi_get_*() This was necessary for implementations where multiple devices can have different clock sources. This broke the macros SPI_CLK_* that were reverted to an enum. periph/spi: adapted to the new API Arbitrary speed support was added to all implementations where it was missing except kinetis. nrf52/periph/spi: moved in nfr5x_common (RIOT-OS#16814)
tests/periph_spi: printing and testing SPI clock rates drivers/periph_spi: change API of spi_acquire (from RIOT-OS#15904) drivers/periph_spi: add the `bus` parameter to spi_get_*() This was necessary for implementations where multiple devices can have different clock sources. This broke the macros SPI_CLK_* that were reverted to an enum. periph/spi: adapted to the new API Arbitrary speed support was added to all implementations where it was missing. nrf52/periph/spi: moved in nfr5x_common (RIOT-OS#16814)
But spi_clk_t is the output of spi_get_clk() which basically doing something like return a prescaler >= source_clock / target frequency. So it need to know which source_clock to use i.e. on same54-xpro (SAM0_GCLK_PERIPH / 2) for SPI_DEV(0), ( SAM0_GCLK_48MHZ / 2) for SPI_DEV(1), or SAM0_GCLK_MAIN for SPI_DEV(2) (SPI_ON_QSPI). Or on nucleo-f103rb APB2 (72MHz) for SPI_DEV(0) or APB1 (36MHz) for SPI_DEV(1). |
tests/periph_spi: printing and testing SPI clock rates drivers/periph_spi: change API of spi_acquire (from RIOT-OS#15904) drivers/periph_spi: add the `bus` parameter to spi_get_*() This was necessary for implementations where multiple devices can have different clock sources. This broke the macros SPI_CLK_* that were reverted to an enum. periph/spi: adapted to the new API Arbitrary speed support was added to all implementations where it was missing. nrf52/periph/spi: moved in nfr5x_common (RIOT-OS#16814)
tests/periph_spi: printing and testing SPI clock rates drivers/periph_spi: change API of spi_acquire (from RIOT-OS#15904) drivers/periph_spi: add the `bus` parameter to spi_get_*() This was necessary for implementations where multiple devices can have different clock sources. This broke the macros SPI_CLK_* that were reverted to an enum. periph/spi: adapted to the new API Arbitrary speed support was added to all implementations where it was missing. nrf52/periph/spi: moved in nfr5x_common (RIOT-OS#16814)
tests/periph_spi: printing and testing SPI clock rates drivers/periph_spi: change API of spi_acquire (from RIOT-OS#15904) drivers/periph_spi: add the `bus` parameter to spi_get_*() This was necessary for implementations where multiple devices can have different clock sources. This broke the macros SPI_CLK_* that were reverted to an enum. periph/spi: adapted to the new API Arbitrary speed support was added to all implementations where it was missing.
tests/periph_spi: printing and testing SPI clock rates drivers/periph_spi: change API of spi_acquire (from RIOT-OS#15904) drivers/periph_spi: add the `bus` parameter to spi_get_*() This was necessary for implementations where multiple devices can have different clock sources. This broke the macros SPI_CLK_* that were reverted to an enum. periph/spi: adapted to the new API Arbitrary speed support was added to all implementations where it was missing. 2023-06: - rebased on current master - some backports from 2022 RIOT-OS#18374 - 3 new implementations adapted (gd32v, rpx0xx, and esp32) - minial frequency asserts was replaced by return codes - useless upper frequency bounding removed from many implementations - SPI_DIV_UP was replaced by the new DIV_ROUND_UP from macros/math.h - driver clock configuration caching was removed from implementations where it exists because it should be done at application level with this new API - br computation was simplified for stm32 / gd32v as performace optimisation is no longer needed at this level and the inaccuracy of the fixed point arithmetic was unreliable for frequencies requested lower but close to resulting frequencies
tests/periph_spi: printing and testing SPI clock rates drivers/periph_spi: change API of spi_acquire (from RIOT-OS#15904) drivers/periph_spi: add the `bus` parameter to spi_get_*() This was necessary for implementations where multiple devices can have different clock sources. This broke the macros SPI_CLK_* that were reverted to an enum. periph/spi: adapted to the new API Arbitrary speed support was added to all implementations where it was missing. 2023-06: - rebased on current master - some backports from 2022 RIOT-OS#18374 - 3 new implementations adapted (gd32v, rpx0xx, and esp32) - minial frequency asserts was replaced by return codes - useless upper frequency bounding removed from many implementations - SPI_DIV_UP was replaced by the new DIV_ROUND_UP from macros/math.h - driver clock configuration caching was removed from implementations where it exists because it should be done at application level with this new API - br computation was simplified for stm32 / gd32v as performace optimisation is no longer needed at this level and the inaccuracy of the fixed point arithmetic was unreliable for frequencies requested lower but close to resulting frequencies
tests/periph_spi: printing and testing SPI clock rates drivers/periph_spi: change API of spi_acquire (from RIOT-OS#15904) drivers/periph_spi: add the `bus` parameter to spi_get_*() This was necessary for implementations where multiple devices can have different clock sources. This broke the macros SPI_CLK_* that were reverted to an enum. periph/spi: adapted to the new API Arbitrary speed support was added to all implementations where it was missing. 2023-06: - rebased on current master - some backports from 2022 RIOT-OS#18374 - 3 new implementations adapted (gd32v, rpx0xx, and esp32) - minial frequency asserts was replaced by return codes - useless upper frequency bounding removed from many implementations - SPI_DIV_UP was replaced by the new DIV_ROUND_UP from macros/math.h - driver clock configuration caching was removed from implementations where it exists because it should be done at application level with this new API - br computation was simplified for stm32 / gd32v as performace optimisation is no longer needed at this level and the inaccuracy of the fixed point arithmetic was unreliable for frequencies requested lower but close to resulting frequencies
tests/periph_spi: printing and testing SPI clock rates drivers/periph_spi: change API of spi_acquire (from RIOT-OS#15904) drivers/periph_spi: add the `bus` parameter to spi_get_*() This was necessary for implementations where multiple devices can have different clock sources. This broke the macros SPI_CLK_* that were reverted to an enum. periph/spi: adapted to the new API Arbitrary speed support was added to all implementations where it was missing. 2023-06: - rebased on current master - some backports from 2022 RIOT-OS#18374 - 3 new implementations adapted (gd32v, rpx0xx, and esp32) - minial frequency asserts was replaced by return codes - useless upper frequency bounding removed from many implementations - SPI_DIV_UP was replaced by the new DIV_ROUND_UP from macros/math.h - driver clock configuration caching was removed from implementations where it exists because it should be done at application level with this new API - br computation was simplified for stm32 / gd32v as performace optimisation is no longer needed at this level and the inaccuracy of the fixed point arithmetic was unreliable for frequencies requested lower but close to resulting frequencies
tests/periph_spi: printing and testing SPI clock rates drivers/periph_spi: change API of spi_acquire (from RIOT-OS#15904) drivers/periph_spi: add the `bus` parameter to spi_get_*() This was necessary for implementations where multiple devices can have different clock sources. This broke the macros SPI_CLK_* that were reverted to an enum. periph/spi: adapted to the new API Arbitrary speed support was added to all implementations where it was missing. 2023-06: - rebased on current master - some backports from 2022 RIOT-OS#18374 - 3 new implementations adapted (gd32v, rpx0xx, and esp32) - minial frequency asserts was replaced by return codes - useless upper frequency bounding removed from many implementations - SPI_DIV_UP was replaced by the new DIV_ROUND_UP from macros/math.h - driver clock configuration caching was removed from implementations where it exists because it should be done at application level with this new API - br computation was simplified for stm32 / gd32v as performace optimisation is no longer needed at this level and the inaccuracy of the fixed point arithmetic was unreliable for frequencies requested lower but close to resulting frequencies
Contribution description
Note: only the last commit belongs to this PR, the rest are dependencies.
For specifying the SPI clock rather use a numeric value than a set of predetermined
enum
values. This has the following advantages:spi_acquire()
to fail. For sharing code between two MCU types with a different set of supported SPI cocks, this code would have to specify a clock supported by both MCUsReturning the actually used frequency can aid in a number of use cases:
ws281x
LEDs are using. This allows using the DMA for bit-banging, which can greatly improve responsiveness of the systemspi_acquire()
andspi_release()
can be easily computed.Testing procedure
Read the API. Once this API is agreed upon and all dependencies are merged, I can update the implementations. Once this is done, there something to test :-)
Issues/PRs references
Depends on and includes #15902