Código ejemplo inicializando el ADC

Función para seleccionar el reloj:

void clock_setup(void)
 {
   rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_168MHZ]);	//f4 stm32-discovery
 }
 

Inicialización de los leds, y el puerto A.

 
 void gpio_setup(void)
 {
/* Enable GPIOC clock. */
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN);		
/* Set GPIOs (in GPIO port D) to 'output push-pull'. */
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,GPIO_PUPD_NONE, GPIO12);	//	green LED 
gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT,GPIO_PUPD_NONE, GPIO15);	//	blue led
/* Enable GPIOC clock. */
rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);
/* Set GPIO0 (in GPIO port A) to 'input open-drain'. */
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1);			
}

Inicialización de las funciones del ADC, activar que sea en puerto A, pre-escalado, des-habilitar escaneo de canales (porque solo se usa 1), ADC en modo simple.

void set_adc (void)
{
     gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1); // Configura el Pin PA1, modo analógico, sin pull up/down
     rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN);   // Habilita reloj del ADC1
     rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN);   // Habilita pin PA1
     adc_set_clk_prescale(ADC_CCR_ADCPRE_BY2);                        // Pre escala el reloj
     adc_disable_scan_mode(ADC1);                                     // Se deshabilita el escaneo por grupo
     adc_set_single_conversion_mode(ADC1);                            
     adc_set_sample_time(ADC1, ADC_CHANNEL1, ADC_SMPR1_SMP_1DOT5CYC);
     //Solo se esta usando un canal
     u8 channels[16];
     channels[0] = ADC_CHANNEL1;
     channels[1] = ADC_CHANNEL1;
     channels[2] = ADC_CHANNEL1;
     channels[3] = ADC_CHANNEL1;   
     channels[4] = ADC_CHANNEL1;
     channels[5] = ADC_CHANNEL1;
     channels[6] = ADC_CHANNEL1;
     channels[7] = ADC_CHANNEL1;
     channels[8] = ADC_CHANNEL1;
     channels[9] = ADC_CHANNEL1;
     channels[10] = ADC_CHANNEL1;
     channels[11] = ADC_CHANNEL1;
     channels[12] = ADC_CHANNEL1;
     channels[13] = ADC_CHANNEL1;
     channels[14] = ADC_CHANNEL1;
     channels[15] = ADC_CHANNEL1;
     adc_set_regular_sequence(ADC1, 16, channels);
     adc_set_multi_mode(ADC_CCR_MULTI_INDEPENDENT);
     adc_power_on(ADC1);
}

Programa de prueba:

int main(void)
{

     u16 medicion;
     float Vref=2.966f;
     float voltage=0.0f;
     
     //Inicializar, y configuración 
     
     clock_setup();	
     gpio_setup();
     set_adc();
     while(1) 
     {
           adc_start_conversion_regular(ADC1);  //Empieza la lectura para realizar la conversión del ADC1
      while (!adc_eoc(ADC1));
     medicion = adc_read_regular(ADC1);   //"medición" obtiene el valor calculado por el ADC
     voltage=medicion*(Vref/4096.0f);     //Se establece un valor de voltaje en base a una referencia 
     //min hall voltaje1.49
     //max hall voltaje 1.67
     if (voltage>=1.64f)                    //Dependiendo del voltaje voltaje medido y el de referencia de prende el led GPIO12o el GPIO15
	gpio_port_write(GPIOD, GPIO12); 
     else 
	gpio_port_write(GPIOD, GPIO15);
     }
return 0;
}

Prueba

A continuación se puede observar la imagen que muestra la funcionalidad del ADC, en la primera imagen al no haber voltaje de entrada el LED que se enciende es el azul, y cuando a la entrada le colocamos un voltaje mayor al de referencia (en este caso 3 V) vemos que el LED que enciende es el verde.