-
Notifications
You must be signed in to change notification settings - Fork 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
Use Shared IRQ for stm32 ADC driver #37585
Use Shared IRQ for stm32 ADC driver #37585
Conversation
Looks like the failures are due to the configurable prescalar change. I will take a look later when I have time |
I was reading the contribution guidelines and I missed a few things, such as the commit signoff. I will fix that soon. |
ba886e5
to
124bdda
Compare
I fixed the styling issues that caused the compliance checks to fail before. I also veried it with the checkpatch script before pushing 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.
Thanks for your first patch! I have some general coding style comments. Please remember to follow the contribution guidelines by squashing or splitting commits as needed, without piling on a series of "fix this, fix that" commits to address review feedback.
@erwango or another STM32 maintainer will need to do the hardware specific review, but the binding change looks fine to me.
drivers/adc/Kconfig.stm32
Outdated
depends on ADC_STM32 | ||
help | ||
Enable the use of shared interrupts for famalies that only have a single interrupt for all ADC's | ||
endif |
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.
Please add a newline to the end of the file.
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.
The compliance check failed after adding the new line at the end of the file
drivers/adc/adc_stm32.c
Outdated
@@ -227,7 +236,6 @@ struct adc_stm32_data { | |||
const struct device *dev; | |||
uint16_t *buffer; | |||
uint16_t *repeat_buffer; | |||
|
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.
We usually try not to include unrelated whitespace changes in commits which change functionality. I would recommend dropping this change or moving it to a separate commit.
drivers/adc/adc_stm32.c
Outdated
@@ -239,12 +247,17 @@ struct adc_stm32_data { | |||
|
|||
struct adc_stm32_cfg { | |||
ADC_TypeDef *base; | |||
const uint16_t prescalar; |
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.
No need for const
here as the entire structure is const
.
drivers/adc/adc_stm32.c
Outdated
LOG_ERR("Conversion time not supportted."); | ||
LOG_ERR("Conversion time not supported."); |
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.
You might want to split this into its own commit also.
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.
@mbolivar-nordic I can do that, would you recommend to just remove this and the other changes and force update the single comment. Then create new comments for the other changes, like the fix of this typo in this case?
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.
How people split up commits while rebasing is a personal decision, so I can't really offer you a "recommendation" in that sense. Beyond individual preference, tooling varies: for example, I use magit instead of the command line.
However, one simple way to handle this since the PR contains a single commit is to put all its changes back into the working tree:
git checkout feature/stm32f407-adc
git reset HEAD~
Then you can split changes in a single file into their own commits using git add -p
, e.g. for this particular comment:
git add -p drivers/adc/adc_stm32.c
< follow instructions to just stage this hunk>
git commit
<write a commit comment describing the typo fix>
Then keep adding additional commits for the other changes you want to make.
But again this sort of thing is subject to taste, and I would do it in a different way using my own favorite tools.
dts/arm/st/f4/stm32f4.dtsi
Outdated
reg = <0x40012000 0x400>; | ||
reg = <0x40012000 0x50>; |
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 this really part of the same commit? I think it needs a justification.
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.
@mbolivar-nordic The ADC1 device currently holds the address space for ADC1, ADC2, ADC3.
The address for all ADC's starts at 0x40012000 with a length of 0x400. The following is the addresses of the individual ADC's:
ADC1: 0x40012000 length of 0x50
ADC2: 0x40012100 length of 0x50
ADC3: 0x40012200 length of 0x50
Common: 0x40012300 length of 0xC (need to double check the length of this one)
Maybe someone that knows stm32 well can comment on how to handle 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.
OK, then yes, I think this definitely needs a justification and likely a separate commit.
Maybe someone that knows stm32 well can comment on how to handle it.
Let's wait to see what the STM32 maintainers say.
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 do agree with @mbolivar-nordic. Please split this in a dedicated commit.
124bdda
to
3eb045c
Compare
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.
Thanks for this addition!
Some changes requested otherwise this looks fine.
Then, have you been able to test these changes ?
drivers/adc/adc_stm32.c
Outdated
static const struct adc_stm32_cfg adc_stm32_cfg_##index = { \ | ||
.base = (ADC_TypeDef *)DT_INST_REG_ADDR(index), \ | ||
.prescalar = DT_INST_PROP_OR(index, prescalar, 4), \ | ||
.irq_cfg_func = adc_stm32_shared_irq_handler, \ |
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 part of the struct is actually meant to hold the irq init function, not the irq handler.
In current case, it should then be NULL if we don't want to use it.
Alternatively, it could be set to adc_stm32_cfg_func_isr
and use the init_irq
flag inside this function to make sure irq init is only done once (which would remove need for the adc_stm32_init
hack).
dts/arm/st/f4/stm32f4.dtsi
Outdated
reg = <0x40012000 0x400>; | ||
reg = <0x40012000 0x50>; |
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 do agree with @mbolivar-nordic. Please split this in a dedicated commit.
drivers/adc/adc_stm32.c
Outdated
#ifdef CONFIG_ADC_STM32_SHARED_IRQS | ||
DT_INST_FOREACH_STATUS_OKAY(STM32_ADC_INIT_SHARED) | ||
#else | ||
DT_INST_FOREACH_STATUS_OKAY(STM32_ADC_INIT) | ||
#endif |
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.
Alternative otpion is to put the #ifdef CONFIG_ADC_STM32_SHARED_IRQS
inside STM32_ADC_INIT
definition, to minimize code changes
drivers/adc/adc_stm32.c
Outdated
#if defined(CONFIG_SOC_SERIES_STM32F2X) || \ | ||
defined(CONFIG_SOC_SERIES_STM32F4X) || \ | ||
defined(CONFIG_SOC_SERIES_STM32F7X) | ||
static uint32_t adc_stm32_get_prescalar(uint16_t prescalar) |
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.
Please put the prescalar changes into a dedicated commit.
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.
Will do
drivers/adc/Kconfig.stm32
Outdated
default y | ||
depends on ADC_STM32 | ||
help | ||
Enable the use of shared interrupts for famalies that only have a single interrupt for all ADC's |
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.
s/famalies/families
We have a custom board using the stm32f407 and I have tested using multiple ADC's together and it is working. |
6ef9dc8
to
b00eee0
Compare
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.
Thanks for the update, few more comments.
drivers/adc/adc_stm32.c
Outdated
static const struct soc_gpio_pinctrl adc_pins_##index[] = \ | ||
ST_STM32_DT_INST_PINCTRL(index, 0); \ | ||
\ | ||
ADC_STM32_CONFIG_ISR(index) \ |
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.
Unindent for readability.
drivers/adc/adc_stm32.c
Outdated
} | ||
} | ||
|
||
#define ADC_STM32_CONFIG_ISR(index) \ |
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 why you used ADC_STM32_CONFIG_ISR
, but this is a bit misleading.
Let's use ADC_STM32_CONFIG
instead of ADC_STM32_CONFIG_ISR
.
drivers/adc/adc_stm32.c
Outdated
DT_INST_FOREACH_STATUS_OKAY(HANDLE_IRQS); | ||
} | ||
|
||
static void adc_stm32_cfg_func_isr(void) |
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 funtion is not technically an isr, what about adc_stm32_irq_init
?
b00eee0
to
06973db
Compare
4459091
to
24e1f3a
Compare
@mcscholtz You will have to rebase and make sure that you only have one ADC commit on top of the branch if you continue with this branch. |
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.
@mcscholtz You will have to rebase and make sure that you only have one ADC commit on top of the branch if you continue with this branch.
@MaureenHelm would you pick this PR up? Seems a shame not to merge it if the author is unresponsive. |
Closing. See #41497 |
I added the ability to use a shared IRQ for the stm32 ADC driver to allow devices with just a single ADC IRQ to use all channels.
Edit: This is my first PR, please let me know if I need to make any changes. Thanks!
Fixes #26874