summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/stm32/adc.h5
-rw-r--r--ports/stm32/machine_adc.c8
-rwxr-xr-xports/stm32/mboot/Makefile1
-rw-r--r--ports/stm32/mboot/mphalport.h5
4 files changed, 17 insertions, 2 deletions
diff --git a/ports/stm32/adc.h b/ports/stm32/adc.h
index 6f2e61e09..64864b196 100644
--- a/ports/stm32/adc.h
+++ b/ports/stm32/adc.h
@@ -26,8 +26,13 @@
#ifndef MICROPY_INCLUDED_STM32_ADC_H
#define MICROPY_INCLUDED_STM32_ADC_H
+#if !BUILDING_MBOOT
extern const mp_obj_type_t pyb_adc_type;
extern const mp_obj_type_t pyb_adc_all_type;
+#endif
+
+void adc_config(ADC_TypeDef *adc, uint32_t bits);
+uint32_t adc_config_and_read_u16(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time);
#if defined(ADC_CHANNEL_VBAT)
diff --git a/ports/stm32/machine_adc.c b/ports/stm32/machine_adc.c
index d9e5a64da..f28bd5b39 100644
--- a/ports/stm32/machine_adc.c
+++ b/ports/stm32/machine_adc.c
@@ -96,7 +96,7 @@ STATIC const uint8_t adc_cr_to_bits_table[] = {16, 14, 12, 10, 8, 8, 8, 8};
STATIC const uint8_t adc_cr_to_bits_table[] = {12, 10, 8, 6};
#endif
-STATIC void adc_config(ADC_TypeDef *adc, uint32_t bits) {
+void adc_config(ADC_TypeDef *adc, uint32_t bits) {
// Configure ADC clock source and enable ADC clock
#if defined(STM32L4) || defined(STM32WB)
__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_SYSCLK);
@@ -331,7 +331,7 @@ STATIC uint32_t adc_read_channel(ADC_TypeDef *adc) {
return value;
}
-STATIC uint32_t adc_config_and_read_u16(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time) {
+uint32_t adc_config_and_read_u16(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time) {
if (channel == ADC_CHANNEL_VREF) {
return 0xffff;
}
@@ -357,6 +357,8 @@ STATIC uint32_t adc_config_and_read_u16(ADC_TypeDef *adc, uint32_t channel, uint
/******************************************************************************/
// MicroPython bindings for machine.ADC
+#if !BUILDING_MBOOT
+
const mp_obj_type_t machine_adc_type;
typedef struct _machine_adc_obj_t {
@@ -462,3 +464,5 @@ const mp_obj_type_t machine_adc_type = {
.make_new = machine_adc_make_new,
.locals_dict = (mp_obj_dict_t *)&machine_adc_locals_dict,
};
+
+#endif
diff --git a/ports/stm32/mboot/Makefile b/ports/stm32/mboot/Makefile
index 534622c03..d57b9368e 100755
--- a/ports/stm32/mboot/Makefile
+++ b/ports/stm32/mboot/Makefile
@@ -128,6 +128,7 @@ SRC_C += \
ports/stm32/flash.c \
ports/stm32/flashbdev.c \
ports/stm32/i2cslave.c \
+ ports/stm32/machine_adc.c \
ports/stm32/powerctrlboot.c \
ports/stm32/qspi.c \
ports/stm32/spibdev.c \
diff --git a/ports/stm32/mboot/mphalport.h b/ports/stm32/mboot/mphalport.h
index 56d18a9b0..ab0bc1587 100644
--- a/ports/stm32/mboot/mphalport.h
+++ b/ports/stm32/mboot/mphalport.h
@@ -39,6 +39,11 @@ static inline int mp_hal_status_to_neg_errno(HAL_StatusTypeDef status) {
#define MP_HAL_PIN_MODE_OUTPUT (1)
#define MP_HAL_PIN_MODE_ALT (2)
#define MP_HAL_PIN_MODE_ANALOG (3)
+#if defined(GPIO_ASCR_ASC0)
+#define MP_HAL_PIN_MODE_ADC (11)
+#else
+#define MP_HAL_PIN_MODE_ADC (3)
+#endif
#define MP_HAL_PIN_MODE_OPEN_DRAIN (5)
#define MP_HAL_PIN_MODE_ALT_OPEN_DRAIN (6)
#define MP_HAL_PIN_PULL_NONE (GPIO_NOPULL)