Skip to content

Commit aa9037c

Browse files
Rework RTC calendar to use a elapsed seconds offset (BKPx); this way RTC once started does not have to be modified
Use a S11 value for subsecond correction throu PPS (BKPx) Use RTC for millis() over Systick Add LSE calibration via TCXO for CMWX1ZZABZ (via DIO1) Add PPS tracking for GNSS to facility RTC phase correction
1 parent 15b2929 commit aa9037c

File tree

33 files changed

+1879
-1159
lines changed

33 files changed

+1879
-1159
lines changed

cores/arduino/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ LD = $(TOOLS)/bin/arm-none-eabi-ld
88
CFLAGS = -mcpu=cortex-m0plus -mthumb -c -g -Os $(WARNINGS) -std=gnu11 -ffunction-sections -fdata-sections -nostdlib -MMD $(EXTRAS) $(DEFINES) $(INCLUDES)
99
CXXFLAGS = -mcpu=cortex-m0plus -mthumb -c -g -Os $(WARNINGS) -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib -fno-rtti -fno-exceptions -MMD $(EXTRAS) $(DEFINES) $(INCLUDES)
1010
ASFLAGS = -c -g -x assembler-with-cpp $(EXTRAS) $(DEFINES) $(INCLUDES)
11-
LDFLAGS = -g -Os -mcpu=cortex-m0plus -mthumb -mabi=aapcs -mfloat-abi=soft -Wl,--gc-sections,--no-undefined -T../../variants/STM32L082CZ-Cricket/linker_scripts/STM32L082CZ_FLASH.ld --specs=nano.specs
11+
LDFLAGS = -g -Os -mcpu=cortex-m0plus -mthumb -mabi=aapcs -mfloat-abi=soft -Wl,--gc-sections,--no-undefined -T../../variants/Cricket-L082CZ/linker_scripts/STM32L082CZ_FLASH.ld --specs=nano.specs
1212
WARNINGS = -Wall -Wextra -Wno-unused-parameter
1313
EXTRAS = -DSTM32L082xx -march=armv6-m -mthumb -mabi=aapcs -mfloat-abi=soft
1414
DEFINES = -D_SYSTEM_CORE_CLOCK_=32000000 -DDOSFS_SDCARD=0 -DDOSFS_SFLASH=1 -DARDUINO_MAKEFILE
1515
INCLUDES = \
1616
-I../../system/CMSIS/Include \
1717
-I../../system/CMSIS/Device/ST/STM32L0xx/Include \
1818
-I../../system/STM32L0xx/Include \
19-
-I../../variants/STM32L082CZ-Cricket \
19+
-I../../variants/Cricket-L082CZ \
2020
-I../../libraries/CayenneLPP/src \
2121
-I../../libraries/DOSFS/src \
2222
-I../../libraries/EEPROM/src \
@@ -40,7 +40,7 @@ SRCS = \
4040
../../libraries/STM32L0/src/STM32L0.cpp \
4141
../../libraries/TimerMillis/src/TimerMillis.cpp \
4242
../../libraries/Wire/src/Wire.cpp \
43-
../../variants/STM32L082CZ-Cricket/variant.cpp \
43+
../../variants/Cricket-L082CZ/variant.cpp \
4444
avr/dtostrf.c \
4545
avr/eeprom.c \
4646
avr/fdevopen.c \
@@ -86,7 +86,7 @@ OBJS = \
8686
../../libraries/STM32L0/src/STM32L0.o \
8787
../../libraries/TimerMillis/src/TimerMillis.o \
8888
../../libraries/Wire/src/Wire.o \
89-
../../variants/STM32L082CZ-Cricket/variant.o \
89+
../../variants/Cricket-L082CZ/variant.o \
9090
avr/dtostrf.o \
9191
avr/eeprom.o \
9292
avr/fdevopen.o \

cores/arduino/delay.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131

3232
unsigned long millis(void)
3333
{
34-
return armv6m_systick_millis();
34+
uint32_t seconds;
35+
uint16_t subseconds;
36+
37+
stm32l0_rtc_get_time(&seconds, &subseconds);
38+
39+
return (seconds * 1000) + ((subseconds * 1000) / 32768);
3540
}
3641

3742
unsigned long micros(void)
@@ -81,11 +86,11 @@ void delay(uint32_t msec)
8186
while (msec);
8287

8388
} else {
84-
start = armv6m_systick_millis();
89+
start = millis();
8590

8691
do
8792
{
8893
}
89-
while ((armv6m_systick_millis() - start) < msec);
94+
while ((millis() - start) < msec);
9095
}
9196
}

