• 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!

About

Avatar for Gordon @Gordon started