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

Use Shared IRQ for stm32 ADC driver #37585

Closed

Conversation

mcscholtz
Copy link
Contributor

@mcscholtz mcscholtz commented Aug 10, 2021

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

@mcscholtz
Copy link
Contributor Author

Looks like the failures are due to the configurable prescalar change. I will take a look later when I have time

@mcscholtz
Copy link
Contributor Author

I was reading the contribution guidelines and I missed a few things, such as the commit signoff. I will fix that soon.

@mcscholtz mcscholtz force-pushed the feature/stm32f407-adc branch 2 times, most recently from ba886e5 to 124bdda Compare August 12, 2021 18:59
@mcscholtz
Copy link
Contributor Author

I fixed the styling issues that caused the compliance checks to fail before. I also veried it with the checkpatch script before pushing it.

Copy link
Contributor

@mbolivar-nordic mbolivar-nordic left a 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.

depends on ADC_STM32
help
Enable the use of shared interrupts for famalies that only have a single interrupt for all ADC's
endif
Copy link
Contributor

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.

Copy link
Contributor Author

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

@@ -227,7 +236,6 @@ struct adc_stm32_data {
const struct device *dev;
uint16_t *buffer;
uint16_t *repeat_buffer;

Copy link
Contributor

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.

@@ -239,12 +247,17 @@ struct adc_stm32_data {

struct adc_stm32_cfg {
ADC_TypeDef *base;
const uint16_t prescalar;
Copy link
Contributor

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.

Comment on lines 645 to 690
LOG_ERR("Conversion time not supportted.");
LOG_ERR("Conversion time not supported.");
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Comment on lines 445 to 446
reg = <0x40012000 0x400>;
reg = <0x40012000 0x50>;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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.

@mcscholtz mcscholtz force-pushed the feature/stm32f407-adc branch from 124bdda to 3eb045c Compare August 23, 2021 16:00
Copy link
Member

@erwango erwango left a 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 ?

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

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).

Comment on lines 445 to 446
reg = <0x40012000 0x400>;
reg = <0x40012000 0x50>;
Copy link
Member

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.

Comment on lines 1117 to 1121
#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
Copy link
Member

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

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

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

Choose a reason for hiding this comment

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

s/famalies/families

@mcscholtz
Copy link
Contributor Author

Then, have you been able to test these changes ?

We have a custom board using the stm32f407 and I have tested using multiple ADC's together and it is working.

@mcscholtz mcscholtz force-pushed the feature/stm32f407-adc branch 4 times, most recently from 6ef9dc8 to b00eee0 Compare August 26, 2021 23:05
Copy link
Member

@erwango erwango left a 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.

static const struct soc_gpio_pinctrl adc_pins_##index[] = \
ST_STM32_DT_INST_PINCTRL(index, 0); \
\
ADC_STM32_CONFIG_ISR(index) \
Copy link
Member

Choose a reason for hiding this comment

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

Unindent for readability.

}
}

#define ADC_STM32_CONFIG_ISR(index) \
Copy link
Member

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.

DT_INST_FOREACH_STATUS_OKAY(HANDLE_IRQS);
}

static void adc_stm32_cfg_func_isr(void)
Copy link
Member

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 ?

@mcscholtz mcscholtz force-pushed the feature/stm32f407-adc branch from b00eee0 to 06973db Compare August 30, 2021 22:08
@mcscholtz mcscholtz force-pushed the feature/stm32f407-adc branch from 4459091 to 24e1f3a Compare October 22, 2021 19:20
@ycsin
Copy link
Member

ycsin commented Oct 24, 2021

@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.

Copy link
Member

@MaureenHelm MaureenHelm left a 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.

@carlescufi
Copy link
Member

@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.

@mcscholtz
Copy link
Contributor Author

Closing. See #41497

@mcscholtz mcscholtz closed this Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ADC Analog-to-Digital Converter (ADC) area: Devicetree Binding PR modifies or adds a Device Tree binding area: Devicetree platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

STM32: Multiple ADCs using same interrupt not possible
8 participants