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
ESP32: Add driver support to SPI Master and Slave #1422
Conversation
@@ -81,25 +81,23 @@ config ESP32_SDMMC | |||
---help--- | |||
No yet implemented | |||
|
|||
config ESP32_SPI0 |
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.
What's the reason to remove SPI0 and SPI1? SPI0 is somewhat special, but the difference with SPI1 is that SPI2 and 3 can be configured as slaves.
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.
Yes, that was the idea, it only support SPI2 and SPI3 because these ports can be master or slave. The code should be modified in the future to support SPI0 and SPI1
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.
Shouldn't then only the slave source code be dependent on CONFIG_ESP32_SPI2 || CONFIG_ESP32_ESP3
? The master code is similar, right?
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.
Good point! I agree! You are right, thank you very much Abde!
if ESP32_SPI2 | ||
|
||
config ESP32_SPI2_CSPIN | ||
int "SPI2 CS Pin" |
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.
Shouldn't these SPI pins be configured by board logic? Similar to other boards.
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.
Since the pins definition for ESP32 UART and other are already in the Kconfig, I think it is better to keep it this way.
arch/xtensa/src/esp32/esp32_spi.c
Outdated
extern uint8_t esp32_spi2_status(FAR struct spi_dev_s *dev, uint32_t devid); | ||
extern uint8_t esp32_spi3_status(FAR struct spi_dev_s *dev, uint32_t devid); |
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.
For other architectures, these are prototyped in the header file (arch/xtensa/src/esp32/esp32_spi.h in this case) and implemented in the board logic.
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.
Yes, I'm moving it to the header
****************************************************************************/ | ||
|
||
static int esp32_spi_lock(FAR struct spi_dev_s *dev, bool lock); | ||
static void esp32_spi_select(FAR struct spi_dev_s *dev, |
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 is also prototyped in the header file and implemented in board logic.
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 think only spi_select should be in the header, at least on stm32 and nrf52 I only found _select, not _lock.
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.
Yes, I was referring to spi_select not _lock.
@xiaoxiang781216 I think these recent modifications on CI broke the xtensa build, it appears that ${{matrix.boards}}.dat wasn't updated: "cd sources/testing USAGE: /github/workspace/sources/nuttx/tools/testbuild.sh [-l|m|c|u|g|n] [-d] [-e ] [-x] [-j ] [-a ] [-t ] [-p] [-G] |
FAR struct esp32_spi_priv_s *priv = (FAR struct esp32_spi_priv_s *)dev; | ||
const uint32_t duty_cycle = 128; | ||
|
||
if (frequency > ((APB_CLK_FREQ / 4) * 3)) |
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.
Higher level drivers use setfrequency/setmode/setbits before every SPI transaction to make sure that the bus is in the state that the driver wants it to be. To avoid having to do all of what follows, usually we test if the frequency hasn't changed, if so we just return. Something like:
if (priv->frequency == frequency)
{
/* We are already at this frequency. Return the actual. */
return priv->actual;
}
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.
Good point Abdelatif! Thank you!
That's because the config matrix was only updated in testing/. It's trivial, I can provide a fix for that. #1424 and its sister in apps/ should do. |
It didn't fix/update the issue: cd sources/testing USAGE: /github/workspace/sources/nuttx/tools/testbuild.sh [-l|m|c|u|g|n] [-d] [-e ] [-x] [-j ] [-a ] [-t ] [-p] [-G] Where: |
You'll need to rebase. I doubt that the checks would pass however. As I said there is another PR that selects the right toolchain, and then there are some warnings in the AVR build. |
This driver was implemented by Dong Heng <dongheng@espressif.com> and modified to fix coding style by Alan Carvalho de Assis.
Summary
This driver was implemented by Dong Heng dongheng@espressif.com
and modified to fix coding style by Alan Carvalho de Assis.
Impact
New feature to ESP32
Testing
ESP-WROVER-KIT