drivers/linux/49-nucleo.rules

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", ENV{ID_MM_DEVICE_IGNORE}="1"
2+
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", ENV{MTP_NO_PROBE}="1"
3+
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", ENV{UDISKS_AUTO}="0"
4+
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", MODE:="0666"
5+
KERNEL=="ttyACM*", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", MODE:="0666"

libraries/GNSS/examples/GNSS_periodic/GNSS_periodic.ino

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#include "GNSS.h"
22
#include "STM32L0.h"
3+
#include "RTC.h"
34

45
bool isPeriodic = false;
56

67
unsigned int myAcqTime = 45;
7-
unsigned int myOnTime = 5;
8+
unsigned int myOnTime = 15;
89
unsigned int myPeriod = 120;
910

1011
GNSSLocation myLocation;
@@ -28,6 +29,8 @@ void setup( void )
2829
GNSS.setAntenna(GNSS.ANTENNA_INTERNAL);
2930

3031
while (GNSS.busy()) { }
32+
33+
GNSS.enableWakeup();
3134
}
3235

3336
void loop( void )
@@ -36,6 +39,9 @@ void loop( void )
3639

3740
if (GNSS.location(myLocation))
3841
{
42+
uint8_t year, month, day, hours, minutes, seconds;
43+
uint32_t subSeconds, milliSeconds;
44+
3945
static const char *fixTypeString[] = {
4046
"NONE",
4147
"TIME",
@@ -57,14 +63,50 @@ void loop( void )
5763

5864
if (!isPeriodic)
5965
{
60-
if (myLocation.fixType() == GNSSLocation::TYPE_3D)
66+
if ((myLocation.fixType() == GNSSLocation::TYPE_3D) && (myLocation.ehpe() <= 30.0) && myLocation.fullyResolved())
6167
{
6268
isPeriodic = true;
6369

6470
GNSS.setPeriodic(myAcqTime, myOnTime, myPeriod);
6571
}
6672
}
6773

74+
RTC.getDate(day, month, year);
75+
RTC.getTime(hours, minutes, seconds, subSeconds);
76+
77+
milliSeconds = ((subSeconds >> 17) * 1000 + 16384) / 32768;
78+
79+
Serial.print("RTC: ");
80+
Serial.print(2000 + year);
81+
Serial.print("/");
82+
Serial.print(month);
83+
Serial.print("/");
84+
Serial.print(day);
85+
Serial.print(" ");
86+
if (hours <= 9) {
87+
Serial.print("0");
88+
}
89+
Serial.print(hours);
90+
Serial.print(":");
91+
if (minutes <= 9) {
92+
Serial.print("0");
93+
}
94+
Serial.print(minutes);
95+
Serial.print(":");
96+
if (seconds <= 9) {
97+
Serial.print("0");
98+
}
99+
Serial.print(seconds);
100+
Serial.print(".");
101+
if (milliSeconds <= 9) {
102+
Serial.print("0");
103+
}
104+
if (milliSeconds <= 99) {
105+
Serial.print("0");
106+
}
107+
Serial.print(milliSeconds);
108+
Serial.println();
109+
68110
Serial.print("LOCATION: ");
69111
Serial.print(fixTypeString[myLocation.fixType()]);
70112

@@ -101,6 +143,14 @@ void loop( void )
101143
}
102144
Serial.print(myLocation.millis());
103145

146+
if (myLocation.leapSeconds() != GNSSLocation::LEAP_SECONDS_UNDEFINED) {
147+
Serial.print(" ");
148+
Serial.print(myLocation.leapSeconds());
149+
if (!myLocation.fullyResolved()) {
150+
Serial.print("D");
151+
}
152+
}
153+
104154
if (myLocation.fixType() != GNSSLocation::TYPE_TIME)
105155
{
106156
Serial.print(" LLA=");

libraries/GNSS/src/GNSS.cpp

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ GNSSLocation::GNSSLocation()
4444
_location.time.seconds = 0;
4545
_location.time.millis = 0;
4646
_location.mask = 0;
47-
_location.correction = 0;
47+
_location.correction = -128;
4848
_location.type = 0;
4949
_location.latitude = 0;
5050
_location.longitude = 0;
@@ -77,6 +77,11 @@ enum GNSSLocation::GNSSfixQuality GNSSLocation::fixQuality(void) const
7777
return (enum GNSSLocation::GNSSfixQuality)_location.quality;
7878
}
7979

80+
bool GNSSLocation::fullyResolved(void) const
81+
{
82+
return !!(_location.mask & GNSS_LOCATION_MASK_RESOLVED);
83+
}
84+
8085
unsigned int GNSSLocation::satellites(void) const
8186
{
8287
return _location.numsv;
@@ -117,7 +122,7 @@ uint16_t GNSSLocation::millis(void) const
117122
return _location.time.millis;
118123
}
119124

120-
uint8_t GNSSLocation::leapSeconds(void) const
125+
int8_t GNSSLocation::leapSeconds(void) const
121126
{
122127
return _location.correction;
123128
}
@@ -342,6 +347,11 @@ void GNSSClass::begin(Uart &uart, GNSSmode mode, GNSSrate rate)
342347
}
343348
#endif /* defined(STM32L0_CONFIG_PIN_GNSS_ENABLE) */
344349

