2 years, 7 months ago.

why am in geting 30 Erors just by importing the "STM32L4xx_HAL_Driver"

Hy, i am new here, and i tried to import the STM32L4xx_HAL_Driver Library, because i wana use the Oversampler in my NUCLEO-L432KC and there for i have to wite to the ADCx_CFGR register. But after importing the STM32L4xx_HAL_Driver i got 30 Error the various things like VREFBUF are undefint. Is it my mistake, or du i hve to define this things in MY code ? Is is there maybe another way to write the ADCx_CFGR register, without the Driver Library ?

Thanks

2 Answers

2 years, 7 months ago.

Simon -

You don’t have to import the STM HAL driver library to use the drivers. The "mbed.h" header file contains the appropriate HAL header files and library functions you need.

I have found the STM HAL driver libraries to be pretty easy to use with mbed, but I had to discover a trick to get them to play together. I have not worked with the ADC HAL drivers, but I have successfully used the HAL drivers to implement USART DMA transfers with the NUCLEO-L432KC and several other Nucleo boards.

First, you probably want to download a copy of the STM32L4 HAL firmware library if you have not already done so. This firmware library contains the same drivers as the "mbed.h" header file, but it also contains a number of examples that will help you understand how to use the driver library. The HAL firmware library for the NUCLEO-L432KC is STM32CubeL4. The current version is 1.8.0 as of this writing. [Note that this is NOT the STMCubeMX code generator.] You will also want to download the user manual UM1884 for the STM32L4 HAL library. You probably already have the reference manual RM0393 for the STM32L432KC MCU that describes the peripheral function registers. Note that the STM32L4 HAL firmware library includes the "ADC OverSampler" example for the NUCLEO-L432KC, which will probably help you with your application.

The STM HAL drivers each use a specific handle structure for configuring the various peripherals. There is an "init" structure for each peripheral. The HAL library includes macros to write to specific peripheral registers, which are accessed through the appropriate elements of the peripheral's init structure. Once the peripheral is initialized, you pass its handle to the various library functions to cause the peripheral to perform the desired operations.

mbed initializes the peripheral when you declare it, so the trick is get make sure that instance of the peripheral that is declared in the mbed setup is attached to the specific peripheral handle that you have declared for use with the HAL drivers. With this trick, you can use the simplicity of mbed for the low level hardware setup and then add the particular HAL driver functions that you want to exploit.

Again, I have not used the ADC HAL drivers, but I think the setup using mbed goes something like this:

1) declare a handle for the ADC; you may want to make this handle static

ADC_HandleTypeDef AdcHandle     // ADC handle structure defined in "stm32l4xx_hal_adc_ex.h"

2) declare and initialize the analog input pin using the mbed AnalogIn function

AnalogIn ain(PA_4)     // PA_4 is the input pin used in "ADC OverSampler" example

3) associate the ADC handle with the particular ADC used by the analog input pin declared in Step 2; the STM32L432KC MCU has only one ADC (ADC1)

AdcHandle.Instance = ADC1     // ADC1 is defined in "stm32l432xx.h"

From here you should be able to configure the ADC as done in the "ADC OverSampler" example. The second element of the ADC_HandleTypeDef structure is an ADC_InitTypeDef structure. This structure is defined in "stm32l4xx_hal_adc_ex.h". The elements of the ADC_InitTypeDef structure allow you to directly access the registers of the ADC. The macros to write to the ADCx_CFGR and ADCx_CFGR2 registers are in "stm32l4xx_hal_adc.h" and "stm32l4xx_hal_adc_ex.h", respectively.

JR

Accepted Answer

Thank you very much for your very detailed answer.

posted by Simon Arndt 17 May 2017
2 years, 7 months ago.

I believe all required STM432 HAL header files are already include in "mbed.h".