STM32F Arduino register setup

Post here first, or if you can't find a relevant section!
Post Reply
mikedb
Posts: 5
Joined: Sat Aug 28, 2021 12:43 pm

STM32F Arduino register setup

Post 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.
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32F Arduino register setup

Post by fpiSTM »

In the adc_read_value().
mikedb
Posts: 5
Joined: Sat Aug 28, 2021 12:43 pm

Re: STM32F Arduino register setup

Post 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
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32F Arduino register setup

Post 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
mikedb
Posts: 5
Joined: Sat Aug 28, 2021 12:43 pm

Re: STM32F Arduino register setup

Post 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?
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32F Arduino register setup

Post 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.
mikedb
Posts: 5
Joined: Sat Aug 28, 2021 12:43 pm

Re: STM32F Arduino register setup

Post by mikedb »

Thanks I will do some searching.
mikedb
Posts: 5
Joined: Sat Aug 28, 2021 12:43 pm

Re: STM32F Arduino register setup

Post 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)
Post Reply

Return to “General discussion”