cpu/stm32l0 : implementation of ADC driver#7815
Conversation
aabadie
left a comment
There was a problem hiding this comment.
Thanks for your PR. As usual I found some (minor) style issues.
I'll test on hardware when time permits.
|
|
||
| /** | ||
| * @name ADC configuration | ||
| * @name ADC configuration |
There was a problem hiding this comment.
This change is not 'valid', we want to keep 4 spaces after @name
| * @{ | ||
| */ | ||
| #define ADC_NUMOF (0) | ||
| #define ADC_CONFIG { \ |
There was a problem hiding this comment.
The backslashes could be vertically aligned
| { GPIO_PIN(PORT_A, 6), 6 }, \ | ||
| } | ||
|
|
||
| #define ADC_NUMOF (1U) |
cpu/stm32l0/periph/adc.c
Outdated
| } | ||
|
|
||
| if ((ADC1->CR & ADC_CR_ADEN) != 0) /* (1) */ | ||
| { |
There was a problem hiding this comment.
The opening curly brace should be at the end of the if line
cpu/stm32l0/periph/adc.c
Outdated
| } | ||
|
|
||
| if ((ADC1->CR & ADC_CR_ADEN) == 0) | ||
| { |
cpu/stm32l0/periph/adc.c
Outdated
| prep(); | ||
|
|
||
| switch (res) { | ||
| case ADC_RES_6BIT: |
There was a problem hiding this comment.
the case block should be indented
cpu/stm32l0/periph/adc.c
Outdated
|
|
||
| /* Disable ADC before renenabling it */ | ||
| if ((ADC1->CR & ADC_CR_ADEN) != 0) /* (1) */ | ||
| { |
There was a problem hiding this comment.
curly brace on same line as if
cpu/stm32l0/periph/adc.c
Outdated
| } | ||
|
|
||
| if ((ADC1->CR & ADC_CR_ADEN) == 0) | ||
| { |
cpu/stm32l0/periph/adc.c
Outdated
| gpio_init_analog(adc_config[line].pin); | ||
| } | ||
|
|
||
| if ((ADC1->CR & ADC_CR_ADEN) != 0) /* (1) */ |
There was a problem hiding this comment.
What does (1) mean ?
Some code could also be factorized in a static function here, I see can the same code some lines below in adc_sample
cpu/stm32l0/periph/adc.c
Outdated
|
|
||
| /* Disable ADC */ | ||
| if ((ADC1->CR & ADC_CR_ADEN) != 0) /* (1) */ | ||
| { |
Marc-Aurele
left a comment
There was a problem hiding this comment.
Tested on NUCLEO-L073 and a custom board.
|
Here is the code that i used to test : Don't forget to initialize ADC : |
|
For testing, you can also use the application in |
| */ | ||
| #define ADC_NUMOF (0) | ||
| #define ADC_CONFIG { \ | ||
| { GPIO_PIN(PORT_A, 0), 17 }, \ |
There was a problem hiding this comment.
According to the nucleo boards datasheet section 6.11, table 18 page 46, the default configuration of ADC pins should be something like:
/**
* @name ADC configuration
* @{
*/
#define ADC_CONFIG { \
{ GPIO_PIN(PORT_A, 0), 0 }, \
{ GPIO_PIN(PORT_A, 1), 1 }, \
{ GPIO_PIN(PORT_A, 4), 4 }, \
{ GPIO_PIN(PORT_B, 0), 8 }, \
{ GPIO_PIN(PORT_C, 1), 11 },\
{ GPIO_PIN(PORT_C, 0), 10 } \
}
#define ADC_NUMOF (6)
/** @} */
cpu/stm32l0/periph/adc.c
Outdated
| static void _enable_adc(void) | ||
| { | ||
| if ((ADC1->CR & ADC_CR_ADEN) != 0) { | ||
| ADC1->CR |= ADC_CR_ADDIS; |
There was a problem hiding this comment.
indentation is off: 8 spaces instead of 4. Same issue in the block below
cpu/stm32l0/periph/adc.c
Outdated
| prep(); | ||
|
|
||
| if ((adc_config[line].chan != 17) && (adc_config[line].chan != 18)) { | ||
| /*configure the pin */ |
There was a problem hiding this comment.
nit: space missing after /*
cpu/stm32l0/periph/adc.c
Outdated
| gpio_init_analog(adc_config[line].pin); | ||
| } | ||
|
|
||
| ADC1->CFGR1 = 0; //no watchdog, no discontinuous mode, no auto off, single conv, no trigger, right align, 12bits, no dma, no wait |
There was a problem hiding this comment.
Please use C-style comments, e.g /* */ here and below. For readability and reviewability in Github, you should also split the long lines.
|
Thanks for updating @Marc-Aurele. Code style wise, everything is ok now. I gave it a try on my nucleo-l073 using the Can you test on your side ? Maybe you have an idea of what is missing/wrong ? |
|
Thank you very much for the reviews. I'm sry for the inconveniences, i will try to improve my patches in the future. |
|
@Marc-Aurele your updated version works like a charm now, good job ! Can you squash your commits into 2 with comments: each commit should be related to changes in the corresponding directories. Murdock is passing now, so after squashing it can be merged. |
|
I have run the test tests/periph_adc on a nucleo board but it seems there is a kernel panic due to xtimer_periodic_wakeup. I'm not sure this panic is related to my patch. |
I tested on nucleo-l073 since it's the only one configured by your PR. On which one have you tried (could nucleo-l053 or nucleo32-l031) ? |
aabadie
left a comment
There was a problem hiding this comment.
Just had another look and I found 2 remaining minor issues.
cpu/stm32l0/periph/adc.c
Outdated
| #include "mutex.h" | ||
| #include "periph/adc.h" | ||
|
|
||
| #ifdef ADC_CONFIG |
There was a problem hiding this comment.
Here it shoud be:
#ifdef ADC_NUMOFThere was a problem hiding this comment.
Are you sure about this ? Because it is done like this everywhere else.
| { GPIO_PIN(PORT_C, 0), 10 } \ | ||
| } | ||
|
|
||
| #define ADC_NUMOF (6) |
There was a problem hiding this comment.
Maybe update to:
#define ADC_NUMOF (6U)Now, ADC is available on stm32l0 family. A calibration is done at each new adc_sample. Moreover, when conversion is done, VREFINT and temperature sensor are dactivated to save power. Signed-off-by: Aurelien Fillau <[email protected]>
ADC configuration added for nucleo-l073 board Signed-off-by: Aurelien Fillau <[email protected]>
|
Now, test is running very well. I have only nucleo-l073 and custom boards i have made to test. I'm pretty sure the kernel panic i have faced was not related to this patch. I'm suspecting a PSP (process stack pointer) not initialized or something like that because the board was panicking at the first context switch but not sure. |
aabadie
left a comment
There was a problem hiding this comment.
Regarding the kernel panic, this looks weird indeed. But the L0 clock initialization is not perfect as @haukepetersen said one day. It could be one of the reason. Since it's unrelated (I think), let's merge.
ACK and go, thanks @Marc-Aurele !
Now, ADC is available on stm32l0 family. A calibration is
done at each new adc_sample to avoid error, especially during voltage variation. Moreover, when conversion is done, VREFINT and temperature sensor are dactivated to save power and reactivated at next adc_sample.
Signed-off-by: Aurelien Fillau [email protected]