• I'm trying to build Espruino for a nRF52840 device (Particle Xenon) and started with the following:

    //1st try with defaults
    git clone https://github.com/espruino/Espruino.git­
    cd Espruino/
    source scripts/provision.sh NRF52840DK
    make clean && BOARD=NRF52840DK RELEASE=1 make

    and found out that the current source uses nRF SDK15 but "FIXME - SDK15 NFC patches don't apply cleanly" and some other fails appear. Building hex file works but executing NFC methods fail:

    Uncaught Error: Function "nfcURL" not found!

    I checked the source and found out that there is a USE_NFC option but seems that the build fails:

    targetlibs/nrf5x_15/components/nfc/t2t_l­ib/hal_t2t/hal_nfc_t2t.c: In function 'hal_nfc_send':
    targetlibs/nrf5x_15/components/nfc/t2t_l­ib/hal_t2t/hal_nfc_t2t.c:742:12: warning: passing argument 1 of 'memcpy' discards 'volatile' qualifier from pointer target type [-Wdiscarded-qualifiers]
         memcpy(m_nfc_buffer, p_data, NFC_BUFFER_SIZE);
    In file included from targetlibs/nrf5x_15/components/nfc/t2t_l­ib/hal_t2t/hal_nfc_t2t.h:56,
                     from targetlibs/nrf5x_15/components/nfc/t2t_l­ib/hal_t2t/hal_nfc_t2t.c:44:
    ~/Espruino/gcc-arm-none-eabi-8-2018-q4-m­ajor/arm-none-eabi/include/string.h:31:9­: note: expected 'void * restrict' but argument is of type 'volatile uint8_t *' {aka 'volatile unsigned char *'}
     void *  memcpy (void *__restrict, const void *__restrict, size_t);
    targetlibs/nrf5x_15/components/nfc/t2t_l­ib/hal_t2t/hal_nfc_t2t.c: In function 'NFCT_IRQHandler':
    targetlibs/nrf5x_15/components/nfc/t2t_l­ib/hal_t2t/hal_nfc_t2t.c:874:17: error: 'm_nfc_rx_buffer' undeclared (first use in this function); did you mean 'm_nfc_buffer'?
                 if (m_nfc_rx_buffer[0] == T2T_READ_CMD)
    targetlibs/nrf5x_15/components/nfc/t2t_l­ib/hal_t2t/hal_nfc_t2t.c:874:17: note: each undeclared identifier is reported only once for each function it appears in
    targetlibs/nrf5x_15/components/nfc/t2t_l­ib/hal_t2t/hal_nfc_t2t.c:874:39: error: 'T2T_READ_CMD' undeclared (first use in this function)
                 if (m_nfc_rx_buffer[0] == T2T_READ_CMD)
    make: *** [Makefile:799: ~/Espruino/targetlibs/nrf5x_15/component­s/nfc/t2t_lib/hal_t2t/hal_nfc_t2t.o] Error 1
    make: *** Waiting for unfinished jobs....

    There are 4 SDK folders under Espruino/targetlibs


    but provision.sh only supports SDK15 and SDK17.
    What is the best SDK version for building?

  • Right now NFC only works with SDK12, and I don't think nRF52840 works with that. SDK15 is what's generally used with nRF52840 at the moment.

    Basically no, right now there is no NFC support for nRF52840

    You could look at the NFC changes that were applied to SDK12 (I'm not sure there are patches - you may need to download the original SDK12 and compare, or look at Git history) and then apply those to SDK15.

    However, the patches (apart from reliability that I think was pulled from later SDKs) were to allow Espruino to emulate NFC at a deeper level (providing NFCrx events and allowing JS to send responses). I think there's a strong chance that you could just comment out that functionality in Espruino and then use the basically unpatched NFC library for SDK15 - I'd imagine that's your best bet.

    If you succeed and PR would be awesome :)

  • you can also try to build with SDK12 if you don't need USB. at least bluetooth will work with S132 softdevice and SDK12 on 52840, then maybe nfc will work too

  • nRF SDK12 comes with folder nRF5_SDK_12.3.0_d7731ad\examples\nfc\rec­ord_text\pca10056 and that NFC example runs without issues on my nRF52840@Xenon board.

    @fanoush building without USB was a good idea because after some small changes the source can be compiled. The only thing that does not work is the linker! A *.ld file is missing in the SDK12 folder and copying targetlibs/nrf5x_15/nrf5x_linkers/linker­_nrf52840_ble_espruino.ld + nrf_common.ld to the SDK12 folder builds the hex file but a lot of warnings will be thrown.

    If someone can help me fixing the link files it would be nice ;-)

  • Well, if you are building espruino from github source then it should simply work with any 52832 board file as is. Or look at MICROBIT2 board file, that one is 52833 (like 52840 but only half of features, 128KB RAM,512KB of flash) you could put LD_SRAM_SIZE=0x40000 for 52840 there to use whole RAM if you also increase variables accordingly.

    For larger flash - if you build without bootloader you can increase this https://github.com/espruino/Espruino/blo­b/master/targetlibs/nrf5x_12/nrf5x_linke­rs/linker_nrf52_ble_espruino.ld#L12 by 0x80000 (just adding + 0x80000 should work)
    with bootloader it is a bit more complex.

  • Ahhh cool! I forgot that nRF52840 is same as 52832/52833 + more memory/features. That's great, at least NRF.nfcURL is working! Many thanks @fanoush

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

How to build Espruino with NFC support (for nRF52840 boards)?

Posted by Avatar for rena2019 @rena2019