Custom native firmware?

Posted on
  • So I found out that javascript isn't quite performant enough for my project and I want to jump off the deep end and write my code in native C, but for programming micro controllers I've only ever used the Arduino IDE.

    Is there any sort of blink example project already configured with a Makefile that builds a DFU image for the Puck.js?

    I don't really have a need for the additional sensors that the puck includes, I only have a need for NFC related functions at the moment.

    I'm no stranger to Linux either.

  • First, you can compile javascript to C: https://www.espruino.com/Compilation That might help. Or haven't seen what is exactly slow, but there might be room for some optimization.

    If you have some functionality that is not supported by the espruino Js -> C compiler, you can add your own C code: https://github.com/espruino/Espruino/blo­b/master/libs/README.md

    If you want to do 100% custom code, Nordic semi's website is your best bet I guess: https://www.nordicsemi.com/Products/Low-­power-short-range-wireless/nRF52832

  • between first and second choice there is also https://www.espruino.com/InlineC
    can do more than compiled JS (and faster, with less bloat) but less than native extensions linked into Espruino binary

  • I'd rather just write the code in native C instead of dealing with anything the JS to C transpiler might introduce.

    I don't have an issue with C code, I'm just a little confused with how the compile process works, especially when you consider that the puck.js has secure dfu

    My code when you really boil it down can be condensed into a single switch statement on the first byte of the received data since all NFC commands are one byte

  • So you don't need bluetooth either? what you do with bytes received over nfc then?
    How do you plan to debug it or update after your code hangs due to some bug?

    Anyway, you can start with
    nrf2832 specs https://infocenter.nordicsemi.com/topic/­struct_nrf52/struct/nrf52832.html?cp=4_2­ and Nordic SDK12 https://infocenter.nordicsemi.com/topic/­com.nordic.infocenter.sdk5.v12.3.0/index­.html?cp=7_5_9
    If you plan to use SWD you can use any other (e.g. latest) SDK

  • I don't actually need bluetooth at this very moment, what I'm doing is writing a NTAG215 tag emulator that has a couple different slots that can be swapped with the button that also has a backdoor NFC command that allows rewriting the entire "tag".

    I might add in bluetooth later so that I can just manage the tag data directly from an app, but I don't even have that implemented in javascript yet.

    After looking into inline c, that could potentially be all I need, but I am curious if I could call the NRF.nfcSend() directly from the C code in some way, that would certainly simplify and speed up things in that respect by not having to pass the response data back to the javascript side of things.

    it's not that I dislike the javascript environment, it's just not fast enough it seems to process and send the ntag215 response back within the few ms required.

    As far as debugging, I have pin headers on my puck and just connect over uart.

    here's what I have so far, it does work, but not all devices are very accepting of the timings.

  • Hi - the issue you might be having is (as you say) the delay introduced by Espruino's JS handling of NFC. Hopefully you could write some Inline C code, but Espruino still executes that code outside the interrupt in which it happens, which would introduce some lag.

    As others have said, the Puck is just a standard nRF52832 using SDK12. You could get Nordic's tools set up and then just start compiling and uploading their NFC examples and they should 'just work': https://infocenter.nordicsemi.com/index.­jsp?topic=%2Fcom.nordic.infocenter.sdk5.­v12.3.0%2Findex.html&cp=7_5_9

    However you'll probably find that a very steep learning curve. We've had to patch Nordic's NFC libraries to let us get that low level with tag handling.

    So there is a bit of a middle ground - just compile the Espruino firmware and make some tweaks to it. If you've some knowledge of Linux it should be totally trivial: https://github.com/espruino/Espruino/blo­b/master/README_Building.md#under-linux

    Then you can add your code into the NFC handler here: https://github.com/espruino/Espruino/blo­b/master/targets/nrf5x/bluetooth.c#L1525­

    At that point (nfc_callback) you're running in an IRQ, so anything you do should be extremely fast.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Custom native firmware?

Posted by Avatar for DanTheMan827 @DanTheMan827

Actions