1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/{gd32v,stm32}/periph/adc: ensure max ADC speed is honored

This patch ensures that the ADC's max clock speed is not exceded.
This commit is contained in:
Joshua DeWeese 2024-05-10 21:40:47 -04:00
parent 4218fca673
commit 410e55d912
4 changed files with 8 additions and 0 deletions

View File

@ -22,6 +22,7 @@
* @}
*/
#include "compiler_hints.h"
#include "cpu.h"
#include "macros/units.h"
#include "mutex.h"
@ -128,6 +129,7 @@ int adc_init(adc_t line)
break;
}
}
assume((periph_apb_clk(APB2) / clk_div) <= ADC_CLK_MAX);
RCU->CFG0 &= ~(RCU_CFG0_ADCPSC_2_Msk);
RCU->CFG0 |= ((clk_div / 2) - 1) << RCU_CFG0_ADCPSC_2_Pos;

View File

@ -20,6 +20,7 @@
* @}
*/
#include "compiler_hints.h"
#include "cpu.h"
#include "mutex.h"
#include "periph/adc.h"
@ -99,6 +100,7 @@ int adc_init(adc_t line)
break;
}
}
assume((periph_apb_clk(APB2) / clk_div) <= ADC_CLK_MAX);
RCC->CFGR &= ~(RCC_CFGR_ADCPRE);
RCC->CFGR |= ((clk_div / 2) - 1) << 14;

View File

@ -20,6 +20,7 @@
* @}
*/
#include "compiler_hints.h"
#include "cpu.h"
#include "mutex.h"
#include "periph/adc.h"
@ -92,6 +93,7 @@ int adc_init(adc_t line)
break;
}
}
assume((periph_apb_clk(APB2) / clk_div) <= ADC_CLK_MAX);
ADC->CCR = ((clk_div / 2) - 1) << 16;
/* enable the ADC module */

View File

@ -19,6 +19,7 @@
* @}
*/
#include "compiler_hints.h"
#include "cpu.h"
#include "irq.h"
#include "mutex.h"
@ -101,6 +102,7 @@ int adc_init(adc_t line)
break;
}
}
assume((periph_apb_clk(APB2) / clk_div) <= ADC_CLK_MAX);
ADC->CCR = ((clk_div / 2) - 1) << 16;
/* set sampling time to the maximum */
unsigned irq_state = irq_disable();