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

ad400x: Support for pulsar HDL and STM32 #2105

Merged
merged 16 commits into from
May 31, 2024
Merged

ad400x: Support for pulsar HDL and STM32 #2105

merged 16 commits into from
May 31, 2024

Conversation

ahaslam2
Copy link
Collaborator

@ahaslam2 ahaslam2 commented Feb 20, 2024

Pull Request Description

This PR adds:

  • support for stm32 with IIO
  • changes for new HDL that contains:
    • fixes for simple spi,
    • pwm
    • clkgen

HDL is not merged yet on main repo, but code was tested with:
https://github.com/adi-ses/sea-misc/tree/main/AD4000-PRJ/debug_single_conversion

PR Type

  • Bug fix (change that fixes an issue)
  • New feature (change that adds new functionality)
  • Breaking change (has dependencies in other repos or will cause CI to fail)

PR Checklist

  • I have followed the Coding style guidelines
  • I have performed a self-review of the changes
  • I have commented my code, at least hard-to-understand parts
  • I have build all projects affected by the changes in this PR
  • I have tested in hardware affected projects, at the relevant boards
  • I have signed off all commits from this PR
  • I have updated the documentation (wiki pages, ReadMe etc), if applies

drivers/adc/ad400x/ad400x.h Outdated Show resolved Hide resolved
projects/ad400x-st/README.rst Outdated Show resolved Hide resolved
@ahaslam2 ahaslam2 force-pushed the ad400x-stm32-iio branch 2 times, most recently from c286e34 to 89b96f2 Compare February 21, 2024 13:10
Copy link
Contributor

@rbolboac rbolboac left a comment

Choose a reason for hiding this comment

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

I still have to think a little bit about the spi chip select changes you have submitted, until then here are my remarks.

drivers/platform/stm32/stm32_spi.c Outdated Show resolved Hide resolved
include/no_os_spi.h Outdated Show resolved Hide resolved
drivers/adc/ad400x/iio_ad400x.h Show resolved Hide resolved
drivers/adc/ad400x/iio_ad400x.h Show resolved Hide resolved
drivers/adc/ad400x/iio_ad400x.h Outdated Show resolved Hide resolved
drivers/adc/ad400x/iio_ad400x.c Outdated Show resolved Hide resolved
drivers/adc/ad400x/iio_ad400x.c Outdated Show resolved Hide resolved
drivers/adc/ad400x/iio_ad400x.c Outdated Show resolved Hide resolved
drivers/adc/ad400x/ad400x.c Outdated Show resolved Hide resolved
projects/ad400x-st/src/common/common_data.c Outdated Show resolved Hide resolved
@ahaslam2
Copy link
Collaborator Author

I still have to think a little bit about the spi chip select changes you have submitted, until then here are my remarks.

There is onother option with these chips is leave the CS go low, but this would require SDI to be high.
this could be done by setting buf=0xFFFFFFFF before the spi operation.

@ahaslam2 ahaslam2 force-pushed the ad400x-stm32-iio branch 3 times, most recently from c977fd6 to c528fb9 Compare February 22, 2024 16:25
@ahaslam2
Copy link
Collaborator Author

changes in v2:

voltage ref patch squashed into iio/project patches.
changed licence agreement text in iio driver
expanded iio scan type table, and removed global scan_type variable
fixed scale factor
removed alloc from capture loop, used single 32 bit variable
add driver remove on iio remove
other minor fixes.

@rbolboac
Copy link
Contributor

I still have to think a little bit about the spi chip select changes you have submitted, until then here are my remarks.

There is onother option with these chips is leave the CS go low, but this would require SDI to be high. this could be done by setting buf=0xFFFFFFFF before the spi operation.

So please correct me if I am wrong: all you actually need for this driver is to have chip-select active high instead of active low, is that right?
If this is the case, I think it would be better to have an cs_active_high flag in the spi driver. the chip select is actual part of the SPI protocol and I find strange to make it optional in a spi driver. however, I think there are cases in which the polarity is inverted... this would ma a more acceptable approach.

