First time with STM32

Post here first, or if you can't find a relevant section!
wally06
Posts: 7
Joined: Tue Jun 09, 2020 4:36 pm

Re: First time with STM32

Post by wally06 »

For newbie like me, I found a very good video tutorial to install bootloader:

- Old version
https://youtu.be/wGbiT6IxGP0
I tried it, it works :)

- New version:
https://youtu.be/Myon8H111PQ
I tried it, bootloader installed but problem with windows and device. My board is maybe suspicious :/

mrburnette
Posts: 256
Joined: Thu Dec 19, 2019 1:23 am
Answers: 1

Re: First time with STM32

Post by mrburnette »

ag123 wrote:
Fri Jun 12, 2020 2:52 pm
i think i'd make my alarm clock out of a nokia one, my old radio clock the lcd got twisted so much it is fading out, the good thing about using a blue pill for a radio clock is that it can hookup with a esp8266 running at commands and time sync itself, and maybe add an additional lipo charger monitor to charge the phone :lol:
"AT commands" ... just the thought of it makes me shutter. Like, it is the bottom feeder of technology. At least up your game and think about a GPS sync'd clock. On the ESP side, you can have multiple clocks (3 I think) all homed on one ESP8266 UDP master.

https://www.hackster.io/rayburne/tardis ... gps-6b5d2a

Getting the GPS up high in the attic works well. I was concerned about the summer heat, but the ESP8266 and the GPS seem to take the heat without issues. Not recommended for metal roofs!

Image

I keep meaning to redo the client-side with a Raspberry Pi, but I am so forgettable that I cannot remember to do it when I get into my home lab.

Ray

mrburnette
Posts: 256
Joined: Thu Dec 19, 2019 1:23 am
Answers: 1

Re: First time with STM32

Post by mrburnette »

wally06 wrote:
Sat Jun 13, 2020 12:22 pm
...
I tried it, it works :)
...
Way to go! This "uC stuff" is easy once you get your head around the concepts.

Ray

ag123
Posts: 475
Joined: Thu Dec 19, 2019 5:30 am
Answers: 1

Re: First time with STM32

Post by ag123 »

i've been trying to find an 'easier' way to time sync, but either i'd have to connect it to usb, or i'd need to connect it over the airwaves somehow. it so happen that NTP is there and esp8266 at firmware has a command as part of getting time from the NTP. i think i think there may be other methods, i've not researched them though, i think there is some shortwave /longwave or some other radio stuff, to grab that from the gps directly from the airwaves is a little beyond my comprehension for now, might be possible with a stm32 and an rf frontend, and of course the laziest way is to use a TCXO, set the time and leave it for months :lol:
Last edited by ag123 on Sat Jun 13, 2020 2:15 pm, edited 1 time in total.

mrburnette
Posts: 256
Joined: Thu Dec 19, 2019 1:23 am
Answers: 1

Re: First time with STM32

Post by mrburnette »

Yea, there are many ways. Another I have used in the past:
https://www.hackster.io/rayburne/nist-d ... 266-e8b9a9

Image

But, WiFi goes off sometimes and the GPS satellites have not dropped out of the sky (yet.) After all, you said "alarm clock" so we certainly would not want you late for breakfast. :lol:


Ray

ag123
Posts: 475
Joined: Thu Dec 19, 2019 5:30 am
Answers: 1

Re: First time with STM32

Post by ag123 »

another option is literally is to improve my algorithm for the time drift offsetting
https://github.com/rogerclarkmelbourne/ ... les/RTCAdj
right now this little lousy 5c 32k crystal drift 'adjuster' got me an accuracy of less than a few 10s of seconds per month.
as we are using a 'high end' (at least better than 8 bits) stm32 after all, i'd guess i can improve the algorithm and try to figure out how temperature affects the frequencies. then with that we've our own TCXO from those cheap 5c 32 k crystals
https://www.aliexpress.com/wholesale?ca ... Text=32768

