Sony's Developer World forum

    • Home
    • Forum guidelines

    Upcoming maintenance 

     

    Dear Customers and Partners.

    This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.

    This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.

    We apologize for any inconvenience.

     

     

    Getting locked in farapi_main farapi_semtake(&g_farlock);

    Spresense
    1
    7
    1287
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jens6151 0 1 1 last edited by jens6151 0 1 1

      I am getting locked in farapi_main. The semaphore g_farlock is not unlocked.
      Consequently the next call (from another thread) is blocked. If this happens while reading from flash, then smart_fs gets locked and does not unlock. Another thread gets locked in open() ...

      Unfortunately I cannot make much sense.
      I get this error message printed out which I did not find in the code.

      #1-xxxx/SYS/E:cannot set remote API finish flag
      

      It happened while PID 24.
      Also I still get this warning

      altcom_recvthread: container is not found
      

      Log

      cpuid : 2
      modid : 1
      id    : 60
      arg   : 0d13fd18
      mbxid : 0
      flagid: 775
      flagbitno: 0
      farapi_main farapi_semtake (24) 0xd1086f4 
      cpuid : 2
      modid : 1
      id #1-xxxx/SYS/E:cannot set remote API finish flag
         : 60
      arg   : 0d13fd18
      mbxid : 257
      flagid: 775
      flagbitno: 0
      farapi_main nxsem_post (8) 0xd1086f4 
      farapi_main farapi_semtake (8) 0xd1086f4 
      cpuid : 2
      modid : 8
      id    : 144
      arg   : 0d142340
      mbxid : 0
      flagid: 775
      flagbitno: 0
      altcom_recvthread: container is not found
      altcom_recvthread: container is not found
      ps
        PID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK   STACK   USED  FILLED COMMAND
          0         0 FIFO     Kthread N-- Ready              00000000 001000 000460  46.0%  Idle Task
          1       224 RR       Kthread --- Waiting  Semaphore 00000000 002016 000604  29.9%  hpwork 0xd12ff7c
          2       100 RR       Kthread --- Waiting  Semaphore 00000000 002016 000268  13.2%  lpwork 0xd12ff88
          3       100 RR       Kthread --- Waiting  Semaphore 00000000 002016 000268  13.2%  lpwork 0xd12ff88
          4       100 RR       Kthread --- Waiting  Semaphore 00000000 002016 000268  13.2%  lpwork 0xd12ff88
          6       200 RR       Task    --- Waiting  MQ empty  00000000 001000 000400  40.0%  cxd56_pm_task
          7       255 RR       Kthread --- Waiting  Semaphore 00000000 001000 001000 100.0%! gnss_receiver
          8       100 RR       Task    --- Waiting  Semaphore 00000000 008176 001724  21.0%  init
         10       120 RR       pthread --- Waiting  Signal    fffffffd 002048 000300  14.6%  alarm_daemon 0
         11       100 RR       Task    --- Waiting  Signal    00000000 000752 000500  66.4%  pollImu
         12       100 RR       Task    --- Waiting  Signal    00000000 001504 001004  66.7%  lteConnectionChecker
         13       100 RR       Task    --- Waiting  Signal    00000000 004064 001484  36.5%  loop_globalStatus
         14       100 RR       Task    --- Ready              00000000 004072 001580  38.8%  bluetoothTask
         15       100 RR       Task    --- Waiting  Semaphore 00000000 002016 000932  46.2%  alt1250 -s0d128f18
         21       100 RR       Task    --- Waiting  MQ empty  00000000 002024 000716  35.3%  lteevt_task
         22       100 RR       pthread --- Waiting  Semaphore 00000000 002048 000908  44.3%  altcom_recvthread 0xd144750
         23       100 RR       Task    --- Running            00000000 008176 001204  14.7%  nsh
         24       100 RR       Task    --- Waiting  Semaphore 00000000 001000 000372  37.2%  gnssWork
         25       100 RR       Task    --- Waiting  Semaphore 00000000 001000 000860  86.0%! poll_geofence
         26       100 RR       Task    --- Waiting  Semaphore 00000000 004072 002508  61.5%  mqttTaskThread
         27       100 RR       Task    --- Waiting  MQ empty  00000000 004072 000732  17.9%  cloudTask
      nsh> .[K
      nsh> .[KTLS handshake succeeded
      farapi_main farapi_semtake (25) 0xd1086f4 
      
      

      poll_geofence is just polling the geofence.
      A recent change I did was to open and close the geofence when I init/add/delete a geofence. Maybe it must be opened only once on startup and never closed as in the sample?

      int poll_geofence() {
        int ret;
      
        int fdgeo = open("/dev/geofence", O_RDONLY);
        if (fdgeo < 0) {
          Log.errorln("Geofence fd not open");
          return;
        }
      
        /* Wait transition status notify */
        g_fds[0].fd = fdgeo;
        g_fds[0].events = POLLIN;
        while (true) {
          // Log.traceln("poll_geofence on CPU %d", sched_getcpu());
          ret = poll(g_fds, POLL_FD_NUM, POLL_TIMEOUT_FOREVER);
      ....
      

      Another log

      00:00:53.374 24F *** queueEvent EvGNSS:GEO_FENCE
      farapi_main farapi_semtake (24) 0xd1086f4 
      cpuid : 2
      modid : 1
      id    : 60
      arg   : 0d13fd18
      mbxid : 257
      flagid: 775
      flagbitno: 0
      farapi_main nxsem_post (8) 0xd1086f4 
      smartfs_semgive (8) 0xd13ba58 0
      smartfs_semtake (8) 0xd13ba58 1
      smartfs_semgive (8) 0xd13ba58 0
      smartfs_semtake (8) 0xd13ba58 1
      farapi_main farapi_semtake (8) 0xd1086f4 
      cpuid : 2
      modid : 8
      id    : 152
      arg   : 0d14f690
      mbxid : 0
      flagid: 775
      flagbitno: 0
      cpuid : 2
      modid : 8
      id    : 152
      arg   : 0d14f690
      mbxid : 513
      flagid: 775
      flagbitno: 0
      farapi_main nxsem_post (24) 0xd1086f4 
      cpuid : 2
      modid : 1
      id    : 60
      arg   : 0d13fd18
      mbxid : 0
      flagid: 775altcom_recvthread: container is not found
      TLS handshake succeeded
      00:00:57.053 25V MQTT_MODULE: MQTTSocketConnect PASSED
      00:00:57.053 25V MQTT_MODULE: MQTTSocketConnect PASSED
      00:00:57.056 25V MQTT_MODULE: MQTTClientInit PASSED
      00:00:57.058 25F MQTT_MODULE: Connecting to *****-ats.iot.us-east-1.amazonaws.com 8883
      00:00:57.442 25F MQTT_MODULE: You're connected to the MQTT broker!
      00:00:58.487 25V MQTT_MODULE: initializeConnection EXIT | 7617ms
      00:00:58.491 27V MQTT_MODULE: mqttPoll ENTER
      00:00:58.494 25F MQTT_MODULE: mqttTask: opened message queue to listen.
      00:00:58.581 11V Re-enter pollImu.
      00:01:03.510 27V MQTT_MODULE: mqttPoll EXIT | 5019ms
      00:01:03.513 27V MQTT_MODULE: mqttPoll ENTER
      00:01:03.592 11V Re-enter pollImu.
      farapi_main farapi_semtake (24) 0xd1086f4 
      

      What happens?

      • re-enter of geofence poll while(true)
      • Mqtt reads certificates from flash (smartfs_semtake)
      • TLS handshake succeeded message
      J 1 Reply Last reply Reply Quote
      • J
        jens6151 0 1 1 @jens6151 0 1 1 last edited by

        What I found out so far

        • I could strip the application down to only using GNSS
        • With the minimal sample it is reproducible only if I compile in the QZQSM for Arduino.
          • The resulting config is very similar, MQTT is added, some values increased, some debug is enabled.
        • It only fails when I compile with the Spresense SDK and does not fail with the Arduino Spresense SDK
        • The code for the QZQSM is not reached but it fails within Gnss.getNavData(&navData);

        It is totally confusing that the code is not used at all, only compiled in. The map file shows differences in e.g. arm-none-eabi/9.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libsupc++

        example

         .text.startup._GLOBAL__sub_I__ZN9__gnu_cxx9__freeresEv
                        0x000000000d024074       0x28 /Users/jens/spresenseenv/usr/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libsupc++.a(eh_alloc.o)
        
        

        .text increases a lot (150KB)

         .text          0x000000000d00abb4      0x4e0 /Users/jens/work/mcu_prj/prj/spresense/references/spresense-sdk/spresense/nuttx/staging/libapps.a(Print.cpp.Users.jens.work.mcu_prj.prj.spresense.prj.bicycleComputer-on-spresense_SDK.bike_computer_app.o)
         .text          0x000000000d00bca8    0x120e4 /Users/jens/work/mcu_prj/prj/spresense/references/spresense-sdk/spresense/nuttx/staging/libapps.a(QZQSM.cpp.Users.jens.work.mcu_prj.prj.spresense.prj.bicycleComputer-on-spresense_SDK.bike_computer_app.o)
        
        
        J 1 Reply Last reply Reply Quote
        • J
          jens6151 0 1 1 @jens6151 0 1 1 last edited by

          Minimal sample I reproduced it (compiling with Spresense SDK)
          main.ino

          #include "gnss_module.h"
          
          
          void setup() {
          
            Serial.begin(115200);
            while (!Serial) {
            }
          
            myinitGnss();
          
          }
          
          void loop() {
            printf("Print some stuff!\n");
            usleep(100 * 1000);
          }
          

          gnss_module.cpp

          #include "gnss_module.h"
          
          #include <Arduino.h>
          #include <GNSS.h>
          #include <RTC.h>
          #include <gpsutils/cxd56_gnss_nmea.h>
          #include <sched.h>
          #include <signal.h>
          
          #define GET_ERROR 1
          
          #if GET_ERROR
          #include <QZQSM.h>
          #endif
          
          #define LED_PULSE PIN_LED0
          #define LED_FIX PIN_LED1
          #define LED_ERR PIN_LED2
          #define LED_APP PIN_LED3
          
          SpGnss Gnss;
          SpNavData navData;  // possibly not thread safe?
          
          int gnssWorkThread = -1;
          int geofenceWorkThread = -1;
          
          static bool onceSaveGnssToFlash = true;
          static bool onceSendPosHistory = true;
          
          static void toggleLed() {
            static bool toggleState = true;
            if (toggleState) {
              ledOn(LED_PULSE);
            } else {
              ledOff(LED_PULSE);
            }
            toggleState = !toggleState;
          }
          
          void _pollGnss() {
            static int LastPrintMin = 0;
          
            if (Gnss.waitUpdate(1)) {
              printf("getNavData\n");
              Gnss.getNavData(&navData);
          
              /* Print position information. */
              if (navData.posDataExist) {
                if (navData.posFixMode == FixInvalid) {
                  ledOff(LED_FIX);
                  if (onceSendPosHistory) {
                    onceSendPosHistory = false;
                  }
                } else {
                  ledOn(LED_FIX);
                  if (onceSaveGnssToFlash) {
                    printf("saveEphemeris\n");
                    Gnss.saveEphemeris();
                    onceSaveGnssToFlash = false;
                  }
                }
              }
              printf("getDCReport\n");
              void *dcreport_data = Gnss.getDCReport();
              if (dcreport_data) {
                printf("dcreport_data %p\n", dcreport_data);
                NMEA_DcReport_Output(dcreport_data);
          #if GET_ERROR
                QZQSM report;
                RtcTime now = RTC.getTime();
                report.SetYear(now.year());
                report.Decode(((struct cxd56_gnss_dcreport_data_s *)dcreport_data)->sf);
                Serial.println(report.GetReport());
          #endif
              }
          
            } else {
              /* Not update. */
              printf("no Gnss data update\n");
            }
          }
          
          int gnssWork(int argc, FAR char *argv[]) {
            while (true) {
              printf("Re-enter pollGnss.\n");
              usleep(1100 * 1000);
              _pollGnss();
            }
            return 0;
          }
          
          // modified this :)
          #define SECRET_LOCATION_HOME_LAT 35.71068993353628
          #define SECRET_LOCATION_HOME_LNG 139.81213806399293
          #define SECRET_LOCATION_HOME_ALT 10.0
          
          #define SECRET_LOCATION_TIME_ZONE -9
          
          #define DEFAULT_GEOFENCE_RADIUS_HOME 100
          #define DEFAULT_GEOFENCE_RADIUS_CURRENT 50
          #define CONFIG_GNSS_MODULE_STACK_SIZE 1024
          
          #define GEOFENCE_ID_HOME 0
          
          void myinitGnss() {
            printf("initGnss\n");
            Gnss.setDebugMode(PrintInfo);
          
            int result;
          
            /* Activate GNSS device */
            result = Gnss.begin();
          
            if (result != 0) {
              printf("Gnss begin error!!\n");
            } else {
              printf("select GNSS\n");
              Gnss.select(GPS);
              Gnss.select(GALILEO);
              Gnss.select(QZ_L1CA);
              Gnss.select(QZ_L1S);
          
              printf("getTime\n");
              RtcTime now = RTC.getTime();
          
              now += SECRET_LOCATION_TIME_ZONE * 3600;
          
              SpGnssTime gnss_time;
              gnss_time.year = now.year();
              gnss_time.month = now.month();
              gnss_time.day = now.day();
              gnss_time.hour = now.hour();
              gnss_time.minute = now.minute();
              gnss_time.sec = now.second();
              gnss_time.usec = now.nsec() / 1000;
              printf("Gnss.setTime to: %lld", now.unixtime());
              Gnss.setTime(&gnss_time);
          
              Gnss.setPosition(SECRET_LOCATION_HOME_LAT, SECRET_LOCATION_HOME_LNG, SECRET_LOCATION_HOME_ALT);
          
              /* Start positioning */
              result = Gnss.start(HOT_START);
              if (result != 0) {
                printf("Gnss hot start failed with %d. Retry with cold start.", result);
                result = Gnss.start(COLD_START);
                if (result != 0) {
                  printf("Gnss hot and cold start failed with %d.", result);
                }
              } else {
                printf("Gnss setup OK\n");
              }
            }
            start_geofence();
            add_geofence(SECRET_LOCATION_HOME_LAT, SECRET_LOCATION_HOME_LNG, GEOFENCE_ID_HOME,
                         DEFAULT_GEOFENCE_RADIUS_HOME);
          
            gnssWorkThread = task_create("gnssWork", SCHED_PRIORITY_DEFAULT, CONFIG_GNSS_MODULE_STACK_SIZE,
                                         gnssWork, NULL);
            printf("********** PID gnssWork = %d\n", gnssWorkThread);
          
            geofenceWorkThread = task_create("poll_geofence", SCHED_PRIORITY_DEFAULT,
                                             CONFIG_GNSS_MODULE_STACK_SIZE, poll_geofence, NULL);
            printf("********** PID poll_geofence = %d\n", geofenceWorkThread);
          
            printf("initGnss complete\n");
          }
          

          gnss_module.h

          #pragma once
          
          #include <GNSS.h>
          #include <stdint.h>
          
          void myinitGnss();
          int add_geofence(double targetLatD, double targetLngD, uint8_t id, uint16_t radius,
                           uint16_t deadzone = 5, uint16_t dwell_detecttime = 10);
          int remove_geofence(uint8_t id);
          int poll_geofence();
          int stop_geofence();
          int start_geofence();
          

          gnss_module_fence.cpp

          // Modified for this project. Original license is
          
          /****************************************************************************
           * geofence/geofence_main.c
           *
           *   Copyright 2018 Sony Semiconductor Solutions Corporation
           *
           * Redistribution and use in source and binary forms, with or without
           * modification, are permitted provided that the following conditions
           * are met:
           *
           * 1. Redistributions of source code must retain the above copyright
           *    notice, this list of conditions and the following disclaimer.
           * 2. Redistributions in binary form must reproduce the above copyright
           *    notice, this list of conditions and the following disclaimer in
           *    the documentation and/or other materials provided with the
           *    distribution.
           * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
           *    the names of its contributors may be used to endorse or promote
           *    products derived from this software without specific prior written
           *    permission.
           *
           * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
           * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
           * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
           * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
           * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
           * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
           * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
           * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
           * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
           * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
           * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
           * POSSIBILITY OF SUCH DAMAGE.
           *
           ****************************************************************************/
          
          // must be included first!!
          #include <stdint.h>
          
          /****************************************************************************
           * Included Files
           ****************************************************************************/
          #include <arch/chip/geofence.h>
          #include <arch/chip/gnss.h>
          #include <errno.h>
          #include <fcntl.h>
          #include <nuttx/config.h>
          #include <poll.h>
          #include <sched.h>
          #include <stdio.h>
          #include <sys/ioctl.h>
          #include <sys/types.h>
          
          #include "gnss_module.h"
          
          /****************************************************************************
           * Pre-processor Definitions
           ****************************************************************************/
          
          #define POLL_FD_NUM 1
          #define POLL_TIMEOUT_FOREVER -1
          #define DOUBLE_TO_LONG(x) ((long)(x * 1000000.0))
          
          /****************************************************************************
           * Private Types
           ****************************************************************************/
          
          /****************************************************************************
           * Private Data
           ****************************************************************************/
          
          static int g_fdgeo = -1;
          static struct pollfd g_fds[POLL_FD_NUM] = {{0}};
          static struct cxd56_geofence_status_s g_geofence_status;
          
          /****************************************************************************
           * Private Functions
           ****************************************************************************/
          int add_geofence(double targetLatD, double targetLngD, uint8_t id, uint16_t radius,
                           uint16_t deadzone = 5, uint16_t dwell_detecttime = 10) {
            int ret;
            struct cxd56_geofence_mode_s mode;
          
            long targetLat = DOUBLE_TO_LONG(targetLatD);
            long targetLng = DOUBLE_TO_LONG(targetLngD);
          
            /* Region data. */
            struct cxd56_geofence_region_s region;
          
            printf("GNSS_F add_geofence ENTER\n");
          
            mode.deadzone = deadzone;
            mode.dwell_detecttime = dwell_detecttime;
            ret = ioctl(g_fdgeo, CXD56_GEOFENCE_IOCTL_SET_MODE, (unsigned long)&mode);
            if (ret < 0) {
              printf("GNSS_F Error Geofence set mode\n");
              close(g_fdgeo);
              return ret;
            }
          
            /* All clean region data */
            ret = ioctl(g_fdgeo, CXD56_GEOFENCE_IOCTL_DELETE, id);
            if (ret < 0) {
              // do not report false positives.
              // printf("GNSS_F Delete region %d error code %d", id, ret);
              //    return ret;
            }
          
            /* Set region data */
            region.id = id;
            region.latitude = targetLat;
            region.longitude = targetLng;
            region.radius = radius;
          
            ret = ioctl(g_fdgeo, CXD56_GEOFENCE_IOCTL_ADD, (unsigned long)&region);
            if (ret < 0) {
              printf("GNSS_F Error Add region\n");
              close(g_fdgeo);
              return ret;
            }
          
            printf("GNSS_F Added Geofence at (%ld, %ld) r=%d", region.latitude, region.longitude,
                   region.radius);
          
            printf("GNSS_F add_geofence EXIT\n");
            return ret;
          }
          
          int remove_geofence(uint8_t id) {
            int ret;
            printf("GNSS_F remove_geofence ENTER\n");
          
            ret = ioctl(g_fdgeo, CXD56_GEOFENCE_IOCTL_DELETE, id);
            if (ret < 0) {
              printf("GNSS_F Delete region %d error code: %d", id, ret);
              return ret;
            }
            printf("GNSS_F remove_geofence EXIT\n");
            return ret;
          }
          
          int poll_geofence() {
            int ret;
          
            /* Wait transition status notify */
            g_fds[0].fd = g_fdgeo;
            g_fds[0].events = POLLIN;
          
            printf("GNSS_F poll_geofence while ENTER\n");
          
            // printf("GNSS_F poll_geofence on CPU %d", sched_getcpu());
            ret = poll(g_fds, POLL_FD_NUM, POLL_TIMEOUT_FOREVER);
            if (ret <= 0) {
              printf("GNSS_F poll error %d,%x,%x - errno:%d", ret, g_fds[0].events, g_fds[0].revents,
                     get_errno());
            }
          
            if (g_fds[0].revents & POLLIN) {
              ret = read(g_fdgeo, &g_geofence_status, sizeof(struct cxd56_geofence_status_s));
              if (ret < 0) {
                printf("GNSS_F Error read geofence status data\n");
          
              } else if (ret != sizeof(struct cxd56_geofence_status_s)) {
                printf("GNSS_F Size error read geofence status data %d:%d", ret,
                       sizeof(struct cxd56_geofence_status_s));
                ret = ERROR;
          
              } else {
                ret = OK;
              }
          
              /* Check updated region */
              printf("GNSS_F [GEO] Updated region:%d", g_geofence_status.update);
          
              /* Check region status */
              for (int i = 0; i < g_geofence_status.update; i++) {
                printf("GNSS_F ID:%d, Status:", g_geofence_status.status[i].id);
          
                switch (g_geofence_status.status[i].status) {
                  case CXD56_GEOFENCE_TRANSITION_EXIT: {
                    printf("GNSS_F EXIT\n");
                  } break;
                  case CXD56_GEOFENCE_TRANSITION_ENTER: {
                    printf("GNSS_F ENTER\n");
                  } break;
                  case CXD56_GEOFENCE_TRANSITION_DWELL: {
                    printf("GNSS_F DWELL\n");
                  } break;
                  default: {
                    printf("GNSS_F UNKNOWN\n");
                  } break;
                }
              }
            }
          
            printf("GNSS_F poll_geofence EXIT\n");
            printf("GNSS_F Exit Geofence poll thread.\n");
            return ret;
          }
          
          int start_geofence() {
            printf("GNSS_F start_geofence ENTER\n");
            /* Get file descriptor to control Geofence. */
            int g_fdgeo = open("/dev/geofence", O_RDONLY);
            if (g_fdgeo <= 0) {
              printf("GNSS_F Error Geofence not open\n");
              return -ENODEV;
            }
            printf("GNSS_F start_geofence EXIT\n");
            return 0;
          }
          
          int stop_geofence() {
            printf("GNSS_F stop_geofence ENTER\n");
            int ret = ioctl(g_fdgeo, CXD56_GEOFENCE_IOCTL_STOP, 0);
            if (ret < 0) {
              printf("GNSS_F Error stop geofence\n");
            }
          
            ret = close(g_fdgeo);
            if (ret < 0) {
              printf("Error close geofence\n");
            }
          
            printf("GNSS_F stop_geofence EXIT\n");
            return ret;
          }
          

          config I changed.

          #define CONFIG_DEBUG_FEATURES 1
          #define CONFIG_DEBUG_ERROR 1
          #define CONFIG_DEBUG_WARN 1
          #define CONFIG_MODEM_ALT1250_DEBUG 1
          #define CONFIG_NFILE_DESCRIPTORS_PER_BLOCK 16
          #define CONFIG_MQ_MAXMSGSIZE 512
          #define CONFIG_FS_NEPOLL_DESCRIPTORS 16
          #define CONFIG_FS_MQUEUE_NPOLLWAITERS 8
          #define CONFIG_ASMP_MEMSIZE 0x00000
          #define CONFIG_EXTERNALS_MQTT 1
          

          Makefile (striped down, but a few unnecessary things are left)

          # Application makefile
          
          # Command name (Public function 'int <APPNAME>_main(void)' required)
          APPNAME = spresense
          
          # Application execute priority (Range: 0 ~ 255, Default: 100)
          PRIORITY =
          
          # Application stack memory size (Default: 2048)
          STACKSIZE =
          
          SPRESENSE_ARDUINO_CORE = /Users/jens/Library/Arduino15/packages/SPRESENSE
          CORE = $(SPRESENSE_ARDUINO_CORE)/hardware/spresense/2.6.0/cores/spresense
          CODE_BIKE_MAIN = /Users/jens/work/mcu_prj/prj/spresense/prj/bicycleComputer-on-spresense/src/main
          LIBRARIES_SPRESENSE = $(SPRESENSE_ARDUINO_CORE)/hardware/spresense/2.6.0/libraries
          LIBRARIES_ARDUINO = /Users/jens/Documents/Arduino/libraries
          
          CXXSRCS += $(CORE)/HardwareSerial.cpp
          CXXSRCS += $(CORE)/IPAddress.cpp
          CXXSRCS += $(CORE)/Print.cpp
          CXXSRCS += $(CORE)/Stream.cpp
          CXXSRCS += $(CORE)/WInterrupt.cpp
          CXXSRCS += $(CORE)/WMath.cpp
          CXXSRCS += $(CORE)/WString.cpp
          CSRCS += $(CORE)/hooks.c
          MAINSRC += $(CORE)/main.cpp
          CSRCS += $(CORE)/multi_print.c
          CSRCS += $(CORE)/time.c
          CSRCS += $(CORE)/timer_utility.c
          CSRCS += $(CORE)/wiring_analog.c
          CSRCS += $(CORE)/wiring_digital.c
          CSRCS += $(CORE)/wiring_pulse.c
          CSRCS += $(CORE)/wiring_shift.c
          CSRCS += $(CORE)/wiring_tone.c
          
          CXXSRCS += $(LIBRARIES_SPRESENSE)/EEPROM/src/EEPROM.cpp
          CXXSRCS += $(LIBRARIES_SPRESENSE)/File/src/File.cpp
          CXXSRCS += $(LIBRARIES_SPRESENSE)/GNSS/GNSS.cpp
          CXXSRCS += $(LIBRARIES_SPRESENSE)/LowPower/src/LowPower.cpp
          CXXSRCS += $(LIBRARIES_SPRESENSE)/MemoryUtil/MemoryUtil.cpp
          CXXSRCS += $(LIBRARIES_SPRESENSE)/MP/src/MP.cpp
          CXXSRCS += $(LIBRARIES_SPRESENSE)/RTC/src/RTC.cpp
          CXXSRCS += $(LIBRARIES_SPRESENSE)/RTC/src/RtcTime.cpp
          CXXSRCS += $(LIBRARIES_SPRESENSE)/SDHCI/src/SDHCI.cpp
          CXXSRCS += $(LIBRARIES_SPRESENSE)/SPI/SPI.cpp
          CXXSRCS += $(LIBRARIES_SPRESENSE)/Storage/src/Storage.cpp
          CXXSRCS += $(LIBRARIES_SPRESENSE)/Wire/Wire.cpp
          
          CXXSRCS += $(LIBRARIES_ARDUINO)/QZQSM/src/QZQSM.cpp
          
          
          CXXSRCS += $(CODE_BIKE_MAIN)/gnss_module_fence.cpp
          CXXSRCS += $(CODE_BIKE_MAIN)/gnss_module.cpp
          CXXSRCS += $(CODE_BIKE_MAIN)/main_app.cpp
          
          # Additional assembler source files (*.S)
          ASRCS =
          
          # C compiler flags
          _INCLUDES += -I$(TOPDIR)/include/nuttx/include
          _INCLUDES += -I$(SPRESENSE_ARDUINO_CORE)/tools/spresense-sdk/2.6.0/spresense/release/nuttx/include/libcxx 
          _INCLUDES += -I$(SPRESENSE_ARDUINO_CORE)/tools/spresense-sdk/2.6.0/spresense/release/nuttx/include 
          _INCLUDES += -I$(SPRESENSE_ARDUINO_CORE)/tools/spresense-sdk/2.6.0/spresense/release/nuttx/arch 
          _INCLUDES += -I$(SPRESENSE_ARDUINO_CORE)/tools/spresense-sdk/2.6.0/spresense/release/nuttx/arch/chip 
          _INCLUDES += -I$(SPRESENSE_ARDUINO_CORE)/tools/spresense-sdk/2.6.0/spresense/release/sdk/include 
          _INCLUDES += -I$(SPRESENSE_ARDUINO_CORE)/tools/spresense-sdk/2.6.0/spresense/release/sdk/modules/include 
          _INCLUDES += -I$(SPRESENSE_ARDUINO_CORE)/tools/spresense-sdk/2.6.0/spresense/release/sdk/apps/include 
          _INCLUDES += -I$(SPRESENSE_ARDUINO_CORE)/tools/spresense-sdk/2.6.0/spresense/release/sdk/system/include 
          _INCLUDES += -I$(SPRESENSE_ARDUINO_CORE)/tools/spresense-sdk/2.6.0/spresense/release/sdk/externals/include 
          _INCLUDES += -I$(SPRESENSE_ARDUINO_CORE)/tools/spresense-sdk/2.6.0/spresense/release/sdk/externals/include/cmsis 
          _INCLUDES += -I$(SPRESENSE_ARDUINO_CORE)/hardware/spresense/2.6.0/variants/spresense 
          _INCLUDES += -I$(SPRESENSE_ARDUINO_CORE)/hardware/spresense/2.6.0/cores/spresense
          _INCLUDES += -I$(LIBRARIES_ARDUINO)/QZQSM/src
          _INCLUDES += -I$(LIBRARIES_SPRESENSE)/EEPROM/src
          _INCLUDES += -I$(LIBRARIES_SPRESENSE)/File/src
          _INCLUDES += -I$(LIBRARIES_SPRESENSE)/GNSS
          _INCLUDES += -I$(LIBRARIES_SPRESENSE)/LowPower/src
          _INCLUDES += -I$(LIBRARIES_SPRESENSE)/MP/src
          _INCLUDES += -I$(LIBRARIES_SPRESENSE)/MemoryUtil
          _INCLUDES += -I$(LIBRARIES_SPRESENSE)/RTC/src
          _INCLUDES += -I$(LIBRARIES_SPRESENSE)/SDHCI/src
          _INCLUDES += -I$(LIBRARIES_SPRESENSE)/SPI
          _INCLUDES += -I$(LIBRARIES_SPRESENSE)/Storage/src
          _INCLUDES += -I$(LIBRARIES_SPRESENSE)/Wire
          
          COMMON_FLAGS += -DARDUINO_BOARD=\"spresense_ast\"
          COMMON_FLAGS += -DARDUINO=10816
          COMMON_FLAGS += -DARDUINO_ARCH_SPRESENSE
          COMMON_FLAGS += -DARDUINO_spresense_ast
          COMMON_FLAGS += -DCONFIG_HAVE_DOUBLE
          COMMON_FLAGS += -DCONFIG_WCHAR_BUILTIN
          COMMON_FLAGS += -DF_CPU=156000000L
          COMMON_FLAGS += -fpermissive
          COMMON_FLAGS += -ggdb
          COMMON_FLAGS += -Os
          COMMON_FLAGS += -w
          
          CFLAGS = $(_INCLUDES) $(COMMON_FLAGS)
          CXXFLAGS = $(_INCLUDES) $(COMMON_FLAGS)
          
          CXXEXT = .cpp
          
          LDFLAGX += -Map=output.map
          
          include $(SPRESENSE_HOME)/.vscode/application.mk
          
          J 1 Reply Last reply Reply Quote
          • J
            jens6151 0 1 1 @jens6151 0 1 1 last edited by

            After removing the QZQSM and switching back to the full application, I did not see any lock ups anymore. I will observe it for a while but believe for now that this issue is solved.

            If anyone has any idea what happens, please let me know.

            J 1 Reply Last reply Reply Quote
            • J
              jens6151 0 1 1 @jens6151 0 1 1 last edited by

              As it does not make sense that this library causes these issues ... here an update.

              I investigated on differences between SDK and Arduino.

              1. While SDK uses separate calls for gcc, g++, ar and ld (and probably more), the Arduino compiles and links with arm-none-eabi-g++. This introduces some ""smart" additional flags.
              2. The compiler flags are different. Arduino has additional ones like
              gcc/g++
              -MMD -pipe -gdwarf-3 -fno-strict-aliasing -fno-strength-reduce
              
              ld
              -nodefaultlibs -nostartfiles -gc-sections
              

              Additionally by removing -fpermissive I was pointed to programming mistakes which I fixed.

              It seems that these mistakes or the different compiler switches introduced memory corruptions at a very early state. Maybe already at up_cxxinitialize().

              I think this issue can be closed.

              J 1 Reply Last reply Reply Quote
              • J
                jens6151 0 1 1 @jens6151 0 1 1 last edited by

                @jens6151-0-1-1
                I conclude that the GNSS issue described here https://forum.developer.sony.com/topic/844/can-i-shrink-the-dsp-src-s-heap-memory was the issue. It is unrelated to farapi.

                Btw. farapi switches automatically to CPU0 on SMP, so it should work fine with SMP.

                This issue can be closed.

                J 1 Reply Last reply Reply Quote
                • J
                  jens6151 0 1 1 @jens6151 0 1 1 last edited by

                  @jens6151-0-1-1 see farapi can get into deadlock when SMP is on.

                  1 Reply Last reply Reply Quote
                  • First post
                    Last post
                  Developer World
                  Copyright © 2021 Sony Group Corporation. All rights reserved.
                  • Contact us
                  • Legal