@@ -261,6 +261,47 @@ void SystemInit( void )
261261 CoreDebug -> DEMCR |= CoreDebug_DEMCR_TRCENA_Msk ;
262262 DWT -> CTRL |= DWT_CTRL_CYCCNTENA_Msk ;
263263
264+ /* ----------------------------------------------------------------------------------------------
265+ * 5) Load AC factory calibration values
266+ */
267+
268+ uint32_t bias0 = (* ((uint32_t * )AC_FUSES_BIAS0_ADDR ) & AC_FUSES_BIAS0_Msk ) >> AC_FUSES_BIAS0_Pos ;
269+ AC -> CALIB .reg = AC_CALIB_BIAS0 (bias0 );
270+
271+ /* ----------------------------------------------------------------------------------------------
272+ * 6) Load ADC factory calibration values
273+ */
274+
275+ // ADC0 Bias Calibration
276+ uint32_t biascomp = (* ((uint32_t * )ADC0_FUSES_BIASCOMP_ADDR ) & ADC0_FUSES_BIASCOMP_Msk ) >> ADC0_FUSES_BIASCOMP_Pos ;
277+ uint32_t biasr2r = (* ((uint32_t * )ADC0_FUSES_BIASR2R_ADDR ) & ADC0_FUSES_BIASR2R_Msk ) >> ADC0_FUSES_BIASR2R_Pos ;
278+ uint32_t biasref = (* ((uint32_t * )ADC0_FUSES_BIASREFBUF_ADDR ) & ADC0_FUSES_BIASREFBUF_Msk ) >> ADC0_FUSES_BIASREFBUF_Pos ;
279+
280+ ADC0 -> CALIB .reg = ADC_CALIB_BIASREFBUF (biasref )
281+ | ADC_CALIB_BIASR2R (biasr2r )
282+ | ADC_CALIB_BIASCOMP (biascomp );
283+
284+ // ADC1 Bias Calibration
285+ biascomp = (* ((uint32_t * )ADC1_FUSES_BIASCOMP_ADDR ) & ADC1_FUSES_BIASCOMP_Msk ) >> ADC1_FUSES_BIASCOMP_Pos ;
286+ biasr2r = (* ((uint32_t * )ADC1_FUSES_BIASR2R_ADDR ) & ADC1_FUSES_BIASR2R_Msk ) >> ADC1_FUSES_BIASR2R_Pos ;
287+ biasref = (* ((uint32_t * )ADC1_FUSES_BIASREFBUF_ADDR ) & ADC1_FUSES_BIASREFBUF_Msk ) >> ADC1_FUSES_BIASREFBUF_Pos ;
288+
289+ ADC1 -> CALIB .reg = ADC_CALIB_BIASREFBUF (biasref )
290+ | ADC_CALIB_BIASR2R (biasr2r )
291+ | ADC_CALIB_BIASCOMP (biascomp );
292+
293+ /* ----------------------------------------------------------------------------------------------
294+ * 7) Load USB factory calibration values
295+ */
296+
297+ //USB Calibration
298+ uint32_t usbtransn = (* ((uint32_t * )USB_FUSES_TRANSN_ADDR ) & USB_FUSES_TRANSN_Msk ) >> USB_FUSES_TRANSN_Pos ;
299+ uint32_t usbtransp = (* ((uint32_t * )USB_FUSES_TRANSP_ADDR ) & USB_FUSES_TRANSP_Msk ) >> USB_FUSES_TRANSP_Pos ;
300+ uint32_t usbtrim = (* ((uint32_t * )USB_FUSES_TRIM_ADDR ) & USB_FUSES_TRIM_Msk ) >> USB_FUSES_TRIM_Pos ;
301+ USB -> DEVICE .PADCAL .reg = USB_PADCAL_TRIM (usbtrim )
302+ | USB_PADCAL_TRANSN (usbtransn )
303+ | USB_PADCAL_TRANSP (usbtransp );
304+
264305//*************** END SAMD51 *************************//
265306
266307#else
@@ -536,4 +577,3 @@ void SystemInit( void )
536577 NVMCTRL -> CTRLB .bit .MANW = 1 ;
537578 #endif
538579}
539-
0 commit comments