Skip to content

[NUCLEO_F334R8] Fix issue with multiple ADC initialization #809

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

Merged
merged 3 commits into from
Jan 8, 2015
Merged

[NUCLEO_F334R8] Fix issue with multiple ADC initialization #809

merged 3 commits into from
Jan 8, 2015

Conversation

bcostm
Copy link
Contributor

@bcostm bcostm commented Dec 22, 2014

No description provided.

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 24, 2014

The variables should be definitely private and the check does not work as expected , anyway, my question is if we can make this runtime check.

A pseudo code:

if (adc clock enabled && peripheral enabled) {
    return;
}

@bcostm
Copy link
Contributor Author

bcostm commented Jan 5, 2015

You are right the first code was not correct (it was just before end of year holidays...). I have changed it and it works ok.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 5, 2015

I meant, was an approach in some files already, recently also used here https://github.com/mbedmicro/mbed/pull/815/files - runtime check if it was already initialized

@bcostm
Copy link
Contributor Author

bcostm commented Jan 5, 2015

Yes, this is what I've done. During initialization I check if the ADC has been already initialized. If yes then I exit. But instead of reading an HW register I use a local variable...

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 5, 2015

Can you change that to use hw?

@bcostm
Copy link
Contributor Author

bcostm commented Jan 5, 2015

Yes I can do it but as you know, STM strategy is to avoid as much as possible to use hw registers and use STM32Cube HAL function instead. I've found that the "HAL_ADC_GetState" function can be used to check if the ADC is initialized or not. Is it ok to use this function ?

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 5, 2015

Looks good for that use, the definition of ADC State type:

typedef enum
{
  HAL_ADC_STATE_RESET                   = 0x00,    /*!< ADC not yet initialized or disabled */
  HAL_ADC_STATE_READY                   = 0x01,    /*!< ADC peripheral ready for use */
  HAL_ADC_STATE_BUSY                    = 0x02,    /*!< An internal process is ongoing */ 
  HAL_ADC_STATE_BUSY_REG                = 0x12,    /*!< Regular conversion is ongoing */
  HAL_ADC_STATE_BUSY_INJ                = 0x22,    /*!< Injected conversion is ongoing */
  HAL_ADC_STATE_BUSY_INJ_REG            = 0x32,    /*!< Injected and regular conversion are ongoing */
  HAL_ADC_STATE_TIMEOUT                 = 0x03,    /*!< Timeout state */
  HAL_ADC_STATE_ERROR                   = 0x04,    /*!< ADC state error */
  HAL_ADC_STATE_EOC                     = 0x05,    /*!< Conversion is completed */
  HAL_ADC_STATE_EOC_REG                 = 0x15,    /*!< Regular conversion is completed */
  HAL_ADC_STATE_EOC_INJ                 = 0x25,    /*!< Injected conversion is completed */
  HAL_ADC_STATE_EOC_INJ_REG             = 0x35,    /*!< Injected and regular conversion are completed */
  HAL_ADC_STATE_AWD                     = 0x06    /*!< ADC state analog watchdog */

}HAL_ADC_StateTypeDef;

@bcostm
Copy link
Contributor Author

bcostm commented Jan 5, 2015

I've just tried it but it doesn't work as I expected unfortunately. The returned state is for the AdcHandle variable and so I need to save this result for the two different ADCs and I need for this two local variables... This is even worse as before because with this method, I need to call a function instead of just reading a local variable... I've also tried to use two different handles (i.e. Adc1Handle and Adc2Handle) but here also there is two many code to add for managing this.

For my understanding, what is the problem to use local variables (i.e. adcx_inited) ? This is not the first time I use this method and I have duplicated it a long time ago from Freescale or NXP targets. And it is still in use for example in us_ticker hal for those targets.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 8, 2015

I'll merge this as it is. Thanks for looking again at this.

HAL should be stateless, this type of information can be retrieved from hw, thus no need to keep it in RAM.

0xc0170 added a commit that referenced this pull request Jan 8, 2015
NUCLEO_F334R8 - Fix issue with multiple ADC initialization
@0xc0170 0xc0170 merged commit 2acefb6 into ARMmbed:master Jan 8, 2015
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.

2 participants