Suspending a thread also suspends another randomly

Hello,

I've been working on a project using nRF52832 + NCS 2.1.1 including BLE and some sensors : MAX86150, MAX30205, MP34DT05, LIS3DH

I'm sending data of these sensors through BLE on demand i.e. requesting by sending a char code on a write characteristic for example to request PPG data (from MAX86150) I send 0x01 and for ECG (from MAX86150) I send 0x02. I have two separate threads one is the main thread (thread_main) which controls data requests, system and sensors shutdown, LED control and the other thread  (thread0):

void thread_main(void) {
	while(1) {
		// Check the input from client and manage the data send
		if (meas_value != 0xFF) {
			if (meas_value == 0x00) {
				printk("cancel any calculation\n");
				if (meas_value_current == 0x01) { 		// PPG + Force
					max86150_setPA_IR(&max86150_dev, 0);
					max86150_setPA_Red(&max86150_dev, 0);
					max86150_shutdown(&max86150_dev);
					suspend_thread0 = true;
				}else if (meas_value_current == 0x02) { // ECG
					max86150_shutdown(&max86150_dev);
					suspend_thread0 = true;
				}else if (meas_value_current == 0x03) { // PCG
					nrfx_pdm_stop();
				}else if (meas_value_current == 0x04) { // TEMP
					// max30205_shutdown(&max30205_dev);
					suspend_thread0 = true;
				}else if (meas_value_current == 0x05) { // Accel
					suspend_thread0 = true;
				}
				meas_value_current = 0xFF;
			}
			else if (meas_value == 0x01) {
				printk("cal PPG\n");
				MAX86150_config.slot[0] = MAX86150_SLOT_IR_LED1;
				MAX86150_config.slot[1] = MAX86150_SLOT_RED_LED2;
				MAX86150_config.slot[2] = 0;
				MAX86150_config.slot[3] = 0;
				MAX86150_config.IR_LED_PA = 0x1E;
				MAX86150_config.RED_LED_PA = 0x1E;
				max86150_init(&max86150_dev, &MAX86150_config, &MAX86150_data);
				// max86150_wakeup(&max86150_dev);
				k_timer_start(&thread0_timer, K_MSEC(1000), K_MSEC(0));
				meas_value_current = 0x01;
				wake_to_sleep_time = 0;
			}
			else if (meas_value == 0x02) {
				printk("cal ECG\n");
				MAX86150_config.slot[0] = MAX86150_SLOT_ECG;
				MAX86150_config.slot[1] = 0;
				MAX86150_config.slot[2] = 0;
				MAX86150_config.slot[3] = 0;
				MAX86150_config.ECG_sample_rate = ECG_SAMPLE_RATE_400;
				MAX86150_config.ECG_PGA_gain = ECG_PGA_GAIN_8;
				MAX86150_config.ECG_IA_gain = ECG_IA_GAIN_9_5;
				max86150_init(&max86150_dev, &MAX86150_config, &MAX86150_data);
				// max86150_wakeup(&max86150_dev);
				k_timer_start(&thread0_timer, K_MSEC(1000), K_MSEC(0));
				meas_value_current = 0x02;
				wake_to_sleep_time = 0;
			}
			else if (meas_value == 0x03) {
				printk("cal PCG\n");
				nrfx_pdm_start();
				meas_value_current = 0x03;
				wake_to_sleep_time = 0;
			}
			else if (meas_value == 0x04) {
				printk("cal TEMP\n");
				k_timer_start(&thread0_timer, K_MSEC(1000), K_MSEC(0));
				meas_value_current = 0x04;
				wake_to_sleep_time = 0;
			}
			else if (meas_value == 0x05) {
				printk("cal Accel\n");
				k_timer_start(&thread0_timer, K_MSEC(1000), K_MSEC(0));
				meas_value_current = 0x05;
				wake_to_sleep_time = 0;
			}
			else {
				printk("do nothing\n");
				meas_value_current = 0xFF;
			}
			meas_value = 0xFF;
		}

		// If disconnect condition is fulfilled, disconnect the BLE
		if (disconnect_ble) {
			printk("disconnecting ble\n");
			bt_conn_disconnect(my_conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN);
			disconnect_ble = false;
		}

		// Put the lis3dh device to suspend mode
		if (lis3dh_drv_off) {
			printk("turning off lis3dh\n");
			pm_device_action_run(lis3dh_dev, PM_DEVICE_ACTION_SUSPEND);
		}

		// If system off condition is fulfilled, put it to the sleep mode
		if (system_off) {
			// turning off all leds if somehow one is on
			led_off(led_ind_pwm, 0);
			max86150_shutdown(&max86150_dev);
			

			printk("turning off the system\n");
			pm_state_force(0u, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0});
			k_sleep(K_SECONDS(2U));	
		}

		// Stop the measurement thread (thread0) whenever needed
		if (suspend_thread0) {
			printk("suspending thread0\n");
			k_thread_suspend(thread0_id);
			suspend_thread0 = false;
		}

		// Measure accelerometer to detect any inactivity
		struct sensor_value accel[3];

		sensor_sample_fetch(lis3dh_dev);
		sensor_channel_get(lis3dh_dev, SENSOR_CHAN_ACCEL_XYZ, accel);

		float x_accel_new = sensor_value_to_double(&accel[0]);
		float y_accel_new = sensor_value_to_double(&accel[1]);
		float z_accel_new = sensor_value_to_double(&accel[2]);

		if (abs(x_accel - x_accel_new) > 0.5 |
			abs(y_accel - y_accel_new) > 0.5 |
			abs(z_accel - z_accel_new) > 0.5)
		{
			wake_to_sleep_time = 0;
		}else{
			wake_to_sleep_time++;
			if (wake_to_sleep_time >= WAKE_DURATION) {
				k_timer_start(&before_system_off, K_MSEC(0), K_MSEC(0));
				wake_to_sleep_time = 0;
			}
		}
		x_accel = x_accel_new;
		y_accel = y_accel_new;
		z_accel = z_accel_new;

		// LED Pulsing
		if (led_pulsing) {
			led_on(led_ind_pwm, 0);
			k_msleep(50);
			led_off(led_ind_pwm, 0);
			k_msleep(50);
			led_on(led_ind_pwm, 0);
			k_msleep(50);
			led_off(led_ind_pwm, 0);
			k_msleep(50);
		}

		// Debug LED
		// gpio_pin_toggle_dt(&led_pin);
		printk("main loop running...\n");
		k_msleep(1000);

	}
}

