hsi only for adc; run msi at 512k for 360uA

master
Clyne 4 years ago
parent 764446fb86
commit 2b3bc49928

@ -139,7 +139,7 @@ ASMXSRC = $(ALLXASMSRC)
INCDIR = $(CONFDIR) $(ALLINC) $(TESTINC)
# Define C warning options here.
CWARN = -Wall -Wextra -Wundef -pedantic #-Wstrict-prototypes
CWARN = -Wall -Wextra -Wundef -Wno-cpp #-Wstrict-prototypes
# Define C++ warning options here.
CPPWARN = -Wall -Wextra -Wundef

@ -47,13 +47,13 @@ void buttons_init()
palEnablePadEvent(GPIOA, 7, PAL_EVENT_MODE_BOTH_EDGES);
palEnablePadEvent(GPIOA, 9, PAL_EVENT_MODE_BOTH_EDGES);
palEnablePadEvent(GPIOA, 10, PAL_EVENT_MODE_BOTH_EDGES);
palSetPadCallback(GPIOA, 0, buttonStateHandler, 0x0700);
palSetPadCallback(GPIOA, 1, buttonStateHandler, 0x0601);
palSetPadCallback(GPIOA, 2, buttonStateHandler, 0x0502);
palSetPadCallback(GPIOA, 3, buttonStateHandler, 0x0403);
palSetPadCallback(GPIOA, 6, buttonStateHandler, 0x0306);
palSetPadCallback(GPIOA, 7, buttonStateHandler, 0x0207);
palSetPadCallback(GPIOA, 9, buttonStateHandler, 0x0109);
palSetPadCallback(GPIOA, 10, buttonStateHandler, 0x000A);
palSetPadCallback(GPIOA, 0, buttonStateHandler, (void *)0x0700);
palSetPadCallback(GPIOA, 1, buttonStateHandler, (void *)0x0601);
palSetPadCallback(GPIOA, 2, buttonStateHandler, (void *)0x0502);
palSetPadCallback(GPIOA, 3, buttonStateHandler, (void *)0x0403);
palSetPadCallback(GPIOA, 6, buttonStateHandler, (void *)0x0306);
palSetPadCallback(GPIOA, 7, buttonStateHandler, (void *)0x0207);
palSetPadCallback(GPIOA, 9, buttonStateHandler, (void *)0x0109);
palSetPadCallback(GPIOA, 10, buttonStateHandler, (void *)0x000A);
}

@ -47,13 +47,13 @@
#define STM32_LSI_ENABLED TRUE
#define STM32_HSE_ENABLED FALSE
#define STM32_LSE_ENABLED FALSE
//#define STM32_ADC_CLOCK_ENABLED FALSE
#define STM32_MSIRANGE STM32_MSIRANGE_4M
#define STM32_SW STM32_SW_HSI16
#define STM32_ADC_CLOCK_ENABLED TRUE
#define STM32_MSIRANGE STM32_MSIRANGE_512K
#define STM32_SW STM32_SW_MSI
#define STM32_PLLSRC STM32_PLLSRC_HSI16
#define STM32_PLLMUL_VALUE 4
#define STM32_PLLDIV_VALUE 2
#define STM32_HPRE STM32_HPRE_DIV4
#define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE1 STM32_PPRE1_DIV1
#define STM32_PPRE2 STM32_PPRE2_DIV1
#define STM32_MCOSEL STM32_MCOSEL_NOCLOCK

@ -21,11 +21,13 @@
* - Can read buttons through PAL (through interrupts now)
* - Use ADC to read Vintref, print to screen in mV
* - Sleep mode via WFI, saves ~0.5mA (we're running around 1.1mA)
* - Run at 512kHz, only use HSI for ADC: 360uA
*/
static volatile bool adc_is_complete = false;
static void adc_callback(ADCDriver *adcp)
static void adc_callback(ADCDriver *adcd)
{
(void)adcd;
adc_is_complete = true;
}
@ -49,6 +51,9 @@ static int readVddmv()
{
adcsample_t reading = 0;
RCC->CR |= RCC_CR_HSION;
while (!(RCC->CR & RCC_CR_HSIRDY));
adcStart(&ADCD1, &adccfg);
adcSTM32EnableVREF(&ADCD1);
adcStartConversion(&ADCD1, &adcgrpcfg, &reading, 1);
@ -57,6 +62,8 @@ static int readVddmv()
adcSTM32DisableVREF(&ADCD1);
adcStop(&ADCD1);
RCC->CR &= ~RCC_CR_HSION;
return 3000 * /* CAL */ *((adcsample_t *)0x1FF80078) / reading;
}
@ -116,7 +123,8 @@ int main(void)
{
halInit();
chSysInit();
RCC->CFGR |= RCC_CFGR_STOPWUCK;
RCC->CR &= ~RCC_CR_HSION;
buttons_init();

Loading…
Cancel
Save