Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions targets/TARGET_STM/TARGET_STM32F0/analogin_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@ uint16_t adc_read(analogin_t *obj)
HAL_ADC_Start(&obj->handle); // Start conversion

// Wait end of conversion and get value
uint16_t adcValue = 0;
if (HAL_ADC_PollForConversion(&obj->handle, 10) == HAL_OK) {
return (uint16_t)HAL_ADC_GetValue(&obj->handle);
} else {
return 0;
adcValue = (uint16_t)HAL_ADC_GetValue(&obj->handle);
}
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE((&obj->handle)->Instance), LL_ADC_PATH_INTERNAL_NONE);
return adcValue;
}

const PinMap *analogin_pinmap()
Expand Down
7 changes: 4 additions & 3 deletions targets/TARGET_STM/TARGET_STM32F1/analogin_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,12 @@ uint16_t adc_read(analogin_t *obj)
HAL_ADC_Start(&obj->handle); // Start conversion

// Wait end of conversion and get value
uint16_t adcValue = 0;
if (HAL_ADC_PollForConversion(&obj->handle, 10) == HAL_OK) {
return (uint16_t)HAL_ADC_GetValue(&obj->handle);
} else {
return 0;
adcValue = (uint16_t)HAL_ADC_GetValue(&obj->handle);
}
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE((&obj->handle)->Instance), LL_ADC_PATH_INTERNAL_NONE);
return adcValue;
}

const PinMap *analogin_pinmap()
Expand Down
4 changes: 4 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F1/device/stm32f1xx_hal_adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal_def.h"

/* Include low level driver */
#include "stm32f1xx_ll_adc.h"

/** @addtogroup STM32F1xx_HAL_Driver
* @{
*/
Expand Down
7 changes: 4 additions & 3 deletions targets/TARGET_STM/TARGET_STM32F2/analogin_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,12 @@ uint16_t adc_read(analogin_t *obj)
HAL_ADC_Start(&obj->handle); // Start conversion

// Wait end of conversion and get value
uint16_t adcValue = 0;
if (HAL_ADC_PollForConversion(&obj->handle, 10) == HAL_OK) {
return (uint16_t)HAL_ADC_GetValue(&obj->handle);
} else {
return 0;
adcValue = (uint16_t)HAL_ADC_GetValue(&obj->handle);
}
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE((&obj->handle)->Instance), LL_ADC_PATH_INTERNAL_NONE);
return adcValue;
}

const PinMap *analogin_pinmap()
Expand Down
3 changes: 3 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F2/device/stm32f2xx_hal_adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
/* Includes ------------------------------------------------------------------*/
#include "stm32f2xx_hal_def.h"

/* Include low level driver */
#include "stm32f2xx_ll_adc.h"

/** @addtogroup STM32F2xx_HAL_Driver
* @{
*/
Expand Down
2 changes: 1 addition & 1 deletion targets/TARGET_STM/TARGET_STM32F3/analogin_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ uint16_t adc_read(analogin_t *obj)
} else {
debug("HAL_ADC_PollForConversion issue\n");
}

LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE((&obj->handle)->Instance), LL_ADC_PATH_INTERNAL_NONE);
if (HAL_ADC_Stop(&obj->handle) != HAL_OK) {
debug("HAL_ADC_Stop issue\n");;
}
Expand Down
7 changes: 4 additions & 3 deletions targets/TARGET_STM/TARGET_STM32F4/analogin_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,12 @@ uint16_t adc_read(analogin_t *obj)
HAL_ADC_Start(&obj->handle); // Start conversion

// Wait end of conversion and get value
uint16_t adcValue = 0;
if (HAL_ADC_PollForConversion(&obj->handle, 10) == HAL_OK) {
return (uint16_t)HAL_ADC_GetValue(&obj->handle);
} else {
return 0;
adcValue = (uint16_t)HAL_ADC_GetValue(&obj->handle);
}
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE((&obj->handle)->Instance), LL_ADC_PATH_INTERNAL_NONE);
return adcValue;
}

