@@ -631,7 +631,7 @@ void setup() {
631
631
LMIC_reset ();
632
632
633
633
// set clock rate error to 0.1%
634
- LMIC_setClockError (1 * MAX_CLOCK_ERROR / 1000 );
634
+ // LMIC_setClockError(1 * MAX_CLOCK_ERROR / 1000);
635
635
636
636
// do the network-specific setup prior to join.
637
637
setupForNetwork (false );
@@ -967,20 +967,20 @@ uint32_t Stm32_CalibrateSystemClock(void)
967
967
CalibLow = 0 ;
968
968
CalibHigh = 0 ;
969
969
mSecondLow = 0 ;
970
- mSecondHigh = 2000 ;
970
+ mSecondHigh = 2000000 ;
971
971
fHaveSeenLow = fHaveSeenHigh = false ;
972
972
973
973
/* loop until we have a new value */
974
974
do {
975
975
/* meassure the # of millis per RTC second */
976
- mSecond = MeasureMillisPerRtcSecond ();
976
+ mSecond = MeasureMicrosPerRtcSecond ();
977
977
978
978
/* invariant: */
979
979
if (Calib == CalibNew)
980
980
mSecondNew = mSecond ;
981
981
982
982
/* if mSecond is low, this meaans we must increase the system clock */
983
- if (mSecond <= 1000 )
983
+ if (mSecond <= 1000000 )
984
984
{
985
985
Serial.print (' -' );
986
986
/*
@@ -1098,6 +1098,7 @@ uint32_t Stm32_CalibrateSystemClock(void)
1098
1098
1099
1099
if (CalibNew != Calib)
1100
1100
{
1101
+ Serial.print (CalibNew < Calib ? ' +' : ' -' );
1101
1102
if (fCalibrateMSI )
1102
1103
{
1103
1104
__HAL_RCC_MSI_CALIBRATIONVALUE_ADJUST (CalibNew);
@@ -1109,11 +1110,13 @@ uint32_t Stm32_CalibrateSystemClock(void)
1109
1110
delay (500 );
1110
1111
}
1111
1112
1113
+ Serial.print (" 0x" );
1114
+ Serial.println (CalibNew, HEX);
1112
1115
return CalibNew;
1113
1116
}
1114
1117
1115
1118
uint32_t
1116
- MeasureMillisPerRtcSecond (
1119
+ MeasureMicrosPerRtcSecond (
1117
1120
void
1118
1121
)
1119
1122
{
@@ -1128,7 +1131,7 @@ MeasureMillisPerRtcSecond(
1128
1131
/* wait for a new second to start, and capture millis() in start */
1129
1132
do {
1130
1133
now = RTC->TR & (RTC_TR_ST | RTC_TR_SU);
1131
- start = millis ();
1134
+ start = micros ();
1132
1135
} while (second == now);
1133
1136
1134
1137
/* update our second of interest */
@@ -1140,7 +1143,7 @@ MeasureMillisPerRtcSecond(
1140
1143
/* wait for the next second to start, and capture millis() */
1141
1144
do {
1142
1145
now = RTC->TR & (RTC_TR_ST | RTC_TR_SU);
1143
- end = millis ();
1146
+ end = micros ();
1144
1147
} while (second == now);
1145
1148
1146
1149
/* return the delta */
0 commit comments