B-L475E-IOT01A

Discussions about the STM32generic core
Post Reply
oneselflost
Posts: 27
Joined: Mon Jul 24, 2017 2:32 am

B-L475E-IOT01A

Post by oneselflost » Wed Sep 20, 2017 4:19 am

Hey everyone,

I PR'd code to add the B-L475E-IOT01A board to the repository, and am currently working on adding some example libraries.

Looking at adding an Analog Read function, I ran into some errors while compiling:

Code: Select all

..\arduino_cache_337086\core\core_STM32GENERIC-master_STM32_DISCO_B_L475E_IOT01A_serial_SerialUART1_0a68d299c446a83dbd96d79f9783f0d6.a(stm32_ADC.c.o): In function `analogRead':

..STM32GENERIC-master\STM32\cores\arduino\stm32/stm32_ADC.c:94: undefined reference to `__HAL_RCC_ADC2_CLK_ENABLE'

..STM32GENERIC-master\STM32\cores\arduino\stm32/stm32_ADC.c:100: undefined reference to `__HAL_RCC_ADC3_CLK_ENABLE'
I did some investigating and found there was no reference to these in the "stm32l4xx_hal_rcc.h" file (..I think I'm looking in the right place?) but have no idea what needs to be added.

Can someone point me in the right direction here?

Thank you,
E

victor_pv
Posts: 1747
Joined: Mon Apr 27, 2015 12:12 pm

Re: B-L475E-IOT01A

Post by victor_pv » Wed Sep 20, 2017 4:31 am

Does the L475 have 3 ADCs? or perhaps it only has 1?

oneselflost
Posts: 27
Joined: Mon Jul 24, 2017 2:32 am

Re: B-L475E-IOT01A

Post by oneselflost » Wed Sep 20, 2017 4:36 am

3× 12-bit ADC 5 Msps, up to 16-bit with hardware oversampling, 200 μA/Msps

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: B-L475E-IOT01A

Post by danieleff » Wed Sep 20, 2017 7:50 am

ADC is the single most diverse peripheral in STM32, it seems every series is somewhat different.

I think on L4 they just share the same single clock source(?)

So add this to the top of stm32_ADC.c (after includes), and report back if it works, and can add it to the master:

Code: Select all

#ifndef __HAL_RCC_ADC2_CLK_ENABLE
#define __HAL_RCC_ADC2_CLK_ENABLE __HAL_RCC_ADC_CLK_ENABLE
#endif

#ifndef __HAL_RCC_ADC3_CLK_ENABLE
#define __HAL_RCC_ADC3_CLK_ENABLE __HAL_RCC_ADC_CLK_ENABLE
#endif

ChrisMicro
Posts: 308
Joined: Fri Mar 24, 2017 4:51 pm
Location: Germany

Re: B-L475E-IOT01A

Post by ChrisMicro » Wed Sep 20, 2017 3:39 pm

ADC is the single most diverse peripheral in STM32, it seems every series is somewhat different.
At least for the F429 disco ... the ADC is still not working .... ;-)

fpiSTM
Posts: 250
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: B-L475E-IOT01A

Post by fpiSTM » Wed Sep 20, 2017 3:52 pm

Maybe this can help, check which instance is used:

Code: Select all

  /* ADC Periph clock enable */
  if(hadc->Instance == ADC1) {
#ifdef __HAL_RCC_ADC1_CLK_ENABLE
	__HAL_RCC_ADC1_CLK_ENABLE();
#endif
#ifdef __HAL_RCC_ADC12_CLK_ENABLE
	__HAL_RCC_ADC12_CLK_ENABLE();
#endif
  }
#ifdef ADC2
  else if(hadc->Instance == ADC2) {
#ifdef __HAL_RCC_ADC2_CLK_ENABLE
	__HAL_RCC_ADC2_CLK_ENABLE();
#endif
#ifdef __HAL_RCC_ADC12_CLK_ENABLE
	__HAL_RCC_ADC12_CLK_ENABLE();
#endif
  }
#endif
#ifdef ADC3
  else if(hadc->Instance == ADC3) {
#ifdef __HAL_RCC_ADC3_CLK_ENABLE
    __HAL_RCC_ADC3_CLK_ENABLE();
#endif
#ifdef __HAL_RCC_ADC34_CLK_ENABLE
    __HAL_RCC_ADC34_CLK_ENABLE();
#endif
  }
#endif
#ifdef ADC4
  else if(hadc->Instance == ADC4) {
    __HAL_RCC_ADC34_CLK_ENABLE();
  }
#endif

#ifdef __HAL_RCC_ADC_CLK_ENABLE
  __HAL_RCC_ADC_CLK_ENABLE();
#endif
/* For STM32F1xx, ADC prescaler is configured in SystemClock_Config (variant.cpp) */
#if defined(__HAL_RCC_ADC_CONFIG) && !defined(STM32F1xx)
  /* ADC Periph interface clock configuration */
  __HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK);
#endif

oneselflost
Posts: 27
Joined: Mon Jul 24, 2017 2:32 am

Re: B-L475E-IOT01A

Post by oneselflost » Thu Sep 21, 2017 3:45 am

The additions to the ADC file that Daniel suggested got the Arduino IDE to at least compile and spit out an integer over the UART1 communication, however, the value (of about 480) did not change with a potentiometer connected. I will keep playing with it.

Thanks for the input, everyone.

fpiSTM
Posts: 250
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: B-L475E-IOT01A

Post by fpiSTM » Thu Sep 21, 2017 4:52 am

For the L4 you need to call the calibration befor the start conversion:

Code: Select all

 /*##-2.1- Calibrate ADC then Start the conversion process ####################*/
  if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK)
Edit:
I've checked the adc config:
https://github.com/danieleff/STM32GENER ... ADC.c#L181

the HAL_ADCEx_Calibration_Start() is not called that's probably why it's not working.

oneselflost
Posts: 27
Joined: Mon Jul 24, 2017 2:32 am

Re: B-L475E-IOT01A

Post by oneselflost » Sat Sep 23, 2017 3:31 am

@fpiSTM, thank you for looking into this.

I added this right below where you pointed: (so it would be ADC Start, ADC Cal, ADC Poll, then ADC stop - in that order)

Code: Select all

error = HAL_ADCEx_Calibration_Start(&handle, ADC_SINGLE_ENDED);
	if (error != HAL_OK) {
        PRINT_ERROR("HAL_ADCEx_Calibration_Start failed, error: %d", error);
        return 0;
    }
Changed ADCHandle to &handle, to align with the per-existing code.

This returned the ADC reading itself to 0, which is good because it's doing something - but it still does not read anything else other than zero.

I'll keep tinkering with it. Thanks again!

fpiSTM
Posts: 250
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: B-L475E-IOT01A

Post by fpiSTM » Sat Sep 23, 2017 7:20 am

You could have a look here to compare sequence
https://github.com/stm32duino/Arduino_C ... log.c#L554

Fyi, the L4 disco iot is now supported by the Arduino_Core_STM32. Moreover several libs have been released to support sensors, BLE,... WIFi, nfc, subghz will come in the coming weeks.

Post Reply