The other thread (thread0) manages the data acquisition and sending of sensors (except for the PDM mic which has it's own callback):

void thread0(void) {
	while(1) {

		if (meas_value_current == 0x01) { // PPG + Force
			max86150_fetch_data(&max86150_dev, &MAX86150_config, &MAX86150_data);

			uint16_t ir_data = (MAX86150_data.channel_data[0]) >> 2;
			uint16_t red_data = (MAX86150_data.channel_data[1]) >> 2;

			float filtered_force = 0, sum_force = 0;
			float new_force = read_Force();
			force_array[force_idx++] = new_force;
			force_idx %= FORCE_WINDOW_SIZE;

			for (int j=0; j<FORCE_WINDOW_SIZE; j++) {
				sum_force += force_array[j];
			}
			filtered_force = (float)sum_force / FORCE_WINDOW_SIZE;
			

			// filtered_force = new_force;

			epf_buf[epf_count++] = red_data;
			epf_buf[epf_count++] = red_data >> 8;
			epf_buf[epf_count++] = ir_data;
			epf_buf[epf_count++] = ir_data >> 8;
			epf_buf[epf_count++] = 0;
			epf_buf[epf_count++] = 0;
			epf_buf[epf_count++] = (char) filtered_force;
			epf_buf[epf_count++] = (filtered_force - epf_buf[epf_count-1]) * 100;;
	
			if (epf_count >= EPF_BUF_SIZE) {
				send_notify(epf_buf, sizeof(epf_buf));
				epf_count = 0;
			}
			k_msleep(5);
		}
		else if (meas_value_current == 0x02) {// ECG
			max86150_fetch_data(&max86150_dev, &MAX86150_config, &MAX86150_data);

			int16_t ecg_data = (int16_t)(MAX86150_data.channel_data[0] >> 2);
				
			epf_buf[epf_count++] = 0;
			epf_buf[epf_count++] = 0;
			epf_buf[epf_count++] = 0;
			epf_buf[epf_count++] = 0;
			epf_buf[epf_count++] = ecg_data;
			epf_buf[epf_count++] = ecg_data >> 8;
			epf_buf[epf_count++] = 0;
			epf_buf[epf_count++] = 0;
	
			if (epf_count >= EPF_BUF_SIZE) {
				send_notify(epf_buf, sizeof(epf_buf));
				epf_count = 0;
			}
			k_msleep(5);
		}
		else if (meas_value_current == 0x04) {// Temperature
			float temp;
			uint8_t buf[2];

			// max30205_oneshot_read(&max30205_dev, &temp);
			temp = 32.5;

			buf[0] = (char) temp;
			buf[1] = (temp - buf[0]) * 100;

			send_notify(buf, sizeof(buf));
			k_msleep(1000);
		}
		else if (meas_value_current == 0x05) {// Accelerometer
			struct sensor_value accel[3];
			uint8_t buf[6];

			sensor_sample_fetch(lis3dh_dev);
			sensor_channel_get(lis3dh_dev, SENSOR_CHAN_ACCEL_XYZ, accel);

			float x_accel = sensor_value_to_double(&accel[0]);
			float y_accel = sensor_value_to_double(&accel[1]);
			float z_accel = sensor_value_to_double(&accel[2]);
			
			buf[0] = (char) x_accel;
			buf[1] = (x_accel - buf[0]) * 100;
			buf[2] = (char) y_accel;
			buf[3] = (y_accel - buf[2]) * 100;
			buf[4] = (char) z_accel;
			buf[5] = (z_accel - buf[4]) * 100;

			send_notify(buf, sizeof(buf));
			k_msleep(1000);
		}
		else {
			k_msleep(1000);
		}
	}
}

The thread_main is always running but the thread0 is suspended most of the time and is resumed on demand (when data is requested). As mentioned above, resuming and suspending thread0 is done in the thread_main. The problem is suspending thread0 is also sometimes suspending the thread_main. This happens very randomly and I haven't found any pattern to it's occurrence. I don't know exactly whats going on here. If I remove the k_thread_suspend(thread0_id) from thread_main loop and leave thread0 running forever (by having a 1000ms delay in it when there is nothing to do) then it won't occur anymore.I've attached the whole project file.

Thanks in advance,
Hossein

edit : The project file has been removed to convert this topic to public

Parents
  • Hi susheel,

    Happy new year!

    After a long time, I tried to figure out this issue. I used thread analyzer as you suggested but couldn't find it useful for this issue, or maybe I used it in a wrong way. I enabled it in the configuration file then placed the thread_analyzer_print() in the thread_main(), so it would log every second. I couldn't find anything weird in it maybe it's better to take a look at it just before the issue happens and the main loop log will end:

    [00:00:46.198,730] <inf> thread_analyzer:       : Total CPU cycles used: 1
    --- 3 messages dropped ---
    [00:00:46.198,852] <inf> thread_analyzer:  0x20002370          : STACK: unused 272 usage 688 / 960 (71 %); CPU: 0 %
    [00:00:46.198,852] <inf> thread_analyzer:       : Total CPU cycles used: 90
    [00:00:46.199,096] <inf> thread_analyzer:  0x20002478          : STACK: unused 1000 usage 536 / 1536 (34 %); CPU: 0 %
    [00:00:46.199,096] <inf> thread_analyzer:       : Total CPU cycles used: 65
    [00:00:46.199,401] <inf> thread_analyzer:  0x20001c60          : STACK: unused 1428 usage 556 / 1984 (28 %); CPU: 0 %
    [00:00:46.199,432] <inf> thread_analyzer:       : Total CPU cycles used: 3898
    [00:00:46.199,768] <inf> thread_analyzer:  0x20001b78          : STACK: unused 1600 usage 384 / 1984 (19 %); CPU: 0 %
    [00:00:46.199,768] <inf> thread_analyzer:       : Total CPU cycles used: 3854
    [00:00:46.200,164] <inf> thread_analyzer:  0x20002b10          : STACK: unused 1720 usage 264 / 1984 (13 %); CPU: 0 %
    [00:00:46.200,164] <inf> thread_analyzer:       : Total CPU cycles used: 13
    [00:00:46.200,347] <inf> thread_analyzer:  0x200027f0          : STACK: unused 616 usage 344 / 960 (35 %); CPU: 0 %
    [00:00:46.200,347] <inf> thread_analyzer:       : Total CPU cycles used: 250
    [00:00:46.200,531] <inf> thread_analyzer:  0x20002268          : STACK: unused 504 usage 736 / 1240 (59 %); CPU: 0 %
    [00:00:46.200,531] <inf> thread_analyzer:       : Total CPU cycles used: 92
    [00:00:46.200,622] <inf> thread_analyzer:  0x20002180          : STACK: unused 48 usage 656 / 704 (93 %); CPU: 17 %
    [00:00:46.200,622] <inf> thread_analyzer:       : Total CPU cycles used: 270147
    [00:00:46.200,744] <inf> thread_analyzer:  0x20002940          : STACK: unused 228 usage 92 / 320 (28 %); CPU: 81 %
    [00:00:46.200,775] <inf> thread_analyzer:       : Total CPU cycles used: 1231154
    [00:00:46.201,019] <inf> thread_analyzer:  ISR0                : STACK: unused 1528 usage 584 / 2112 (27 %)
    [00:00:46.201,049] <dbg> main_c_log: thread_main: main loop running...
    
    [00:00:47.202,606] <inf> thread_analyzer:       : Total CPU cycles used: 1
    --- 2 messages dropped ---
    [00:00:47.202,728] <inf> thread_analyzer:  0x20002370          : STACK: unused 272 usage 688 / 960 (71 %); CPU: 0 %
    [00:00:47.202,728] <inf> thread_analyzer:       : Total CPU cycles used: 90
    [00:00:47.203,002] <inf> thread_analyzer:  0x20002478          : STACK: unused 1000 usage 536 / 1536 (34 %); CPU: 0 %
    [00:00:47.203,002] <inf> thread_analyzer:       : Total CPU cycles used: 65
    [00:00:47.203,277] <inf> thread_analyzer:  0x20001c60          : STACK: unused 1336 usage 648 / 1984 (32 %); CPU: 0 %
    [00:00:47.203,308] <inf> thread_analyzer:       : Total CPU cycles used: 3991
    [00:00:47.203,613] <inf> thread_analyzer:  0x20001b78          : STACK: unused 1520 usage 464 / 1984 (23 %); CPU: 0 %
    [00:00:47.203,643] <inf> thread_analyzer:       : Total CPU cycles used: 4370
    [00:00:47.203,979] <inf> thread_analyzer:  0x20002b10          : STACK: unused 1720 usage 264 / 1984 (13 %); CPU: 0 %
    [00:00:47.204,010] <inf> thread_analyzer:       : Total CPU cycles used: 13
    [00:00:47.204,193] <inf> thread_analyzer:  0x200027f0          : STACK: unused 616 usage 344 / 960 (35 %); CPU: 0 %
    [00:00:47.204,193] <inf> thread_analyzer:       : Total CPU cycles used: 250
    [00:00:47.204,345] <inf> thread_analyzer:  0x20002268          : STACK: unused 504 usage 736 / 1240 (59 %); CPU: 0 %
    [00:00:47.204,376] <inf> thread_analyzer:       : Total CPU cycles used: 92
    [00:00:47.204,437] <inf> thread_analyzer:  0x20002180          : STACK: unused 48 usage 656 / 704 (93 %); CPU: 17 %
    [00:00:47.204,467] <inf> thread_analyzer:       : Total CPU cycles used: 276681
    [00:00:47.204,589] <inf> thread_analyzer:  0x20002940          : STACK: unused 228 usage 92 / 320 (28 %); CPU: 81 %
    [00:00:47.204,589] <inf> thread_analyzer:       : Total CPU cycles used: 1256429
    [00:00:47.204,864] <inf> thread_analyzer:  ISR0                : STACK: unused 1528 usage 584 / 2112 (27 %)
    [00:00:47.204,864] <dbg> main_c_log: thread_main: main loop running...
    
    [00:00:48.206,420] <inf> thread_analyzer:  0x20002370          : STACK: unused 272 usage 688 / 960 (71 %); CPU: 0 %
    --- 3 messages dropped ---
    [00:00:48.206,420] <inf> thread_analyzer:       : Total CPU cycles used: 90
    [00:00:48.206,665] <inf> thread_analyzer:  0x20002478          : STACK: unused 1000 usage 536 / 1536 (34 %); CPU: 0 %
    [00:00:48.206,665] <inf> thread_analyzer:       : Total CPU cycles used: 65
    [00:00:48.206,970] <inf> thread_analyzer:  0x20001c60          : STACK: unused 1336 usage 648 / 1984 (32 %); CPU: 0 %
    [00:00:48.206,970] <inf> thread_analyzer:       : Total CPU cycles used: 4077
    [00:00:48.207,275] <inf> thread_analyzer:  0x20001b78          : STACK: unused 1520 usage 464 / 1984 (23 %); CPU: 0 %
    [00:00:48.207,305] <inf> thread_analyzer:       : Total CPU cycles used: 4891
    [00:00:48.207,672] <inf> thread_analyzer:  0x20002b10          : STACK: unused 1720 usage 264 / 1984 (13 %); CPU: 0 %
    [00:00:48.207,672] <inf> thread_analyzer:       : Total CPU cycles used: 13
    [00:00:48.207,855] <inf> thread_analyzer:  0x200027f0          : STACK: unused 616 usage 344 / 960 (35 %); CPU: 0 %
    [00:00:48.207,855] <inf> thread_analyzer:       : Total CPU cycles used: 250
    [00:00:48.208,007] <inf> thread_analyzer:  0x20002268          : STACK: unused 504 usage 736 / 1240 (59 %); CPU: 0 %
    [00:00:48.208,038] <inf> thread_analyzer:       : Total CPU cycles used: 92
    [00:00:48.208,129] <inf> thread_analyzer:  0x20002180          : STACK: unused 48 usage 656 / 704 (93 %); CPU: 17 %
    [00:00:48.208,129] <inf> thread_analyzer:       : Total CPU cycles used: 283216
    [00:00:48.208,251] <inf> thread_analyzer:  0x20002940          : STACK: unused 228 usage 92 / 320 (28 %); CPU: 81 %
    [00:00:48.208,251] <inf> thread_analyzer:       : Total CPU cycles used: 1281732
    [00:00:48.208,526] <inf> thread_analyzer:  ISR0                : STACK: unused 1528 usage 584 / 2112 (27 %)
    [00:00:48.208,557] <dbg> main_c_log: thread_main: main loop running...
    
    [00:00:49.210,083] <inf> thread_analyzer:  0x20002370          : STACK: unused 272 usage 688 / 960 (71 %); CPU: 0 %
    --- 3 messages dropped ---
    [00:00:49.210,113] <inf> thread_analyzer:       : Total CPU cycles used: 90
    [00:00:49.210,327] <inf> thread_analyzer:  0x20002478          : STACK: unused 1000 usage 536 / 1536 (34 %); CPU: 0 %
    [00:00:49.210,357] <inf> thread_analyzer:       : Total CPU cycles used: 65
    [00:00:49.210,632] <inf> thread_analyzer:  0x20001c60          : STACK: unused 1336 usage 648 / 1984 (32 %); CPU: 0 %
    [00:00:49.210,662] <inf> thread_analyzer:       : Total CPU cycles used: 4163
    [00:00:49.210,968] <inf> thread_analyzer:  0x20001b78          : STACK: unused 1520 usage 464 / 1984 (23 %); CPU: 0 %
    [00:00:49.210,998] <inf> thread_analyzer:       : Total CPU cycles used: 5414
    [00:00:49.211,334] <inf> thread_analyzer:  0x20002b10          : STACK: unused 1720 usage 264 / 1984 (13 %); CPU: 0 %
    [00:00:49.211,364] <inf> thread_analyzer:       : Total CPU cycles used: 13
    [00:00:49.211,517] <inf> thread_analyzer:  0x200027f0          : STACK: unused 616 usage 344 / 960 (35 %); CPU: 0 %
    [00:00:49.211,547] <inf> thread_analyzer:       : Total CPU cycles used: 250
    [00:00:49.211,700] <inf> thread_analyzer:  0x20002268          : STACK: unused 504 usage 736 / 1240 (59 %); CPU: 0 %
    [00:00:49.211,700] <inf> thread_analyzer:       : Total CPU cycles used: 92
    [00:00:49.211,791] <inf> thread_analyzer:  0x20002180          : STACK: unused 48 usage 656 / 704 (93 %); CPU: 18 %
    [00:00:49.211,822] <inf> thread_analyzer:       : Total CPU cycles used: 289502
    [00:00:49.211,914] <inf> thread_analyzer:  0x20002940          : STACK: unused 228 usage 92 / 320 (28 %); CPU: 81 %
    [00:00:49.211,944] <inf> thread_analyzer:       : Total CPU cycles used: 1307285
    [00:00:49.212,219] <inf> thread_analyzer:  ISR0                : STACK: unused 1528 usage 584 / 2112 (27 %)
    [00:00:49.212,219] <dbg> main_c_log: thread_main: main loop running...
    
    [00:00:50.052,642] <dbg> ble_service: comm_write_cb: received byte : 0 
    
    [00:00:50.212,310] <dbg> main_c_log: thread_main: cancel any calculation
    
    [00:00:50.213,470] <dbg> main_c_log: thread_main: suspending thread0
    
    [00:00:55.102,752] <dbg> ble_service: comm_write_cb: received byte : 2 
    
    [00:01:00.052,886] <dbg> ble_service: comm_write_cb: received byte : 0 
    
    [00:01:05.053,009] <dbg> ble_service: comm_write_cb: received byte : 1 
    
    [00:01:10.103,118] <dbg> ble_service: comm_write_cb: received byte : 0 
    
    [00:01:15.153,625] <dbg> ble_service: comm_write_cb: received byte : 2 
    
    [00:01:20.153,350] <dbg> ble_service: comm_write_cb: received byte : 0 
    
    [00:01:25.103,485] <dbg> ble_service: comm_write_cb: received byte : 1 
    
    [00:01:30.103,607] <dbg> ble_service: comm_write_cb: received byte : 0 
    
    [00:01:35.153,717] <dbg> ble_service: comm_write_cb: received byte : 2 
    
    [00:01:40.153,839] <dbg> ble_service: comm_write_cb: received byte : 0 

    By the way I think the problem might be the fact that I'm suspending thread0 from the outside of itself. In this thread BLE sending and data fetching from sensors happens and maybe suspending it when it was in the middle of these operations is not a good practice, and maybe that's why this issue happens randomly. So I decided to suspend thread0 in itself and the problem seems to be solved! I'm never facing this issue again. What is your opinion about this? cause I'm a beginner in RTOS and the operation system concept.

Reply
  • Hi susheel,

    Happy new year!

    After a long time, I tried to figure out this issue. I used thread analyzer as you suggested but couldn't find it useful for this issue, or maybe I used it in a wrong way. I enabled it in the configuration file then placed the thread_analyzer_print() in the thread_main(), so it would log every second. I couldn't find anything weird in it maybe it's better to take a look at it just before the issue happens and the main loop log will end:

    [00:00:46.198,730] <inf> thread_analyzer:       : Total CPU cycles used: 1
    --- 3 messages dropped ---
    [00:00:46.198,852] <inf> thread_analyzer:  0x20002370          : STACK: unused 272 usage 688 / 960 (71 %); CPU: 0 %
    [00:00:46.198,852] <inf> thread_analyzer:       : Total CPU cycles used: 90
    [00:00:46.199,096] <inf> thread_analyzer:  0x20002478          : STACK: unused 1000 usage 536 / 1536 (34 %); CPU: 0 %
    [00:00:46.199,096] <inf> thread_analyzer:       : Total CPU cycles used: 65
    [00:00:46.199,401] <inf> thread_analyzer:  0x20001c60          : STACK: unused 1428 usage 556 / 1984 (28 %); CPU: 0 %
    [00:00:46.199,432] <inf> thread_analyzer:       : Total CPU cycles used: 3898
    [00:00:46.199,768] <inf> thread_analyzer:  0x20001b78          : STACK: unused 1600 usage 384 / 1984 (19 %); CPU: 0 %
    [00:00:46.199,768] <inf> thread_analyzer:       : Total CPU cycles used: 3854
    [00:00:46.200,164] <inf> thread_analyzer:  0x20002b10          : STACK: unused 1720 usage 264 / 1984 (13 %); CPU: 0 %
    [00:00:46.200,164] <inf> thread_analyzer:       : Total CPU cycles used: 13
    [00:00:46.200,347] <inf> thread_analyzer:  0x200027f0          : STACK: unused 616 usage 344 / 960 (35 %); CPU: 0 %
    [00:00:46.200,347] <inf> thread_analyzer:       : Total CPU cycles used: 250
    [00:00:46.200,531] <inf> thread_analyzer:  0x20002268          : STACK: unused 504 usage 736 / 1240 (59 %); CPU: 0 %
    [00:00:46.200,531] <inf> thread_analyzer:       : Total CPU cycles used: 92
    [00:00:46.200,622] <inf> thread_analyzer:  0x20002180          : STACK: unused 48 usage 656 / 704 (93 %); CPU: 17 %
    [00:00:46.200,622] <inf> thread_analyzer:       : Total CPU cycles used: 270147
    [00:00:46.200,744] <inf> thread_analyzer:  0x20002940          : STACK: unused 228 usage 92 / 320 (28 %); CPU: 81 %
    [00:00:46.200,775] <inf> thread_analyzer:       : Total CPU cycles used: 1231154
    [00:00:46.201,019] <inf> thread_analyzer:  ISR0                : STACK: unused 1528 usage 584 / 2112 (27 %)
    [00:00:46.201,049] <dbg> main_c_log: thread_main: main loop running...
    
    [00:00:47.202,606] <inf> thread_analyzer:       : Total CPU cycles used: 1
    --- 2 messages dropped ---
    [00:00:47.202,728] <inf> thread_analyzer:  0x20002370          : STACK: unused 272 usage 688 / 960 (71 %); CPU: 0 %
    [00:00:47.202,728] <inf> thread_analyzer:       : Total CPU cycles used: 90
    [00:00:47.203,002] <inf> thread_analyzer:  0x20002478          : STACK: unused 1000 usage 536 / 1536 (34 %); CPU: 0 %
    [00:00:47.203,002] <inf> thread_analyzer:       : Total CPU cycles used: 65
    [00:00:47.203,277] <inf> thread_analyzer:  0x20001c60          : STACK: unused 1336 usage 648 / 1984 (32 %); CPU: 0 %
    [00:00:47.203,308] <inf> thread_analyzer:       : Total CPU cycles used: 3991
    [00:00:47.203,613] <inf> thread_analyzer:  0x20001b78          : STACK: unused 1520 usage 464 / 1984 (23 %); CPU: 0 %
    [00:00:47.203,643] <inf> thread_analyzer:       : Total CPU cycles used: 4370
    [00:00:47.203,979] <inf> thread_analyzer:  0x20002b10          : STACK: unused 1720 usage 264 / 1984 (13 %); CPU: 0 %
    [00:00:47.204,010] <inf> thread_analyzer:       : Total CPU cycles used: 13
    [00:00:47.204,193] <inf> thread_analyzer:  0x200027f0          : STACK: unused 616 usage 344 / 960 (35 %); CPU: 0 %
    [00:00:47.204,193] <inf> thread_analyzer:       : Total CPU cycles used: 250
    [00:00:47.204,345] <inf> thread_analyzer:  0x20002268          : STACK: unused 504 usage 736 / 1240 (59 %); CPU: 0 %
    [00:00:47.204,376] <inf> thread_analyzer:       : Total CPU cycles used: 92
    [00:00:47.204,437] <inf> thread_analyzer:  0x20002180          : STACK: unused 48 usage 656 / 704 (93 %); CPU: 17 %
    [00:00:47.204,467] <inf> thread_analyzer:       : Total CPU cycles used: 276681
    [00:00:47.204,589] <inf> thread_analyzer:  0x20002940          : STACK: unused 228 usage 92 / 320 (28 %); CPU: 81 %
    [00:00:47.204,589] <inf> thread_analyzer:       : Total CPU cycles used: 1256429
    [00:00:47.204,864] <inf> thread_analyzer:  ISR0                : STACK: unused 1528 usage 584 / 2112 (27 %)
    [00:00:47.204,864] <dbg> main_c_log: thread_main: main loop running...
    
    [00:00:48.206,420] <inf> thread_analyzer:  0x20002370          : STACK: unused 272 usage 688 / 960 (71 %); CPU: 0 %
    --- 3 messages dropped ---
    [00:00:48.206,420] <inf> thread_analyzer:       : Total CPU cycles used: 90
    [00:00:48.206,665] <inf> thread_analyzer:  0x20002478          : STACK: unused 1000 usage 536 / 1536 (34 %); CPU: 0 %
    [00:00:48.206,665] <inf> thread_analyzer:       : Total CPU cycles used: 65
    [00:00:48.206,970] <inf> thread_analyzer:  0x20001c60          : STACK: unused 1336 usage 648 / 1984 (32 %); CPU: 0 %
    [00:00:48.206,970] <inf> thread_analyzer:       : Total CPU cycles used: 4077
    [00:00:48.207,275] <inf> thread_analyzer:  0x20001b78          : STACK: unused 1520 usage 464 / 1984 (23 %); CPU: 0 %
    [00:00:48.207,305] <inf> thread_analyzer:       : Total CPU cycles used: 4891
    [00:00:48.207,672] <inf> thread_analyzer:  0x20002b10          : STACK: unused 1720 usage 264 / 1984 (13 %); CPU: 0 %
    [00:00:48.207,672] <inf> thread_analyzer:       : Total CPU cycles used: 13
    [00:00:48.207,855] <inf> thread_analyzer:  0x200027f0          : STACK: unused 616 usage 344 / 960 (35 %); CPU: 0 %
    [00:00:48.207,855] <inf> thread_analyzer:       : Total CPU cycles used: 250
    [00:00:48.208,007] <inf> thread_analyzer:  0x20002268          : STACK: unused 504 usage 736 / 1240 (59 %); CPU: 0 %
    [00:00:48.208,038] <inf> thread_analyzer:       : Total CPU cycles used: 92
    [00:00:48.208,129] <inf> thread_analyzer:  0x20002180          : STACK: unused 48 usage 656 / 704 (93 %); CPU: 17 %
    [00:00:48.208,129] <inf> thread_analyzer:       : Total CPU cycles used: 283216
    [00:00:48.208,251] <inf> thread_analyzer:  0x20002940          : STACK: unused 228 usage 92 / 320 (28 %); CPU: 81 %
    [00:00:48.208,251] <inf> thread_analyzer:       : Total CPU cycles used: 1281732
    [00:00:48.208,526] <inf> thread_analyzer:  ISR0                : STACK: unused 1528 usage 584 / 2112 (27 %)
    [00:00:48.208,557] <dbg> main_c_log: thread_main: main loop running...
    
    [00:00:49.210,083] <inf> thread_analyzer:  0x20002370          : STACK: unused 272 usage 688 / 960 (71 %); CPU: 0 %
    --- 3 messages dropped ---
    [00:00:49.210,113] <inf> thread_analyzer:       : Total CPU cycles used: 90
    [00:00:49.210,327] <inf> thread_analyzer:  0x20002478          : STACK: unused 1000 usage 536 / 1536 (34 %); CPU: 0 %
    [00:00:49.210,357] <inf> thread_analyzer:       : Total CPU cycles used: 65
    [00:00:49.210,632] <inf> thread_analyzer:  0x20001c60          : STACK: unused 1336 usage 648 / 1984 (32 %); CPU: 0 %
    [00:00:49.210,662] <inf> thread_analyzer:       : Total CPU cycles used: 4163
    [00:00:49.210,968] <inf> thread_analyzer:  0x20001b78          : STACK: unused 1520 usage 464 / 1984 (23 %); CPU: 0 %
    [00:00:49.210,998] <inf> thread_analyzer:       : Total CPU cycles used: 5414
    [00:00:49.211,334] <inf> thread_analyzer:  0x20002b10          : STACK: unused 1720 usage 264 / 1984 (13 %); CPU: 0 %
    [00:00:49.211,364] <inf> thread_analyzer:       : Total CPU cycles used: 13
    [00:00:49.211,517] <inf> thread_analyzer:  0x200027f0          : STACK: unused 616 usage 344 / 960 (35 %); CPU: 0 %
    [00:00:49.211,547] <inf> thread_analyzer:       : Total CPU cycles used: 250
    [00:00:49.211,700] <inf> thread_analyzer:  0x20002268          : STACK: unused 504 usage 736 / 1240 (59 %); CPU: 0 %
    [00:00:49.211,700] <inf> thread_analyzer:       : Total CPU cycles used: 92
    [00:00:49.211,791] <inf> thread_analyzer:  0x20002180          : STACK: unused 48 usage 656 / 704 (93 %); CPU: 18 %
    [00:00:49.211,822] <inf> thread_analyzer:       : Total CPU cycles used: 289502
    [00:00:49.211,914] <inf> thread_analyzer:  0x20002940          : STACK: unused 228 usage 92 / 320 (28 %); CPU: 81 %
    [00:00:49.211,944] <inf> thread_analyzer:       : Total CPU cycles used: 1307285
    [00:00:49.212,219] <inf> thread_analyzer:  ISR0                : STACK: unused 1528 usage 584 / 2112 (27 %)
    [00:00:49.212,219] <dbg> main_c_log: thread_main: main loop running...
    
    [00:00:50.052,642] <dbg> ble_service: comm_write_cb: received byte : 0 
    
    [00:00:50.212,310] <dbg> main_c_log: thread_main: cancel any calculation
    
    [00:00:50.213,470] <dbg> main_c_log: thread_main: suspending thread0
    
    [00:00:55.102,752] <dbg> ble_service: comm_write_cb: received byte : 2 
    
    [00:01:00.052,886] <dbg> ble_service: comm_write_cb: received byte : 0 
    
    [00:01:05.053,009] <dbg> ble_service: comm_write_cb: received byte : 1 
    
    [00:01:10.103,118] <dbg> ble_service: comm_write_cb: received byte : 0 
    
    [00:01:15.153,625] <dbg> ble_service: comm_write_cb: received byte : 2 
    
    [00:01:20.153,350] <dbg> ble_service: comm_write_cb: received byte : 0 
    
    [00:01:25.103,485] <dbg> ble_service: comm_write_cb: received byte : 1 
    
    [00:01:30.103,607] <dbg> ble_service: comm_write_cb: received byte : 0 
    
    [00:01:35.153,717] <dbg> ble_service: comm_write_cb: received byte : 2 
    
    [00:01:40.153,839] <dbg> ble_service: comm_write_cb: received byte : 0 

    By the way I think the problem might be the fact that I'm suspending thread0 from the outside of itself. In this thread BLE sending and data fetching from sensors happens and maybe suspending it when it was in the middle of these operations is not a good practice, and maybe that's why this issue happens randomly. So I decided to suspend thread0 in itself and the problem seems to be solved! I'm never facing this issue again. What is your opinion about this? cause I'm a beginner in RTOS and the operation system concept.

Children
No Data
Related