-
Notifications
You must be signed in to change notification settings - Fork 205
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
WIP: STM32F7 DMA per SPI #25
Conversation
51415bb
to
bca890d
Compare
arch/arm/src/stm32/stm32_spi.c
Outdated
if (!(priv->rxch && priv->txch) || | ||
(txbuffer && !stm32_dmacapable((uint32_t)txbuffer, nwords, priv->txccr)) || | ||
(rxbuffer && !stm32_dmacapable((uint32_t)rxbuffer, nwords, priv->rxccr)) || | ||
up_interrupt_context()) |
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.
Is up_interrupt_context() is a PX4 specific thing, but not a general usage?
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.
I see it all over nuttx proper, although if it seems out of place here we could do something on the PX4 side to force it. I think that will be important for finding a way to do this incrementally.
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.
@dagar - I think it is an artifact of calling the SPI off the HRT. We will need to change that to upstream it.
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.
@dagar the more i think about it this is correct. A driver using SPI in interrupt context can not do the sem_wait.
arch/arm/src/stm32/Kconfig
Outdated
@@ -6381,6 +6381,48 @@ config STM32_SPI_DMA | |||
---help--- | |||
Use DMA to improve SPI transfer performance. Cannot be used with STM32_SPI_INTERRUPT. | |||
|
|||
config STM32_SPI1_DMA |
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.
Do we want to have TX and RX granularity on the DMA? TX are usually tiny. The DMA setup would take longer then the TX to the bus.
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.
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.
On second thought I don't think it makes any sense to split it because of the way SPI works we really need 2 DMA per SPI
@davids5 Could you please support this? |
@thomasgubler FYI |
64dfa70
to
8731ed1
Compare
@davids5 review? |
8731ed1
to
ed45350
Compare
Rebased on current px4_firmware_nuttx-7.22+ |
ed45350
to
4d49e84
Compare
This will be picked up once there is functionality (PR) in PX4 that allows to test it |
4d49e84
to
47f5bd9
Compare
This has been successfully tested on SPI1 in PX4/PX4-Autopilot#10602 |
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.
@dagar Looks Good. Just Coding standards. 4.4 for nested #ifdef and if then else Statement
arch/arm/src/stm32/stm32_spi.c
Outdated
@@ -290,8 +290,13 @@ static struct stm32_spidev_s g_spi1dev = | |||
.spiirq = STM32_IRQ_SPI1, | |||
#endif | |||
#ifdef CONFIG_STM32_SPI_DMA | |||
#ifdef CONFIG_STM32_SPI1_DMA |
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.
Indent the nested #if def
#ifdef CONFIG_ABC
# ifdef CONFIG_DEF
arch/arm/src/stm32/stm32_spi.c
Outdated
if (!(priv->rxch && priv->txch) || | ||
(txbuffer && !stm32_dmacapable((uint32_t)txbuffer, nwords, priv->txccr)) || | ||
(rxbuffer && !stm32_dmacapable((uint32_t)rxbuffer, nwords, priv->rxccr)) || | ||
up_interrupt_context()) |
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.
@dagar the more i think about it this is correct. A driver using SPI in interrupt context can not do the sem_wait.
arch/arm/src/stm32/stm32_spi.c
Outdated
@@ -1730,25 +1762,31 @@ static void spi_bus_initialize(FAR struct stm32_spidev_s *priv) | |||
* priority inheritance enabled. | |||
*/ | |||
|
|||
sem_init(&priv->rxsem, 0, 0); | |||
sem_init(&priv->txsem, 0, 0); | |||
if (priv->rxch && priv->txch) { |
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.
Coding standards. 4.4 if then else Statement (here after NCS)
http://nuttx.org/doku.php?id=documentation:codingstandard
arch/arm/src/stm32/stm32_spi.c
Outdated
|
||
spi_modifycr2(priv, SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN, 0); | ||
} else { |
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.
NCS
arch/arm/src/stm32f7/stm32_spi.c
Outdated
@@ -263,8 +263,13 @@ static struct stm32_spidev_s g_spi1dev = | |||
.spiirq = STM32_IRQ_SPI1, | |||
#endif | |||
#ifdef CONFIG_STM32F7_SPI_DMA | |||
#ifdef CONFIG_STM32F7_SPI1_DMA |
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.
Same as above
arch/arm/src/stm32f7/stm32_spi.c
Outdated
@@ -1704,25 +1736,31 @@ static void spi_bus_initialize(FAR struct stm32_spidev_s *priv) | |||
* priority inheritance enabled. | |||
*/ | |||
|
|||
sem_init(&priv->rxsem, 0, 0); | |||
sem_init(&priv->txsem, 0, 0); | |||
if (priv->rxch && priv->txch) { |
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.
NCS
47f5bd9
to
c8d1c67
Compare
Updated for coding standards and rebased on current px4_firmware_nuttx-7.22+. |
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.
@dagar Great! Thank you!
Upstream NuttX pull request. https://bitbucket.org/nuttx/nuttx/pull-requests/736/stm32-enable-separate-dma-per-spi/diff |
c8d1c67
to
c808528
Compare
Rebased on px4_firmware_nuttx-7.22+, PR now contains stm32f7 only. |
config STM32F7_SPI1_DMA | ||
bool "SPI1 DMA" | ||
default n | ||
depends on STM32F7_SPI_DMA |
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.
add the same chaed Greg did upstream
Note to self: Vet F7 I2C driver, for same issues with ISR. |
Upstream pull request for stm32f7. https://bitbucket.org/nuttx/nuttx/pull-requests/798/stm32f7-enable-separate-dma-per-spi/diff |
Upstream pull request merged (https://bitbucket.org/nuttx/nuttx/commits/3b55f35bb32852c53a85d60c645da7b324f1508f). Given the timing of our NuttX upgrade I won't bother backporting. |
* bbm: Fix errors * bbm: remove unnecessary code
Run all .c and .h files in last PR through nxstyle. Author: macman88 <jjlange91@gmail.com> SAME5x Ethernet Support (#25) boards/arm/samd5e5/same54-xplained-pro/: Adds basic support for Microchip SAM E54 Xplained Pro board. arch/arm/src/samd5e5/: Adds an Ethernet driver for the SAME5x family (based on the SAMA5 GMAC driver).
set CONFIG_PRIORITY_INHERITANCE=y set CONFIG_SEM_PREALLOCHOLDERS=0 or CONFIG_SEM_PREALLOCHOLDERS=8 #24 0x4dcab71 in __assert assert/lib_assert.c:37 #25 0x4d6b0e9 in nxsem_destroyholder semaphore/sem_holder.c:602 #26 0x4d80cf7 in nxsem_destroy semaphore/sem_destroy.c:80 #27 0x4d80db9 in sem_destroy semaphore/sem_destroy.c:120 #28 0x4dcb077 in nxmutex_destroy misc/lib_mutex.c:122 #29 0x4dc6611 in pipecommon_freedev pipes/pipe_common.c:117 #30 0x4dc7fdc in pipecommon_close pipes/pipe_common.c:397 #31 0x4ed4f6d in file_close vfs/fs_close.c:78 #32 0x6a91133 in local_free local/local_conn.c:184 #33 0x6a92a9c in local_release local/local_release.c:129 #34 0x6a91d1a in local_subref local/local_conn.c:271 #35 0x6a75767 in local_close local/local_sockif.c:797 #36 0x4e978f6 in psock_close socket/net_close.c:102 #37 0x4eed1b9 in sock_file_close socket/socket.c:115 #38 0x4ed4f6d in file_close vfs/fs_close.c:78 #39 0x4ed1459 in nx_close_from_tcb inode/fs_files.c:754 #40 0x4ed1501 in nx_close inode/fs_files.c:781 #41 0x4ed154a in close inode/fs_files.c:819 #42 0x6bcb9ce in property_get kvdb/client.c:307 #43 0x6bcd465 in property_get_int32 kvdb/common.c:270 #44 0x5106c9a in tz_offset_restore app/miwear_bluetooth.c:745 #45 0x510893f in miwear_bluetooth_main app/miwear_bluetooth.c:1033 #46 0x4dcf5c8 in nxtask_startup sched/task_startup.c:70 #47 0x4d70873 in nxtask_start task/task_start.c:134 #48 0x4e04a07 in pre_start sim/sim_initialstate.c:52 Signed-off-by: ligd <liguiding1@xiaomi.com>
Targeting PX4's NuttX branch for development and testing, but the intention is to upstream this.