350+
#if defined(STM32L0_CONFIG_PIN_GNSS_PPS)
351+
stm32l0_gpio_pin_configure(STM32L0_CONFIG_PIN_GNSS_PPS, (STM32L0_GPIO_PARK_NONE | STM32L0_GPIO_PUPD_PULLDOWN | STM32L0_GPIO_OSPEED_HIGH | STM32L0_GPIO_OTYPE_PUSHPULL | STM32L0_GPIO_MODE_INPUT));
352+
stm32l0_exti_attach(STM32L0_CONFIG_PIN_GNSS_PPS, STM32L0_EXTI_CONTROL_EDGE_FALLING, (stm32l0_exti_callback_t)ppsCallback, (void*)this);
353+
#endif
354+
345355
_uart = &uart;
346356

347357
_uart->begin(9600);
@@ -412,14 +422,34 @@ bool GNSSClass::setPeriodic(unsigned int acqTime, unsigned int onTime, unsigned
412422
return (_uart && gnss_set_periodic(acqTime, onTime, period));
413423
}
414424

415-
bool GNSSClass::sleep()
425+
bool GNSSClass::suspend()
416426
{
417-
return (_uart && gnss_sleep());
427+
if (!(_uart && gnss_suspend()))
428+
{
429+
return false;
430+
}
431+
432+
#if defined(STM32L0_CONFIG_PIN_GNSS_PPS)
433+
stm32l0_exti_detach(STM32L0_CONFIG_PIN_GNSS_PPS);
434+
stm32l0_gpio_pin_configure(STM32L0_CONFIG_PIN_GNSS_PPS, (STM32L0_GPIO_PARK_NONE | STM32L0_GPIO_MODE_ANALOG));
435+
#endif
436+
437+
return true;
418438
}
419439

420-
bool GNSSClass::wakeup()
440+
bool GNSSClass::resume()
421441
{
422-
return (_uart && gnss_wakeup());
442+
if (!(_uart && gnss_resume()))
443+
{
444+
return false;
445+
}
446+
447+
#if defined(STM32L0_CONFIG_PIN_GNSS_PPS)
448+
stm32l0_gpio_pin_configure(STM32L0_CONFIG_PIN_GNSS_PPS, (STM32L0_GPIO_PARK_NONE | STM32L0_GPIO_PUPD_PULLDOWN | STM32L0_GPIO_OSPEED_HIGH | STM32L0_GPIO_OTYPE_PUSHPULL | STM32L0_GPIO_MODE_INPUT));
449+
stm32l0_exti_attach(STM32L0_CONFIG_PIN_GNSS_PPS, STM32L0_EXTI_CONTROL_EDGE_FALLING, (stm32l0_exti_callback_t)ppsCallback, (void*)this);
450+
#endif
451+
452+
return true;
423453
}
424454

425455
bool GNSSClass::busy()
@@ -462,6 +492,16 @@ bool GNSSClass::satellites(GNSSSatellites &satellites)
462492
return true;
463493
}
464494

495+
void GNSSClass::enableWakeup()
496+
{
497+
_wakeup = true;
498+
}
499+
500+
void GNSSClass::disableWakeup()
501+
{
502+
_wakeup = false;
503+
}
504+
465505
void GNSSClass::onLocation(void(*callback)(void))
466506
{
467507
_locationCallback = Callback(callback);
@@ -482,6 +522,16 @@ void GNSSClass::onSatellites(Callback callback)
482522
_satellitesCallback = callback;
483523
}
484524