one of those things about GPS is i hope to grab signals off the 1.575 ghz airwaves and do my own gps with stm32.
then i ran into those quadrature demodulator stuff 1st hand
https://www.allaboutcircuits.com/textbo ... odulation/
and later i'd need to descramble the various PRN codes, that's quite a big challenge for my limited gray matter for now.
so perhaps that's a project for another time. but of course there are cheap gps modules these days, many of them after all running off some ARM 32 bits based mcus.
:lol:

fredbox
Posts: 81
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: First time with STM32

Post by fredbox »

another option is literally is to improve my algorithm for the time drift offsetting
Your method looks like a variation of Bresenham's algorithm where the error is applied to the value after some time. This was popular when PIC microcontrollers were all we had to play with. See https://www.romanblack.com/one_sec.htm
of course there are cheap gps modules these days,
I bought the cheapest GPS module i could find off of AliExpress. It was around $3 at the time. Indoors, it takes 15-30 minutes to acquire a lock then proceeds to find 8-10 satellites. Extracting the time from GPS is easy with the TinyGPS library. You will need to redefine the serial port from SoftwareSerial to HardwareSerial. Once you have the time from the GPS, you can periodically update the RTC and not worry about drift.

There are also time standards that use cellular signals for use in locations that can't see the sky. I've often wondered if one of the cheap GSM modules could be used as an inexpensive source of fairly accurate time.

I've had good luck with DS3231 modules. They seem to be accurate to a few seconds per year. One that I set and put in service almost two years ago is currently running about 10 seconds fast. Plus you get a couple of kilobytes of real EEPROM for your application. Most of these are configured to use a rechargable battery. You will need to modify the module to disable the charger if you use a standard 2032 battery.

ag123
Posts: 475
Joined: Thu Dec 19, 2019 5:30 am
Answers: 1

Re: First time with STM32

Post by ag123 »

