Avatar for roy.emmerich

roy.emmerich

Member since Jul 2014 • Last active Aug 2014
  • 3 conversations
  • 20 comments

Busy establishing a one-man-band company at http://www.infinitefingers.com. The aim is to create a general purpose, modular, open source, IoT data logging platform and base various products on this platform.

Most recent activity

  • in Interfacing
    Avatar for roy.emmerich

    In terms of external synchronisation, I'd really consider just soldering on a 32kHz crystal - that'll save you a whole bunch of time and should be more than accurate enough for pretty much everything.

    Maybe I didn't explain myself properly @Gordon. As far as I understand things, the crystal is there to prevent the clock drifting by making sure the frequency is exactly 2^15 cycles per second. That doesn't help much if the micro RTC is off by an hour to start with or has a completely incorrect date/time (e.g. after losing power).

    What I am aiming to achieve is to have a datalogger, that is installed in some remote place, automatically update its RTC on start up and then once a day (or more frequently if desired) during long term operation from the GPS timestamp (via serial) and the time pulse pin.

    As I have applications in the scientific research and energy domains, I'd like to make it autonomous and as accurate as I can to ensure that data collected from a geographically distributed network of my devices can be reliably compared.

  • in Interfacing
    Avatar for roy.emmerich

    Goal:
    I want to accurately update the STM32F4 RTC:

    • using a GPS pulse per second (PPS) signal or
    • using the GPS RTC as external reference clock

    Some background:

    I am using the following hardware

    1. STM32F4 Discovery board
    2. MikroElektronika STM32F4 Discovery shield
    3. MikroElektronika GPS click board (ublox LEA-6S receiver)

    which pretty much looks like this:

    So far I have integrated the GPS receiver into my project pretty well and have extended the basic GPS module to include configuration commands and a few other features.

    The STM32F407 has a highly capable, built-in RTC which I would like to make use of within the Espruino JavaScript environment.

    For the inquisitive, the ST manual on how to use the RTC can be found here.

    From what I can see I have the following options to synchronise the STM32F4 RTC:

    • The RTC calendar can be synchronized to a more precise, remote clock using the RTC shift feature (see page 19 of the ST RTC manual for more details).
    • Use the "zero on write" method as described in the "Clock Synchronisation Methods" link below.
    • Figure out RFC2783 and RFC1589 and hack something using the PPS signal (as used in the gpsd Linux project).
    • Hack something according to the IEEE1588 Precision Time Protocol.

    Questions:

    1. I'd appreciate some guidance on how to expose the functionality contained in stm32f4xx_rtc.c to the Espruino JavaScript interpreter.
    2. Has anybody tried to synchronise the RTC to a more precise, external time source and is willing to share some tips?

    References:
    Here are a few interesting links that have edified me somewhat:

  • in Interfacing
    Avatar for roy.emmerich

    Edit: My apologies. I found it :)

    =========================
    @user6350 thanks so much for this wonderful code base to learn from!

    I have one question concerning your code. On lines 38 and 39 you have the following function calls:

    tracking("RMC");
    tracking("GGA");
    

    However I don't see where this tracking function is defined. Could you please clarify?

    Many thanks.
    Roy

  • in Interfacing
    Avatar for roy.emmerich

    Not sure what is going on but there must be something more at play here. I have also just tested all the above cases again, making sure to remove the card completely from the slot, and still no joy :(

    Out of desperation I even removed and replaced the whole microSD click board from the mikroBUS slot while powered up and I still got the same errors!

    The only difference I can think of is the card detect (CD) pin going low upon card extraction and going high upon re-insertion. I wonder whether that change isn't causing some confusion in the code somewhere?

    I'm off visiting a friend for the next few days so my involvement here could be a bit sporadic.

  • in Interfacing
    Avatar for roy.emmerich

    @Gordon thanks for this addition. I cloned the latest from Git, compiled it and am testing it out. This is what I see:

    Case 1.1
    A small change to case 1. Instead of DISK_ERR errors I'm getting NOT_READY errors

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v70 Copyright 2014 G.Williams
    
    >var f = require("fs").readFile("test.txt");
    ="hello\n\n"
    
    >E.unmountSD();
    =undefined
    
    // removed card
    
    >var f = require("fs").readFile("test.txt");
    ERROR: Unable to mount SD card : NOT_READY
    =undefined
    
    // re-inserted card
    
    >var f = require("fs").readFile("test.txt");
    ERROR: Unable to mount SD card : NOT_READY
    =undefined
    
    >reset();
    =undefined
    
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v70 Copyright 2014 G.Williams
    
    >var f = require("fs").readFile("test.txt");
    ERROR: Unable to mount SD card : NOT_READY
    =undefined
    

    Case 2.1
    A slight change to case 2. This time a NOT_READY error instead of a DISK_ERR error.

    // fresh restart
    
    >var f = require("fs").readFile("test.txt");
    ="hello\n\n"
    
    >E.unmountSD();
    =undefined
    
    //Removed card and re-inserted without file operation
    
    >var f = require("fs").readFile("test.txt");
    ERROR: Unable to mount SD card : NOT_READY
    =undefined
    

    Conclusion

    Just to check, I just tried 'Case 1' here on the Espruino Board and it works fine - so I'm pretty surprised that yours is different as it's using the same code.

    I guess it may be possible that you didn't do a make clean before building with the filesystem enabled, and that meant that somehow reset() didn't reinitialise the SD card?

    I did forget to do make clean last time but not this time. For me calling reset() still isn't working

    The problem is that jswrap_fs_kill is actually called from reset(), so if that doesn't solve the problem then there's something else...

    I think there has to be something else. Using the very latest Github version, calling E.unmountSD() has only managed to change DISK_ERR errors into NOT_READY errors.

  • in Interfacing
    Avatar for roy.emmerich

    Unfortunately a soft reset doesn't do the trick @Gordon. This is what happens:

    Case 1:

    // fresh restart
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v70 Copyright 2014 G.Williams
    
    >var f = require("fs").readFile("test.txt");
    ="hello\n\n"
    
    // remove card
    
    >var f = require("fs").readFile("test.txt");
    ERROR: Unable to read file : DISK_ERR
    =undefined
    
    // re-insert card
    
    >var f = require("fs").readFile("test.txt");
    ERROR: Unable to read file : DISK_ERR
    =undefined
    
    >reset();
    =undefined
    
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v70 Copyright 2014 G.Williams
    
    >var f = require("fs").readFile("test.txt");
    ERROR: Unable to mount SD card : NOT_READY
    =undefined
    

    However if I hit the reset button on the board or cycle the power then everything comes back to life.

    Case 2:

    Does the error happen if you pull the card out and re-insert it, without doing any file operations when it is removed?

    Yes, the DISK_ERR also occurs in this case:

    >var f = require("fs").readFile("test.txt");
    ="hello\n\n"
    
    //Removed card and re-inserted without file operation
    
    >var f = require("fs").readFile("test.txt");
    ERROR: Unable to read file : DISK_ERR
    =undefined
    

    Case 3:

    I thought out another situation that could occur:

    • Fresh restart.
    • Card removed and re-inserted.
    • Attempt to read from card.

    This still works. So it seems a problem arises only once you have already performed a previous card read/write and then remove/re-insert the card, with or without doing any file operations while removed.

    If the error only happens if you read when the card is removed, I'd just explicitly check the value of the card detect pin, and not do anything when it's disconnected.

    Yes, that is what I thought I'd do. Hardware wise however, as you pointed out, this isn't possible with the Espruino board as the card detect pin is not wired up. Also, it seems from the second case illustrated above, that if you have already performed a file operation, then remove and re-insert the card without any further file operations (blocked by not detecting a card) and then attempt a file operation post re-insertion, you still have a problem.

    think something needs to be reset, but the filesystem code we have just doesn't do so yet.

    Yes, this is my suspicion too @DrAzzy. It probably has to be looked at in the C code. Not exactly my strength...yet :).

    I would have it a guess that upon detecting the card removal (assuming this hardware functionality is available), that the jswrap_fs_kill() function in jswrap_fs.c should be called.

    I don't suppose it absolutely must happen in the C code. The main thing is the handle to the FATFS needs to be renewed...I think :)

Actions