Page 1 of 1

STM32F Arduino register setup

Posted: Sat Aug 28, 2021 1:01 pm
by mikedb
Arduino with the Official ST micro core.

I would like to know where the actual registers is setup.
This is a small snippet of code in "wiring_analog.c"

Code: Select all

#if defined(HAL_ADC_MODULE_ENABLED) && !defined(HAL_ADC_MODULE_ONLY)
  PinName p = analogInputToPinName(ulPin);
  if (p != NC) {
    value = adc_read_value(p, _internalReadResolution);
    value = mapResolution(value, _internalReadResolution, _readResolution);
  }
#else
  UNUSED(ulPin);
#endif
  return value;
}
But where and how is the actual registers setup from the HAL_ setup?
Like in the sample below.

Code: Select all

RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN |         // Enable clock to GPIO port C
RCC_AHB1ENR_DMA1EN;                                       // Enable DMA1
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;            // Enable clock to TIM2 timer
GPIOC->MODER |= GPIO_MODER_MODER0_1;        // Set D8 (PC0) as alterntive function
GPIOC->AFR[0] |= GPIO_AFRL_AFSEL0_0;     

Thanks in advance.

Re: STM32F Arduino register setup

Posted: Sat Aug 28, 2021 1:12 pm
by fpiSTM
In the adc_read_value().

Re: STM32F Arduino register setup

Posted: Sat Aug 28, 2021 1:21 pm
by mikedb
Where is adc_read_value();

This is the Library path on my pc.

Code: Select all

C:\Users\me\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.0.0\cores\arduino

Re: STM32F Arduino register setup

Posted: Sat Aug 28, 2021 1:30 pm
by fpiSTM
First it is not a library it is a core ;)

The BSP was moved in a library to avoid issue with Arduino cache feature.
https://github.com/stm32duino/Arduino_C ... g.cpp#L748

Re: STM32F Arduino register setup

Posted: Sat Aug 28, 2021 1:44 pm
by mikedb
Thanks ... But.

This code:

Code: Select all

HAL_ADC_MODULE_ENABLED
Must somehow do this:

Code: Select all

ADC1->CR2 |= 1 << 0; // ADON =1 enable ADC1
How is the HAL_ instruction converted to set the ADON bit in the ADC1 Register?

Re: STM32F Arduino register setup

Posted: Sat Aug 28, 2021 1:48 pm
by fpiSTM
The goal of using HAL or LL API is to not be aware of this. So if you want check that, simply dig into all HAL API.

Re: STM32F Arduino register setup

Posted: Sat Aug 28, 2021 1:57 pm
by mikedb
Thanks I will do some searching.

Re: STM32F Arduino register setup

Posted: Sat Aug 28, 2021 4:15 pm
by mikedb
Dont know if this will show up twice but nothing happend when I clicked - submit -

Code: Select all

#define __HAL_RCC_SYSCFG_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_SYSCFGEN))
#define __HAL_RCC_ADC1_CLK_DISABLE()   (RCC->APB2ENR &= ~(RCC_APB2ENR_ADC1EN))
#define __HAL_RCC_TIM1_CLK_DISABLE()   (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM1EN))
#define __HAL_RCC_SPI1_CLK_DISABLE()   (RCC->APB2ENR &= ~(RCC_APB2ENR_SPI1EN))
#define __HAL_RCC_TIM16_CLK_DISABLE()  (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM16EN))
#define __HAL_RCC_TIM17_CLK_DISABLE()  (RCC->APB2ENR &= ~(RCC_APB2ENR_TIM17EN))
#define __HAL_RCC_USART1_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_USART1EN))
#define __HAL_RCC_DBGMCU_CLK_DISABLE() (RCC->APB2ENR &= ~(RCC_APB2ENR_DBGMCUEN))
#define __HAL_RCC_SYSCFG_IS_CLK_ENABLED()     ((RCC->APB2ENR & (RCC_APB2ENR_SYSCFGEN)) != RESET)
#define __HAL_RCC_ADC1_IS_CLK_ENABLED()       ((RCC->APB2ENR & (RCC_APB2ENR_ADC1EN))   != RESET)