Avatar for user63214


Member since Mar 2016 • Last active Oct 2018
  • 2 conversations

Most recent activity

  • in General
    Avatar for user63214

    Great! I was assuming the jsvUnlock method is similar to Objective-C retain/release mechanism so I wanted to make sure all the espruino js methods were being used correctly.

    Glad you mentioned the buffer thing, that was my next move. Setup a test and it seems to be working really well. I didn't realize the idle method was a good place to do some processing, I was thinking it was to allow sleep or something along those lines. Good to know!

    Now I can do some cleanup and more testing. Looking forward to picking up some official hardware like the Puck so that I can get it working on there also.

    Thanks for your help and awesome product Gordon!

  • in General
    Avatar for user63214

    I hope this it the correct place to post this..

    I'm trying to create a CAN Bus lib and I'm running Espruino on a Nucleo STM32F4 board. I'm not great with C but I can usually make my way around, but I've been just looking at other libs to try to figure this out.

    I'm running out of memory (I think) and the runtime crashes. I wrote a nodejs app to blast data (a frame every 2ms) to the Nucleo. When I use jsiConsolePrintf to dump the CAN frame out to the console it works without issue, so this tells me the Interrupt code is fine. But I want to dispatch an event into the JS runtime so that the frame data can be used there. When I do this the chip crashes after just a few minutes.

    Here is how I am dispatching the event:

      * @brief  Read CAN FIFO and dispatch JS event with the CAN Message data
      * @param  None
      * @retval None
    void CANx_ReadAndDispatch(CAN_TypeDef *CANx, uint8_t FIFONumber){
      CanRxMsg RxMessage;
      CAN_Receive(CANx, FIFONumber, &RxMessage);
      // Dispatch event
      JsVar *messageObj = messageObjectFromRxStruct(&RxMessage);
        jsiQueueObjectCallbacks(jsVarCan1, JS_EVENT_PREFIX"message", &messageObj, 1);
    *   Build a JS Object from the CAN RX data
    JsVar *messageObjectFromRxStruct(CanRxMsg *rx){
      uint32_t *id;
      // uint8_t size = rx->DLC+2;
      uint8_t size = 11;
      char dest[size];
      if(rx->IDE == CAN_ID_EXT)
        id = &rx->ExtId;
        id = &rx->StdId;
      // memset(dest, '\0', size);
      dest[0] = (*id >> 8);
      dest[1] = (*id);
      dest[10] = rx->DLC;
      strncpy(dest+2, rx->Data, 8);
      // Mem check
      if (jsuGetFreeStack() < 88) {
        jsExceptionHere(JSET_ERROR, "CAN:: Not enough free stack to receive this mesage. stackfree:%d", jsuGetFreeStack());
        return 0;
      JsVar *buffer = jsvNewArrayBufferWithData(11, dest);
      return buffer;
  • in Porting to new Devices
    Avatar for user63214

    Definitely! That's what I was planning on. The info on plugins on the espruino site was super helpful.

  • in Porting to new Devices
    Avatar for user63214

    I'm going to work on a CAN plugin next. I'll submit it back to the repo if you're interested.

    Thanks for all your help getting this going on the new Nucleo. I look forward to contributing more to the project!

  • in Porting to new Devices
    Avatar for user63214

    Doing a PR now

  • in Porting to new Devices
    Avatar for user63214

    I did indeed. I've been traveling and just returned home. Let me clean up the code and I'll do a PR asap!

  • in Porting to new Devices
    Avatar for user63214

    I'm just making new files for the F413 so everything should be separated out.

    I'm not sure why I get build errors when I change the 'chip' in the board.py file.

    But I did just get USB working on the board by disabling vbus_sense_enable in usbd_conf.c

  • in Porting to new Devices
    Avatar for user63214

    I managed to get it going! Another stm32 newbie mistake, but it's been fun learning. Also, the build system is pretty impressive. Good work @Gordon!

    I had to simply add a word entry for USART3 interrupt to the startup_stm32f401xx.s file the build was using. It was probably simply crashing when calling the interrupt. When trying to bring in the whole newer startup_stm32f413xx.c from the newer lib I have a problem linking. I'm going to continue cleaning things up and trying to make a proper startup for this board so I can do a PR.

    Going to try to see what I can get going on the USB side of things as this board has a built in micro USB connector.

    Could I increase the amount of jsvars in the board.py file? This chip has 320k of ram, quite a bit more than the f401.

    Thanks for all of your guidance @Gordon! I look forward to contributing back to the repo.