ok found the GPS RF frontend
https://www.st.com/en/automotive-infota ... 5620c.html
so it seemed a bluepill gps is after all possible.
but this is a 'complicated' and amazing chip it takes that 1.575 ghz do all that AGC, SAW filter, IF, I & Q, PLL ADC and just gives you MAG (i'd guess magnitude) and SIGN
the trouble is the specs tells very little about all that PRN signals mixed up in the MAG & SIGN, how do you go about decoding that
:lol:
i think some of the more popular gps modules are like the uBlox ones
https://www.aliexpress.com/item/32949893631.html
some of them bundle with a patch antenna

the sta5620 remains interesting nevertheless but i'd guess more info is needed or one would be left with another set of 'useless' chips
another thing would be the QFN package which may mean needing hot air station to solder it
if we could figure this out, then tbe bluepill gps becomes reality
of course if we need more brute force processing power we can get a 168mhz stm32f405/407 for the job
matching those arbitrary gps prn codes don't seem like an easy task
https://en.wikipedia.org/wiki/GPS_signa ... ition_code
and there are some math
https://en.wikipedia.org/wiki/Global_Po ... _equations
which may need the fpu to help and perhaps even the fpu may not be quite adequate as we may need double precision
:lol:

mrburnette
Posts: 256
Joined: Thu Dec 19, 2019 1:23 am
Answers: 1

Re: First time with STM32

Post by mrburnette »

fredbox wrote:
Sat Jun 13, 2020 4:30 pm
...
I bought the cheapest GPS module i could find off of AliExpress. It was around $3 at the time. Indoors, it takes 15-30 minutes to acquire a lock then proceeds to find 8-10 satellites. Extracting the time from GPS is easy with the TinyGPS library. You will need to redefine the serial port from SoftwareSerial to HardwareSerial. Once you have the time from the GPS, you can periodically update the RTC and not worry about drift.
...
Honestly, decoding the serial NMEA is so easy a library is not required; simple state machine.
Example in C for PSoC4:

Code: Select all

/*
Project:    Nokia5110GLCD_PSoC4.cydwr (using bit-bang SPI)
Build date: 20140909 All code by Ray is public domain - OTHER? see Credits-Licenses.txt
UPDATED:    20140909 To include parsing of the month, day, and year
*/

#include <main.h>
#include <stdlib.h> // for function atoi()

#define NewLine() UART_UartPutChar(CR); UART_UartPutChar(LF);   // Used to insert a CR/LF
// Prototypes
void initSystem (void);

// Global variables
uint8_t len = GLCD_LCD_WIDTH / 6;       // 84 pixels / 6 == 14 ch/line
uint8_t hour, minute, seconds;          //, year, month, day;
uint8_t day, month, year;

char    buffer[GLCD_LCD_WIDTH / 6 + 1];
char    nmea[120];

// double  atof(const char *str);       // elimited Limor's float implementation

_Bool   DayLightSavings;                // Pin 3.4
uint8_t GMToffset = 4;
uint8_t Flag = 1;

int main()
{
    ForcedReset:;   // come here if onboard reset button pushed
    DayLightSavings = DSTime_Read();        // Normally true (HIGH)

    if(! DayLightSavings) GMToffset += 1;

    uint32  c = '\0';
    // int8_t  x   = 0 ;   // character position in line 0 ---> 13
    // int8_t  y  = 0 ;   // active line pointer        0 --->  5
    int8_t  k   = 0 ;
    initSystem();
    Flag = 1;          // firstTime since power-on or reset

    for(;;)
    {
        if (Flag == 1) {
            GLCD_WRITE("Waiting on GPS") ;
            // Flag = 0;
        }
        c = UART_UartGetChar();    // Get received character or null
        if (c)  
        {
            if(c == '$') {          // $ start of NMEA sentences
                for(k=0; k<5; k++)  // need 5 characters for sentence type
                {
                    LED_Write( ~LED_Read() );   // flicker LED for activity
                    do {
                        c = UART_UartGetChar();
                    }
                    while (! (c));
                    nmea[k] = c;    // G + P + R + M + C
                    // sprintf(buffer + k, "%c", c) ;  // only for debug
                }
                // DEBUGGING to GLCD
                // glcd_tiny_draw_string(0, 3, buffer);
                // glcd_write() ;                   // display
                LED_Write( LOW );                   // LED off
                if (strstr(nmea, "GPRMC"))
                {
                    do {
                        do {
                            c = UART_UartGetChar();
                            LED_Write( ~LED_Read() ); // flicker LED
                        } while (!(c));
                        nmea[k] = c;
                        ++k;
                    } while ( !( c == '*' ) && k < 120) ;   // marker
                    LED_Write( LOW );                       // LED off
                    // Inspiration: Limor Fried's Arduino GPS lib
                    char *p = nmea;
                    p = strchr(p, ',') + 1;   // position after 1st comma
                    // float    timef  = atof(p);
                    // uint32_t  time  = timef;
                    uint32_t time = atoi(p);
                              hour  = time / 10000;
                            minute  = (time % 10000) / 100;
                           seconds  = (time % 100);
                    // output to GLCD
                    sprintf(buffer, "              %s","");  // clearbuffer
                    
                    // this corrects time to the West but not the date!!!
                    if( hour > GMToffset) {
                        hour = hour - GMToffset;
                    } else {
                        hour = (hour + 24) - GMToffset; }

                    // correct midnight to follow standard format
                    if (hour == 24) hour = 0;

                    if (hour < 10) {
                        if (DayLightSavings) {
                            sprintf(buffer, "EDT:  %d", hour);
                        } else {
                            sprintf(buffer, "EST:  %d", hour);
                        }
                    } else {
                        if (DayLightSavings) {
                            sprintf(buffer, "EDT: %d%d", hour);
                        } else {                       
                        sprintf(buffer, "EST: %d%d", hour); }
                    }
                    if (minute < 10) {
                        sprintf(buffer + 7, ":0%d", minute);
                    } else {
                        sprintf(buffer + 7, ":%d%d", minute); }
                    if (seconds < 10) {
                        sprintf(buffer + 10,":0%d%s", seconds);
                    } else {
                        sprintf(buffer + 10, ":%d%d%s", seconds); }
                    sprintf(buffer + 13, "%s", "\0");
                    if(Flag == 1)
                    {
                        Flag = 0;
                        glcd_clear() ;
                        CyDelay(250) ;
                    }
                    // OUTPUT the TIME on GLCD
                    glcd_tiny_draw_string(0, 4, buffer);
                    glcd_write() ;
                    // Parse to integer date field
                    p = strchr(p, ',') +1;  // A/V?
                    p = strchr(p, ',') +1;  // lat
                    p = strchr(p, ',') +1;  // N/S?
                    p = strchr(p, ',') +1;  // lon
                    p = strchr(p, ',') +1;  // E/W?
                    p = strchr(p, ',') +1;  // speed
                    p = strchr(p, ',') +1;  // angle
                    p = strchr(p, ',') +1;  // move pass for date DDMMYY
                    // nmea date field looks like: 090914 (European)
                    uint32_t fulldate = atoi(p);
                    day     = (fulldate / 10000);
                    month   = (fulldate % 10000) / 100;
                    year    = (fulldate % 100);
                    sprintf(buffer, "              %s","");  // clearbuffer
                    if (day < 10) {
                        sprintf(buffer, "0%d", day);
                    } else {
                        sprintf(buffer, "%d%d", day); }
                    if (month < 10) {
                        sprintf(buffer + 2,"-0%d", month);
                    } else {
                        sprintf(buffer + 2,"-%d%d", month); }
                    sprintf(buffer + 5, "-20%d%d%s", year);
                    sprintf(buffer + 10,"%s",'\0');
                    // OUTPUT the DATE on GLCD
                    glcd_tiny_draw_string(0, 2, buffer);
                    glcd_write() ;
                }   // if (strstr(nmea, "GPRMC"))
            }       // if(c == '$')
        }           // if(c)
        if( ResetSW_Read() == LOW ) // Forced program restart
        {
            goto ForcedReset;
        }
    }               // for(,,)
}                   // main()

void initSystem() 
{
    CyGlobalIntEnable;
    LED_Write( HIGH );
    UART_Start();
    glcd_init();
    glcd_set_contrast(75);      //0== light 100==full black
    GLCD_TEXT_INIT();
    init_printf(NULL, putdata); // see main.h
    // Announce activity to over serial console in case listening
    UART_UartPutString("Hardware Configured\n"); NewLine(); NewLine();
    GLCD_WRITE("Terminal V1.00");
    GLCD_WRITE("Ray Burnette");
    CyDelay(2000);
    glcd_clear();
}

/* [] END OF FILE */

ag123
Posts: 475
Joined: Thu Dec 19, 2019 5:30 am
Answers: 1

Re: First time with STM32

Post by ag123 »

i went ahead and got a bunch of STA5620
https://www.aliexpress.com/item/32827396545.html
it seemed a real STA5620 should look like this
https://lh6.googleusercontent.com/proxy ... E9f-Jy-mQs
http://www.gps.net.cn/showproduct.asp?id=429
but nevertheless, at $2 per gps rf front end, it is hard to resist and i took a gamble.
:lol:

but it'd seem STA5620 may be depreciated and obselete
https://www.st.com/content/st_com/en/pr ... 5620a.html
finger crossed

i did some quick calcs, STA5620 needs a 16.368 MHz osc input, otherwise it needs to be 19.2 MHz
i couldn't get that 8 mhz crystal to output that odd 16.368 mhz out of a bluepill MCO
then i tried working that 19.2 Mhz
it turns out the divisors are
FHSE = 8 mhz
prediv2: 5
pll2mul: 12
fmco 19.2 mhz
if this works, then stm32f103 (or xxyy) may do gps itself
of course there is still the big problem of decrypting all that PRN
and jump through the hoop of all that floating point calculations, it is gps after all
:lol:

Post Reply

Return to “General discussion”