drivers/adc/ad400x/ad400x.c Outdated Show resolved Hide resolved
drivers/adc/ad400x/ad400x.h Outdated Show resolved Hide resolved
drivers/adc/ad400x/iio_ad400x.c Outdated Show resolved Hide resolved
drivers/adc/ad400x/iio_ad400x.c Outdated Show resolved Hide resolved
drivers/adc/ad400x/iio_ad400x.c Outdated Show resolved Hide resolved
drivers/adc/ad400x/iio_ad400x.c Outdated Show resolved Hide resolved
drivers/adc/ad400x/iio_ad400x.h Show resolved Hide resolved
drivers/adc/ad400x/iio_ad400x.c Show resolved Hide resolved
projects/ad400x-st/README.rst Outdated Show resolved Hide resolved
@ahaslam2
Copy link
Collaborator Author

I still have to think a little bit about the spi chip select changes you have submitted, until then here are my remarks.

There is onother option with these chips is leave the CS go low, but this would require SDI to be high. this could be done by setting buf=0xFFFFFFFF before the spi operation.

So please correct me if I am wrong: all you actually need for this driver is to have chip-select active high instead of active low, is that right? If this is the case, I think it would be better to have an cs_active_high flag in the spi driver. the chip select is actual part of the SPI protocol and I find strange to make it optional in a spi driver. however, I think there are cases in which the polarity is inverted... this would ma a more acceptable approach.

this is not exactly right,he chip does not have a CS pin. its a conversion pin.