525+
void GNSSClass::attachInterrupt(void(*callback)(void))
526+
{
527+
_ppsCallback = callback;
528+
}
529+
530+
void GNSSClass::detachInterrupt()
531+
{
532+
_ppsCallback = NULL;
533+
}
534+
485535
void GNSSClass::receiveCallback(void)
486536
{
487537
uint8_t rx_data[16];
@@ -540,6 +590,10 @@ void GNSSClass::disableCallback(class GNSSClass *self)
540590

541591
void GNSSClass::locationCallback(class GNSSClass *self, const gnss_location_t *location)
542592
{
593+
if (self->_wakeup) {
594+
stm32l0_system_wakeup();
595+
}
596+
543597
self->_location_data = *location;
544598
self->_location_pending = true;
545599

@@ -548,10 +602,23 @@ void GNSSClass::locationCallback(class GNSSClass *self, const gnss_location_t *l
548602

549603
void GNSSClass::satellitesCallback(class GNSSClass *self, const gnss_satellites_t *satellites)
550604
{
605+
if (self->_wakeup) {
606+
stm32l0_system_wakeup();
607+
}
608+
551609
self->_satellites_data = *satellites;
552610
self->_satellites_pending = true;
553611

554612
self->_satellitesCallback.queue();
555613
}
556614

615+
void GNSSClass::ppsCallback(class GNSSClass *self)
616+
{
617+
gnss_pps_callback();
618+
619+
if (self->_ppsCallback) {
620+
(*self->_ppsCallback)();
621+
}
622+
}
623+
557624
GNSSClass GNSS;

libraries/GNSS/src/GNSS.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,16 @@ class GNSSLocation {
5353
QUALITY_SIMULATION,
5454
};
5555

56+
static const int LEAP_SECONDS_UNDEFINED = -128;
57+
5658
GNSSLocation(const gnss_location_t *location);
5759
GNSSLocation();
5860

5961
operator bool() const;
6062

6163
enum GNSSfixType fixType(void) const;
6264
enum GNSSfixQuality fixQuality(void) const;
65+
bool fullyResolved(void) const;
6366
unsigned int satellites(void) const;
6467

6568
uint16_t year(void) const;
@@ -69,7 +72,7 @@ class GNSSLocation {
6972
uint8_t minutes(void) const;
7073
uint8_t seconds(void) const;
7174
uint16_t millis(void) const;
72-
uint8_t leapSeconds(void) const;
75+
int8_t leapSeconds(void) const;
7376

7477
double latitude(void) const; // WGS84
7578
double longitude(void) const; // WGS84
@@ -167,21 +170,28 @@ class GNSSClass {
167170
bool setAutonomous(bool enable);
168171
bool setPlatform(GNSSplatform platform);
169172
bool setPeriodic(unsigned int acqTime, unsigned int onTime, unsigned int period);
170-
bool sleep();
171-
bool wakeup();
173+
bool suspend();
174+
bool resume();
172175
bool busy();
173176

174177
bool location(GNSSLocation &location);
175178
bool satellites(GNSSSatellites &satellites);
176179

180+
void enableWakeup();
181+
void disableWakeup();
182+
177183
void onLocation(void(*callback)(void));
178184
void onLocation(Callback callback);
179185
void onSatellites(void(*callback)(void));
180186
void onSatellites(Callback callback);
181187

188+
void attachInterrupt(void(*callback)(void));
189+
void detachInterrupt();
190+
182191
private:
183192
Uart *_uart;
184193
uint32_t _baudrate;
194+
bool _wakeup;
185195
gnss_location_t _location_data;
186196
volatile uint32_t _location_pending;
187197
gnss_satellites_t _satellites_data;
@@ -190,15 +200,18 @@ class GNSSClass {
190200
Callback _locationCallback;
191201
Callback _satellitesCallback;
192202

203+
void (*_ppsCallback)(void);
204+
void (*_doneCallback)(void);
205+
193206
void receiveCallback(void);
194207
void completionCallback(void);
195208

196-
void (*_doneCallback)(void);
197209
static void sendRoutine(class GNSSClass*, const uint8_t*, uint32_t, gnss_send_callback_t);
198210
static void enableCallback(class GNSSClass*);
199211
static void disableCallback(class GNSSClass*);
200212
static void locationCallback(class GNSSClass*, const gnss_location_t*);
201213
static void satellitesCallback(class GNSSClass*, const gnss_satellites_t*);
214+
static void ppsCallback(class GNSSClass*);
202215
};
203216

204217
extern GNSSClass GNSS;

0 commit comments

Comments
 (0)