• Im working on getting Espruino up and running the nRF52832 (ble enabled ARM Cortex M4F) SoC dev board. I forked the github repo and after reading around Im planning on doing the following.

    • Edit the Makefile
    • Create boards/nrf52832.py
    • Create boards/pins/nrf52832.csv
    • Add files from Nordics SDK to targets/lib/nrf52832
    • Create the file jshardware.c in targets/nrf52832

    Am I on the right track/any tips?

    Appreciate the help!
    -Mike

  • Hi Mike,

    Great, i'd be really interested to see how you get on.

    Yes, that sounds spot on.

    Instead of using the CSV, you can also hard-code pins in the python file, see here and here

    The csv files are really when you've got different peripherals on different pins (and Espruino has to know which is which), but it's possible the NRF52832 works differently anyway.

    For starters I'd totally forget about implementing the GPIO, I2C and SPI, and focus on hacking up serial IO so you can talk to the interpreter. From then on, life gets a lot easier.

    Note right now I've just merged the new STM32 USB changes, and on other targets you'll need to call jsiOneSecAfterStartup after you're sure the device will have had time to get usb enabled. I think linux builds might be dead right now because of that.

  • OK,

    I have serial IO going and working with the terminal through COM port. The way I do this is implementing non blocking UART on nRF52 and going through an interface MCU on dev board that is seen as USB CDC by computer.

    But now I need to integrate this into Espruino and not sure how to do that. Would I initialize UART in jshInit()? Im confused about how to get the bytes I read from terminal to Espruino and how to have Espruino write to terminal. Where does this happen?

    Also is jshardware.c and main.c and BOARD.py the only files I need to create? Then just add all libraries i need in targetlibs/target/lib and then modify makefile? What other files/documentation should I be looking at for reference?

    Last Im alittle confused about the Devices. Im guessing just specify UART as a device in BOARD.py and select default console as EV_Serial1? And then I wouldnt need to do any USB defines in the Makefile.

    Thanks!

  • Would I initialize UART in jshInit()?

    Yes, however I'd add the code in jshUSARTSetup - which gets called each time a UART needs initialising, and is passed baud rate/etc.

    You'd then want to call that from jshInit - maybe copy the jshResetSerial function from stm32 and then call it from jshInit and jshReset like the STM32 target does.

    Im confused about how to get the bytes I read from terminal to Espruino and how to have Espruino write to terminal.

    When you get a character from the UART (ideally this would be in an interrupt), you want to call: jshPushIOCharEvent(EV_SERIAL1, (char)ch);

    Ideally, for transmit you'd add code to jshUSARTKick that would enable interrupts for the UART and then send the first character, and in the interrupt handler for the UART you'd do:

    int ch = jshGetCharToTransmit(EV_SERIAL1);
    if (ch>=0) uartTransmit(ch);
    else uartDisable();
    

    But, as kind of a stopgap you can do:

    void jshUSARTKick(IOEventFlags device)  {
      if (device!=EV_SERIAL1) return;
      int ch = jshGetCharToTransmit(device);
      if (ch>=0) uartTransmit(ch);
    }
    
    void jshIdle() {
      jshUSARTKick(EV_SERIAL1);
    }
    

    The issue with doing it from idle is really that if Espruino is busy, it's not going to be sending any data - it'd be relatively easy to crash it just by printing a load of data.

    Also is jshardware.c and main.c and BOARD.py the only files I need to create? Then just add all libraries i need in targetlibs/target/lib and then modify makefile?

    Yes, that should be about it... Potentially you may need to modify build_platform_config.py in order to get some of the #defines for saving to flash to point at the right place, but that's probably not an issue immediately.

    What other files/documentation should I be looking at for reference?

    There's not much apart from README.md I'm afraid. Best to look at what's done in the Makefile for other classes of device. For how to implement the contents of jshardware, the stm32 implementation is best, but the linux one might be handy too, as it's a bit higher level than the hardware-level stuff in stm32.

    Last Im alittle confused about the Devices.

    Espruino's got two queues, and input one where IRQs deposit info for the interpreter (jshPushIOCharEvent/etc) and one where the interpreter puts data and then the IRQs grab it (jshGetCharToTransmit). It doesn't have a queue per Serial port, so instead what you do is tag each bit of data with the device that it's for (with the IOEventFlags EV_* constants).

    To make matters more confusing you've also got the JSH_*(JshPinFunction) constants like JSH_USART1 - but those are used to represent the hardware itself (for instance JSH_USART1|JSH_USART_TX is the transmit pin), rather than data.

    ... and in the Board.py file, if that's what you actually mean? Devices there is mainly for the benefit of the pinout diagram, although it's used to set the constant for LED1/LED2/BTN1/etc - as well as to automatically configure things like SD cards if they're specified.

    Im guessing just specify UART as a device in BOARD.py and select default console as EV_Serial1? And then I wouldnt need to do any USB defines in the Makefile.

    Yes, set the default console as Serial1. You shouldn't have to put anything in devices though

    Hope that helps!

  • OK thank you, this clears a lot up for me!

  • OK so Ive done everything we talked about and it looks like it could work. I got everything to compile and generate espruino_1v79.119_nrf52832.bin but it is empty. I get the message PASS - size of 0 is under 436224 bytes. Any idea what could be causing this?

  • There's a script called scripts/build_linker.py I think that builds the linker script... The linker script itself is gen/linker.ld, and it could be that something in it (because it's not targeting STM32) is wrong?

  • hey so after changing the linker script to target nrf52 im finally getting PASS - size of 153676 is under 436224 bytes. the problem is I had to tell the linker script I have more RAM than i actually do to get this to happen.

    I was getting espruino...nrf52.elf section ".bss" will not fit in region "RAM" - region "RAM" overflowed with stack -region "RAM" overflowed by 24692 bytes

    when I had the actual amount of RAM in nrf52832.py. The board has 64kb of RAM and I have things like GRAPHICS, USE_NET etc.. disabled. Any idea of what could be going on? right now i think it may still be a problem in linker script but wanted to see what you think.

    thanks, Mike

  • now looking at espruino_1v79...nrf52832dk.lst I am seeing that everything looks normal in terms of the different sections and their memory except for .bss. .bss size is 89052 bytes.

    for the stm32f4discovery it is 91kb.

    right now I only have 32kb of RAM to work with total. Where can i reduce this memory useage? what are the tradeoffs? it doesnt look like stm sets memory aside for the stack or heap?

  • figured out the problem. I changed variables in BOARDS.py from ~5000 to 512. Now it is compiling successfully

  • Well that'd do it! Once you get it working, you can nudge that up. JSVars are 16 bytes each, so you can definitely get more (though you do need to leave space for the stack)

  • Great, glad you got it sorted!

    Also, if you stick at 1022 vars or below, Espruino can get away with using 12 bytes for each variable instead.

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

Interfacing with the new nRF52832 development kit

Posted by Avatar for mjdietz @mjdietz

Actions