the issue with just inverting the polarity of the CS pin on the spi driver, is that
in fact to read/write the control register the CNV pin has to be low :(
(just realized need to add a toggle in register read/write too)

if you want to avoid handling the gpio on the driver:
the other option: setting buf to 0xFFFFFFFFF so SDI is high would allow
for CS pin to be low and read samples. the issue with this is that
the conversion starts on a rising edge of CNV, so if i read 1 sample for example: the sample
would be from past: from when the last SPI read finished and CS toggled from low to high.
would this be acceptable?

the above is what i see on the datasheet and from experiments:
https://www.analog.com/media/en/technical-documentation/data-sheets/ad4000-4004-4008.pdf

@ahaslam2
Copy link
Collaborator Author

changes v4:

  • toggle cnv gpio on register read/write
  • remove ref_voltage from driver init param
  • extend sign in case of signed channel

@rbolboac
Copy link
Contributor

rbolboac commented Feb 23, 2024

I still have to think a little bit about the spi chip select changes you have submitted, until then here are my remarks.

There is onother option with these chips is leave the CS go low, but this would require SDI to be high. this could be done by setting buf=0xFFFFFFFF before the spi operation.

So please correct me if I am wrong: all you actually need for this driver is to have chip-select active high instead of active low, is that right? If this is the case, I think it would be better to have an cs_active_high flag in the spi driver. the chip select is actual part of the SPI protocol and I find strange to make it optional in a spi driver. however, I think there are cases in which the polarity is inverted... this would ma a more acceptable approach.

this is not exactly right,he chip does not have a CS pin. its a conversion pin.

the issue with just inverting the polarity of the CS pin on the spi driver, is that in fact to read/write the control register the CNV pin has to be low :( (just realized need to add a toggle in register read/write too)

if you want to avoid handling the gpio on the driver: the other option: setting buf to 0xFFFFFFFFF so SDI is high would allow for CS pin to be low and read samples. the issue with this is that the conversion starts on a rising edge of CNV, so if i read 1 sample for example: the sample would be from past: from when the last SPI read finished and CS toggled from low to high. would this be acceptable?

the above is what i see on the datasheet and from experiments: https://www.analog.com/media/en/technical-documentation/data-sheets/ad4000-4004-4008.pdf

So we would like to avoid changing the SPI driver like that (seeing how for other platforms we will have to adapt this kind of behavior and it might not be possible to not have a chip select configured)... A workaround would be to simply have a dummy chip select in the project (which will not be connected to the chip) and then gpio_cnv pin can be used however is needed directly in the driver.

@ahaslam2
Copy link
Collaborator Author

I still have to think a little bit about the spi chip select changes you have submitted, until then here are my remarks.

There is onother option with these chips is leave the CS go low, but this would require SDI to be high. this could be done by setting buf=0xFFFFFFFF before the spi operation.

So please correct me if I am wrong: all you actually need for this driver is to have chip-select active high instead of active low, is that right? If this is the case, I think it would be better to have an cs_active_high flag in the spi driver. the chip select is actual part of the SPI protocol and I find strange to make it optional in a spi driver. however, I think there are cases in which the polarity is inverted... this would ma a more acceptable approach.

this is not exactly right,he chip does not have a CS pin. its a conversion pin.
the issue with just inverting the polarity of the CS pin on the spi driver, is that in fact to read/write the control register the CNV pin has to be low :( (just realized need to add a toggle in register read/write too)
if you want to avoid handling the gpio on the driver: the other option: setting buf to 0xFFFFFFFFF so SDI is high would allow for CS pin to be low and read samples. the issue with this is that the conversion starts on a rising edge of CNV, so if i read 1 sample for example: the sample would be from past: from when the last SPI read finished and CS toggled from low to high. would this be acceptable?
the above is what i see on the datasheet and from experiments: https://www.analog.com/media/en/technical-documentation/data-sheets/ad4000-4004-4008.pdf

So we would like to avoid changing the SPI driver like that (seeing how for other platforms we will have to adapt this kind of behavior and it might not be possible to not have a chip select configured)... A workaround would be to simply have a dummy chip select in the project (which will not be connected to the chip) and then gpio_cnv pin can be used however is needed directly in the driver.

ok, ill do that.

@ahaslam2 ahaslam2 closed this Feb 23, 2024
@ahaslam2 ahaslam2 force-pushed the ad400x-stm32-iio branch 2 times, most recently from 81da7c1 to cbffd43 Compare May 16, 2024 08:54
Copy link
Contributor

@rbolboac rbolboac left a comment

Choose a reason for hiding this comment

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

overall looks good

commit: e5210d3 has a typo add add a device
commit: 3b83e8f has a typo usies
also, I see all commits have really short lines for the commit message, you can have up to 72-characters per line for the commit description

Comment on lines 206 to 207


Copy link
Contributor

Choose a reason for hiding this comment

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

remove extra lines

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this extra line is not part of the latest push.

Copy link
Contributor

Choose a reason for hiding this comment

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

it is part of this commit: 5e09916
in general, in the same PR, we avoid fixing a problem we introduced with a later commit, rather we remove it in the commit it was introduced by rebasing.
this makes the review process easier, commit by commit

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, ill fix it there.

@ahaslam2
Copy link
Collaborator Author

ahaslam2 commented May 23, 2024

Change log:

  • fix 2 commit message typos.
  • use 72 line indent for commit message.

@ahaslam2
Copy link
Collaborator Author

changelog:

  • fixed white line in iio driver patch.

@rbolboac
Copy link
Contributor

seeing how there is no ad400x driver documentation, do you plan on adding that here?

The pulsar HDL now supports the ad400x parts.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Device id parameter is not set if using standard SPI. We need device
id to be able to set IIO attributes on the IIO driver.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
In standard SPI the CNV pin has to toggle before register access
or getting a conversion result.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
This adds device id's for more ad400x parts that can use this same
driver (AD4000, AD4001, AD4002, AD4004, AD4005, AD4006)

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
If offload is disabled, the xfer width must be byte aligned. We can
also simplify the macro wrappers around the set_xfer_width call.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Fixes to get correct data out of 4-wire turbo mode:

- For the chips that support 18 or 20 bit resolution, the least
  significant bits are in the higher nibble of the last byte.

- Sign needs to be taken into consideration when printing the result.

- The SDI line must remain high.

- Move the bit operations that format the data to the project file,
  as we can avoid the performance hit in the IIO case were scan_type
  gives this info to the app for post processing.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
This adds axi clkgen and pwm to support the pulsar HDL, clkgen will
ckl the spi_engine and pwm is used as offload trigger.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
use a pointer for spi_init parameters, to be consistent accross most
no-os projects, the parameters are passed by reference.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
In preparation for iio and making the projects platform independant,
move the offload code to the driver so it is simply enabled or not
by the project code.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Add initial IIO support for the ad400x driver.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
This migrates the ad400x project to the multiplatform sructure so
that we can add stm32 and iio examples

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
This adds the iio example project that makes use of the iio driver
for the ad400x.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
This adds the stm32 platfrom to the ad400x project. It uses the
standard spi of the stm32 and was tested using the sdp K1
development board.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
Instead of using separtate tables and exports, add a device info
structure to hold the per device resolution and sign.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
The functions are missing a check for null dev pointer.
This adds the check.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
@ahaslam2
Copy link
Collaborator Author

seeing how there is no ad400x driver documentation, do you plan on adding that here?

I added the driver README.

This adds the project and driver documentation.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
@ahaslam2 ahaslam2 merged commit 75514fe into main May 31, 2024
14 checks passed
@ahaslam2 ahaslam2 deleted the ad400x-stm32-iio branch May 31, 2024 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants