• Some tests:

    Serial2.setup(9600,{});
    
    
    ERROR: *** PB *** baudRate = 9600
    ERROR: *** PB *** pinRX = 255
    ERROR: *** PB *** pinTX = 255
    ERROR: *** PB *** pinCK = 255
    ERROR: *** PB *** pinCTS = 255
    ERROR: *** PB *** bytesize = 8
    ERROR: *** PB *** PB0 = 11
    ERROR: *** PB *** PB1 = 22
    ERROR: *** PB *** PB2 = 33
    ERROR: *** PB *** parity = 0
    ERROR: *** PB *** stopbits = 1
    ERROR: *** PB *** PB3 = 44
    ERROR: *** PB *** PB4 = 55
    ERROR: *** PB *** PB5 = 66
    {  }
    

    By default setup, PB0, PB1 and PB2 are not touched.

    Serial2.setup(9600,{bytesize:7});
    
    ERROR: *** PB *** baudRate = 9600
    ERROR: *** PB *** pinRX = 255
    ERROR: *** PB *** pinTX = 255
    ERROR: *** PB *** pinCK = 255
    ERROR: *** PB *** pinCTS = 255
    ERROR: *** PB *** bytesize = 7
    ERROR: *** PB *** PB0 = 0
    ERROR: *** PB *** PB1 = 0
    ERROR: *** PB *** PB2 = 0
    ERROR: *** PB *** parity = 0
    ERROR: *** PB *** stopbits = 1
    ERROR: *** PB *** PB3 = 44
    ERROR: *** PB *** PB4 = 55
    ERROR: *** PB *** PB5 = 66
    { "bytesize": 7 }
    

    With this setup, PB0, PB1 and PB2 are overwritten.

    typedef struct {
      int baudRate;            /// FIXME uint32_t ???
      Pin pinRX;
      Pin pinTX;
      Pin pinCK;               ///< Clock, or PIN_UNDEFINED
      Pin pinCTS;              ///< Clear to send, or PIN_UNDEFINED
      unsigned char bytesize;  ///< size of byte, 7 or 8
      uint8_t PB0;              // insert PB
      uint8_t PB1;              // insert PB
      uint8_t PB2;              // insert PB
      unsigned char parity;    ///< 0=none, 1=odd, 2=even
      unsigned char stopbits;  ///< 1 or 2
      uint8_t PB3;              // insert PB
      uint8_t PB4;              // insert PB
      uint8_t PB5;              // insert PB
      bool xOnXOff;            ///< XON XOFF flow control?
      bool errorHandling;      ///< Whether to forward parity/framing errors
    } PACKED_FLAGS JshUSARTInfo;
    
    

    In the file 'jsserial.c' and in the function 'jsserialPopulateUSARTInfo' there are:

      jsvConfigObject configs[] = {
          {"rx", JSV_PIN, &inf->pinRX},
          {"tx", JSV_PIN, &inf->pinTX},
          {"ck", JSV_PIN, &inf->pinCK},
          {"cts", JSV_PIN, &inf->pinCTS},
          {"bytesize", JSV_INTEGER, &inf->bytesize},
          {"stopbits", JSV_INTEGER, &inf->stopbits},
    

    I do not know what it's doing, but it returns 4 bytes for 'bytesize' and 'stopbits', like 32 bits, but in 'JshUSARTInfo' they are set up as 'chars'

    That is, 'bytesize' overwrites 'parity, stopbits and xOnXOff'.

    It's worse with 'stopbits' because it will overwrite 'xOnXOff' and 'errorHandling' as well as write in an illegal address.

    Maybe we could get a 'JSV_CHAR' to these two.

    If I'm taking a'PICO 'and using:

    Serial2.setup(9600,{});
    
    No errors. Minified 2163 bytes to 70 bytes.
    >
     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v00 (c) 2018 G.Williams
    >{  }
    

    There's nothing going on.

    
    Serial2.setup(9600,{bytesize:8});
    
    
    No errors. Minified 2173 bytes to 80 bytes.
    >
     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v00 (c) 2018 G.Williams
    >Uncaught InternalError: Unsupported serial stopbits length.
     at line 1 col 32
    ...al2.setup(9600,{bytesize:8}),console.log(Serial2._options),c...
                                  ^
    > 
    

    Which shows that stopbits are overwritten by 0.

    Hope it is understandable.

About

Avatar for Frida @Frida started