Got a Clue but haven't got a clue

Posted on
  • Hi, just got an Adafruit Clue a couple of weeks ago (first batch I think) and I'm trying to port Espruino to it (obvs).

    But I'm running out of ideas how to get it going - all I want to get running at first is a Bluetooth connection to the web IDE to test that JS works OK, I don't care about pins and peripherals yet.

    Hence here's my super-cut-down board file:

    import pinutils;
    info = {
     'name' : "Adafruit Clue",
     'link' :  [ "" ],
     'default_console' : "EV_BLUETOOTH",
     'variables' : 2100,
     'bootloader' : 1,
     'binary_name' : 'espruino_%v_cluejs.hex',
     'build' : {
       'optimizeflags' : '-Os',
       'libraries' : [
       'makefile' : [
    chip = {
      'part' : "NRF52840",
      'family' : "NRF52",
      'package' : "QFN48",
      'ram' : 256,
      'flash' : 1024,
      'speed' : 64,
      'usart' : 2,
      'spi' : 3,
      'i2c' : 2,
      'adc' : 1,
      'dac' : 0,
      'saved_code' : {
        'address' : ((270 - 10) * 4096),
        'page_size' : 4096,
        'pages' : 10,
        'flash_available' : 1024 - ((31 + 30 + 2 + 10)*4)
    devices = {
      'BTN1' : { 'pin' : 'D5', 'pinstate' : 'IN_PULLDOWN' },
    board = {
      'left' : [],
      'right' : [],
      '_notes' : {
    board["_css"] = """
    def get_pins():
      pins = [
       { "name":"PD5", "sortingname":"D05", "port":"D", "num":"17", "functions":{}, "csv":{} },
      return pins

    I nicked bits of it from the Nordic dongle suggestions on this forum (I did get the dongle working OK, so the SDK 15 stuff is fine for me). I set the JS code address up a bit in case that needs to be clear of stuff below, but I have to admit I don't know what to put there!

    I build with:

    make clean; rm *hex *.elf

    ..not DFU I don't think, cos they use uf2 for the Clue - so I flash with:

    [..]/uf2/utils/ -f 0xada52840 --convert espruino_2v04.399_cluejs.hex
    cp flash.uf2 /media/duncan/FTHR840BOOT/

    which is getting set into the device OK, but I can't see the Clue Bluetooth device in the IDE.

    Any ideas?

  • Not sure what to suggest, but if they're not using the Nordic bootloader then you could try commenting out the bootloader:1 line in the file? That'll ensure that there's no bootloader built into the image, which may help.

  • Ah OK, I think I tried that but who knows what state things were in when I did it! I'll try that again..

  • Nope :-(

  • Most probably it is adafruit bootloader(?), so make sure the binary and saved_code espruino configuration section fits below 0xF4000 and also beware that there is factory reset bootloader functionality that will clear flash above 0xED000 so if you invoke it by some button combination the espruino filesystem mightt be corrupted/cleared.

    Also most probably you are now building hex file that includes softdevice(?) which is not suitable format for this type of update. You should get just the application hex and the softdevice already on device should match the version you build for. Bootloader always needs softdevice to be present to work so you already have specific one there and bootloader depends on it.

    Or you can of course clear everything but than you cannot use uf2 update but full flash over SWD.

  • Wow thanks fanoush, that's all really helpful .. although I don't fully understand all of it! Hopefully I haven't wiped the existing softdevice! Let me try just with the app hex then.. I don't know which SD they're on, but I guess 140.

    make sure the binary and saved_code espruino configuration section fits below 0xF4000

    not sure how I'd ensure that, what do I put in the board config and how do I work that out?

  • I guess 140

    yes, but which version of S140, looks like they are on 6.1.1 now and there is even board file for clue

    what do I put in the board config and how do I work that out?

    you needto do the math

    'saved_code' : {
        'address' : ((270 - 10) * 4096),
        'page_size' : 4096,
        'pages' : 10,
        'flash_available' : 1024 - ((31 + 30 + 2 + 10)*4)

    the ((270 - 10) * 4096) and 1024 - ((31 + 30 + 2 + 10)*4) parts. (270 - 10) and 31 + 30 + 2 + 10 are counted in number of 4KB flash pages but not sure why there are exactly such numbers

    Hopefully I haven't wiped the existing softdevice

    Not sure, probably not. But maybe you have another soft device where the app should be, don't know what the does.

    For update package you typically build with DFU_UPDATE_BUILD=1
    otherwise I think softdevice is merged into final hex file

  • Well I gave up on the uf2 stuff and zapped it via SWD, and now it's properly shagged I think. :-D

    I zapped it with the full Espruino bootloader/SD140/app_hex package.

  • Oh I didn't see that response; I was typing mine!

    So the numbers still have to be set right even when you SWD it I presume.

    My address and flash_available numbers were just grabbed from elsewhere, not calculated, plus I put a random extra bit on for luck (!), so I could use some help calculating them correctly! :-D

  • Well, the default you steal from other 52840 espruino boards is probably ok, numbers are computed for espruino bootloader size/location. So if you cleared adafruit bootloader or won't use any bootloader (which is also possible) they are probably OK, see explanations in comments here­b/master/boards/
    There are 256 4KB pages in 1MB

    EDIT: however the 31 looks fishy there in 'Softdevice uses 31 pages of flash', that would be 0x1f000 which is for S132 3.x and not right for S140 6.x. Good table is here so for S140 6.x there should be 0x26000/4096=38 instead of 31

  • We've done it!! I used a mixture of values again, yours and the one from the Nordic dongle:

      'saved_code' : {
        'address' : ((223 - 10) * 4096),
        'page_size' : 4096,
        'pages' : 10,
        'flash_available' : 1024 - ((38 + 8 + 2 + 10)*4)

    Thanks for all that info, not that I really understand what we did or how it worked, mind you!

  • Fri 2020.02.14

    Board link $29.95 USD alpha $39.95 release plus S&H

    More I/O, smaller footprint, lower (sans display - optional) cost, Espruino ready

  • Hi @DuncanCragg -- I've got a clue and just popped in here to see if someone had Espruino up on it yet. I read through the postings -- good work all!

    Would you post a process summary and build files so that I can repeat your work?


  • Hi @billsalt,

    I'm afraid I ended up using direct wired flashing to the SWD pads rather than the much nicer built-in UF2 system ("dropping a file on a disk"), but I don't know if that would've worked had I not been so impatient! The tool is needed to convert hex to uf2.

    I had to unlock the chip anyway, I think, with a CMSIS-DAP flasher on the SWD pads. I say "I think" because I do this kind of thing a lot and may have got mixed up with another device :-) I can give you those steps if you like.

    I went with the above config file, modified according to the bit where I said it worked.

    I'm not sure how much you know about all this building/flashing business, to know how to pitch my response! Let me know if I'm talking gobbledegook or baby talk so I know where I am!

  • Thanks @DuncanCragg! I'll see if I have time to replicate your work. I may/may not be a bit more familiar with the code loading process, so I'm not sure if I can add. I would like a uf2 way to do this if possible. We'll see if I find some spare time to look into it. Appreciate the info and your hard work!


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

Got a Clue but haven't got a clue

Posted by Avatar for DuncanCragg @DuncanCragg