Here's some simplified code in the case that works:
Code: Select all
static THD_WORKING_AREA(temp_thread_1_wa, 10000);
static THD_FUNCTION(temp_thread_1, p) {
(void) p;
chRegSetThreadName("Temp thread 1");
// Do some SPI communication
// Do some I2C communication (will apparently work correctly)
while (1) {
// Get temperatures from SPI and I2C and Print data
chThdSleepMilliseconds(1000);
}
}
// Working area definition for Thread1
static THD_WORKING_AREA(waThread1, 10000);
// Definition of Thread1 thread
static THD_FUNCTION(Thread1, arg) {
(void)arg;
chRegSetThreadName("speed_set");
float sv;
while (true) {
sv = setVal; // This one assignment occurs in the stripped out version of this thread function
chThdSleepMilliseconds(1000);
}
}
/*
* Application entry point.
*/
int main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
// Do some initialization
chThdSleepMilliseconds(1000);
/*
* Creates ICM thread
*/
chThdCreateStatic(temp_thread_1_wa, sizeof(temp_thread_1_wa), NORMALPRIO + 2, temp_thread_1, NULL);
chThdSleepMilliseconds(1000);
chThdSleepMilliseconds(10000); // Note that I provide a really long delay here
// In this working case, the second thread is commented out:
//chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1,
// NULL);
while (1) {
setVal = 250.0f;
chThdSleepMilliseconds(500);
setVal = 125.0f;
chThdSleepMilliseconds(500);
}
}
Code: Select all
static THD_WORKING_AREA(temp_thread_1_wa, 10000);
static THD_FUNCTION(temp_thread_1, p) {
(void) p;
chRegSetThreadName("Temp thread 1");
// Do some SPI communication
// Do some I2C communication (will apparently work correctly)
while (1) {
// Get temperatures from SPI and I2C and Print data
chThdSleepMilliseconds(1000);
}
}
// Working area definition for Thread1
static THD_WORKING_AREA(waThread1, 10000);
// Definition of Thread1 thread
static THD_FUNCTION(Thread1, arg) {
(void)arg;
chRegSetThreadName("speed_set");
float sv;
while (true) {
sv = setVal; // This one assignment occurs in the stripped out version of this thread function
chThdSleepMilliseconds(1000);
}
}
/*
* Application entry point.
*/
int main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
// Do some initialization
chThdSleepMilliseconds(1000);
/*
* Creates ICM thread
*/
chThdCreateStatic(temp_thread_1_wa, sizeof(temp_thread_1_wa), NORMALPRIO + 2, temp_thread_1, NULL);
chThdSleepMilliseconds(1000);
chThdSleepMilliseconds(10000); // Note that I provide a really long delay here and even during this time period, the first thread does not properly do SPI communication
// In this broken case, the second thread starts 11 seconds after the first thread
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1,
NULL);
while (1) {
setVal = 250.0f;
chThdSleepMilliseconds(500);
setVal = 125.0f;
chThdSleepMilliseconds(500);
}
}
Thanks,
John