const PinMap *analogin_pinmap()
Expand Down
7 changes: 4 additions & 3 deletions targets/TARGET_STM/TARGET_STM32F7/analogin_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,12 @@ uint16_t adc_read(analogin_t *obj)
HAL_ADC_Start(&obj->handle); // Start conversion

// Wait end of conversion and get value
uint16_t adcValue = 0;
if (HAL_ADC_PollForConversion(&obj->handle, 10) == HAL_OK) {
return (uint16_t)HAL_ADC_GetValue(&obj->handle);
} else {
return 0;
adcValue = (uint16_t)HAL_ADC_GetValue(&obj->handle);
}
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE((&obj->handle)->Instance), LL_ADC_PATH_INTERNAL_NONE);
return adcValue;
}

const PinMap *analogin_pinmap()
Expand Down
7 changes: 4 additions & 3 deletions targets/TARGET_STM/TARGET_STM32H7/analogin_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,12 @@ uint16_t adc_read(analogin_t *obj)
HAL_ADC_Start(&obj->handle); // Start conversion

// Wait end of conversion and get value
uint16_t adcValue = 0;
if (HAL_ADC_PollForConversion(&obj->handle, 10) == HAL_OK) {
return (uint16_t)HAL_ADC_GetValue(&obj->handle);
} else {
return 0;
adcValue = (uint16_t)HAL_ADC_GetValue(&obj->handle);
}
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE((&obj->handle)->Instance), LL_ADC_PATH_INTERNAL_NONE);
return adcValue;
}

const PinMap *analogin_pinmap()
Expand Down
5 changes: 2 additions & 3 deletions targets/TARGET_STM/TARGET_STM32L0/analogin_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ uint16_t adc_read(analogin_t *obj)
if (HAL_ADC_PollForConversion(&obj->handle, 10) == HAL_OK) {
adcValue = (uint16_t)HAL_ADC_GetValue(&obj->handle);
}
sConfig.Rank = ADC_RANK_NONE;
HAL_ADC_ConfigChannel(&obj->handle, &sConfig);
return adcValue;
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE((&obj->handle)->Instance), LL_ADC_PATH_INTERNAL_NONE);
return adcValue;
}

const PinMap *analogin_pinmap()
Expand Down
7 changes: 4 additions & 3 deletions targets/TARGET_STM/TARGET_STM32L1/analogin_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,12 @@ uint16_t adc_read(analogin_t *obj)
HAL_ADC_Start(&obj->handle); // Start conversion

// Wait end of conversion and get value
uint16_t adcValue = 0;
if (HAL_ADC_PollForConversion(&obj->handle, 10) == HAL_OK) {
return (uint16_t)HAL_ADC_GetValue(&obj->handle);
} else {
return 0;
adcValue = (uint16_t)HAL_ADC_GetValue(&obj->handle);
}
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE((&obj->handle)->Instance), LL_ADC_PATH_INTERNAL_NONE);
return adcValue;
}

const PinMap *analogin_pinmap()
Expand Down
14 changes: 4 additions & 10 deletions targets/TARGET_STM/TARGET_STM32L4/analogin_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,12 @@ uint16_t adc_read(analogin_t *obj)
HAL_ADC_Start(&obj->handle); // Start conversion

// Wait end of conversion and get value
uint16_t adcValue = 0;
if (HAL_ADC_PollForConversion(&obj->handle, 10) == HAL_OK) {

/* Ref Manual: To prevent any unwanted consumption on the battery,
it is recommended to enable the bridge divider only when needed for ADC conversion */
if (sConfig.Channel == ADC_CHANNEL_VBAT) {
CLEAR_BIT(__LL_ADC_COMMON_INSTANCE(obj->handle.Instance)->CCR, LL_ADC_PATH_INTERNAL_VBAT);
}

return (uint16_t)HAL_ADC_GetValue(&obj->handle);
} else {
return 0;
adcValue = (uint16_t)HAL_ADC_GetValue(&obj->handle);
}
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE((&obj->handle)->Instance), LL_ADC_PATH_INTERNAL_NONE);
return adcValue;
}

const PinMap *analogin_pinmap()
Expand Down