stm32f2 pll overflow with crystal
With a large enough HSE input frequency, the vco clock calculation will overflow a u32. Therefore, in this specific case we have to use the inner value and cast to u64 to ensure the mul isn't clipped before applying the divider.
This commit is contained in:
		
							parent
							
								
									fcbfd224a7
								
							
						
					
					
						commit
						e0ce7fcde7
					
				@ -58,7 +58,7 @@ impl Default for PLLConfig {
 | 
				
			|||||||
impl PLLConfig {
 | 
					impl PLLConfig {
 | 
				
			||||||
    pub fn clocks(&self, src_freq: Hertz) -> PLLClocks {
 | 
					    pub fn clocks(&self, src_freq: Hertz) -> PLLClocks {
 | 
				
			||||||
        let in_freq = src_freq / self.pre_div;
 | 
					        let in_freq = src_freq / self.pre_div;
 | 
				
			||||||
        let vco_freq = src_freq * self.mul / self.pre_div;
 | 
					        let vco_freq = Hertz((src_freq.0 as u64 * self.mul.0 as u64 / self.pre_div.0 as u64) as u32);
 | 
				
			||||||
        let main_freq = vco_freq / self.main_div;
 | 
					        let main_freq = vco_freq / self.main_div;
 | 
				
			||||||
        let pll48_freq = vco_freq / self.pll48_div;
 | 
					        let pll48_freq = vco_freq / self.pll48_div;
 | 
				
			||||||
        PLLClocks {
 | 
					        PLLClocks {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user