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

WIP: STM32F7 DMA per SPI #25

Closed
wants to merge 1 commit into from

Conversation

dagar
Copy link
Member

@dagar dagar commented Jul 9, 2018

Targeting PX4's NuttX branch for development and testing, but the intention is to upstream this.

@dagar dagar requested a review from davids5 July 9, 2018 22:04
@dagar dagar force-pushed the pr-stm32_spi_dma_bus branch from 51415bb to bca890d Compare July 9, 2018 22:13
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())
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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.

@@ -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
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was wondering about that, we'd have to further split spi_exchange.

image

image

Copy link
Member

@davids5 davids5 Jul 10, 2018

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

@LorenzMeier
Copy link
Member

@davids5 Could you please support this?

@LorenzMeier
Copy link
Member

@thomasgubler FYI

@dagar
Copy link
Member Author

dagar commented Aug 20, 2018

@davids5 review?

@dagar dagar force-pushed the pr-stm32_spi_dma_bus branch from 8731ed1 to ed45350 Compare September 11, 2018 16:59
@dagar
Copy link
Member Author

dagar commented Sep 11, 2018

Rebased on current px4_firmware_nuttx-7.22+

@dagar dagar force-pushed the pr-stm32_spi_dma_bus branch from ed45350 to 4d49e84 Compare September 11, 2018 22:23
@thomasgubler
Copy link

This will be picked up once there is functionality (PR) in PX4 that allows to test it

@dagar dagar force-pushed the pr-stm32_spi_dma_bus branch from 4d49e84 to 47f5bd9 Compare September 29, 2018 23:44
@dagar dagar requested a review from dakejahl October 17, 2018 15:01
@dakejahl
Copy link
Contributor

This has been successfully tested on SPI1 in PX4/PX4-Autopilot#10602

Copy link
Member

@davids5 davids5 left a 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

@@ -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
Copy link
Member

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

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())
Copy link
Member

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.

@@ -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) {
Copy link
Member

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


spi_modifycr2(priv, SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN, 0);
} else {
Copy link
Member

Choose a reason for hiding this comment

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

NCS

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

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

NCS

@dagar dagar force-pushed the pr-stm32_spi_dma_bus branch from 47f5bd9 to c8d1c67 Compare October 18, 2018 15:01
@dagar
Copy link
Member Author

dagar commented Oct 18, 2018

Updated for coding standards and rebased on current px4_firmware_nuttx-7.22+.

@dagar dagar dismissed davids5’s stale review October 18, 2018 15:01

Updated to coding standards.

davids5
davids5 previously approved these changes Oct 18, 2018
Copy link
Member

@davids5 davids5 left a 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!

@dagar
Copy link
Member Author

dagar commented Oct 18, 2018

@dagar dagar force-pushed the pr-stm32_spi_dma_bus branch from c8d1c67 to c808528 Compare October 18, 2018 19:46
@dagar dagar changed the title WIP: STM32 DMA per SPI WIP: STM32F7 DMA per SPI Oct 18, 2018
@dagar
Copy link
Member Author

dagar commented Oct 18, 2018

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
Copy link
Member

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

@davids5
Copy link
Member

davids5 commented Oct 19, 2018

Note to self: Vet F7 I2C driver, for same issues with ISR.

@dagar
Copy link
Member Author

dagar commented Jan 2, 2019

@dagar
Copy link
Member Author

dagar commented Jan 2, 2019

Upstream pull request merged (https://bitbucket.org/nuttx/nuttx/commits/3b55f35bb32852c53a85d60c645da7b324f1508f). Given the timing of our NuttX upgrade I won't bother backporting.

@dagar dagar closed this Jan 2, 2019
@dagar dagar deleted the pr-stm32_spi_dma_bus branch January 2, 2019 18:52
Jun-Tao added a commit to Jun-Tao/nuttx that referenced this pull request Jul 4, 2019
* bbm: Fix errors

* bbm: remove unnecessary code
PX4BuildBot pushed a commit that referenced this pull request Jan 5, 2020
    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).
PX4BuildBot pushed a commit that referenced this pull request Oct 11, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants