-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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] Board config: SPI & I2C config simplifications #14156
Conversation
- v5 + v3 configured + boot (but lots of drivers disabled)
We only need one DEVTYPE per physical interface, and in fact handling both has made more of a mess. I think we could migrate them safely with a hook at parameter import time.
I think we should consider explicitly not supporting these cases (at the cost of flash short term). In many cases it starts off simple enough, but gradually gets worse over time as we discover the devices aren't so similar after all. We saw this happen when the mpu9250 driver was extended to support the icm20689. Partial list of differences between Invensense drivers (#14064). Depending on how we want to handle old boards and variants we'll need a mechanism to handle alternate sensors on a chip select. The ms5607 could be started only if the ms5611 fails, or ideally with a different board manifest entirely. |
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.
@bkueng - this looks great!
All the resets will need to be verified with a scope.
We have to come to an agreement on what is FMUx compatible. The remapping of CS can be avoided with separate bin files. If we enhance the boot loaded it can do the HW detection an supply the alternate ID. or we just add targets more BL targets.
boards/px4/fmu-v3/src/spi.cpp
Outdated
initSPIDevice(DRV_GYR_DEVTYPE_MPU6000, SPI::CS{GPIO::PortC, GPIO::Pin2}), | ||
|
||
// Cube 2.1 | ||
initSPIDevice(DRV_GYR_DEVTYPE_MPU9250, SPI::CS{GPIO::PortC, GPIO::Pin2}), |
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.
@bkueng Can you bake in the HW version here and simplify the select 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 added the versions in c3531af. This makes it indeed much cleaner and allows to use the generic chip-select code (not done yet).
@@ -266,16 +324,32 @@ __EXPORT uint8_t stm32_spi6status(FAR struct spi_dev_s *dev, uint32_t devid) | |||
* | |||
************************************************************************************/ | |||
|
|||
#define _PIN_OFF(def) (((def) & (GPIO_PORT_MASK | GPIO_PIN_MASK)) | (GPIO_INPUT|GPIO_PULLDOWN|GPIO_SPEED_2MHz)) |
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.
These needs to be tested with a scope! Also have a look at v5x it had multiple power domains.
@bkueng How does the code size look? |
This will allow to remove SPI locking as the bus is only accessed by a single thread (if only PX4 drivers access it).
as it will not work with together with the new SPI board config (which specifies a specific device type)
While the SPI/I2C configuration is being improved, I hope it can also be considered to solve 2 issues I encountered while working on code changes in pull request #14168 . The 1st issue is that currently it's possible for one SPI device driver to execute code that should be only applied to I2C driver of the same device. Here is an example, mpu9250 is started in SPI mode with command like "mpu9250 -S start", and you would expect that the driver would only execute code for SPI driver, not code for I2C driver. However in USE_I2C macro is defined in mpu9250.h as the following: #if defined(PX4_I2C_OBDEV_MPU9250) || defined(PX4_I2C_BUS_EXPANSION) define USE_I2C#endif When PX4_I2C_BUS_EXPANSION is also defined in board_config.h for another sensor, then USE_I2C will be defined for mpu9250 and I2C portion of the driver code will be executed although you intend to use mpu9250 in SPI code. The 2nd issue is that SPI driver and I2C driver of the same device cannot be used on the same board. PX4 supports redundant sensors, so this issue could arise. For example, when running out available SPI interfaces, one might want to hook up the sensor using I2C bus. Although usually a different sensor is used as backup sensor, one could choose to use the same sensor with I2C interface. Also there are reports that multiple IMU sensors arranged in different orientations could improve accuracy, so it might be possible to use multiple same IMU devices in the future. |
Yes, this definitely needs to be fixed. I'll look into it.
This will be possible as well. Are you referring to the same issue as above (USE_I2C)? |
Closing this, as it is brought in in separate parts. |
Next round after #13871: SPI + I2C
Summary
Similar to the PWM config, we can configure SPI buses and devices:
This is then mapped to a constant data-structure that the drivers can query. Currently they use
bus_options
structs with lots of ifdefs. The PR replaces this by a generic bus iterator class, which can be used to generically select internal/external I2C/SPI buses. For example the 1. external SPI bus can be selected with:Details & Goals
DRV_*_DEVTYPE_*
. This has pro's and con's:Steps to complete
Note: this is obviously far from complete. It runs on v3 and v5 with a small set of drivers.
I think we can go in steps with this:
@dagar @davids5