Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 9 months ago.
GR_Peach libraries broken?
I updated my offline libraries for GR_Peach today (to mbed V134 and mbed-rtos V123) and found that just adding hardware declarations to a simple threaded example will break the code. This happens with both the online compiler and the GCC EABI offline compiler.
I strongly suspect this is caused by a lack of destructors, since I have to remove the _ _wrap_ _free_r sections from LD_FLAGS to get it to link in the offline version.
The following code does not run, but it will if you comment out the declarations for InterruptIn, SPI, and RawSerial. The main function will run, but the thread won't if you take out the last two but leave the InterruptIn line in.
Note that these are just declarations and don't do anything but initialize hardware (I'm not trying to use the hardware in the code). Yes, I'm positive this code would run correctly under mbed V113 (except for the new thread.start() functions).
Here's the code:
#include "mbed.h" #include "rtos.h" Serial pc(USBTX, USBRX); DigitalOut redled(LED_RED); DigitalOut greled(LED_GREEN); DigitalOut bluled(LED_BLUE); DigitalOut useled(LED_USER); InterruptIn irq_data(P2_14); // <--- Leave this line, blink_thread() won't run SPI spi_data(P10_14, P10_15, P10_12, P10_13); // SPI0 // <--- Leave these two lines, nothing runs RawSerial uart_data(P8_14, P8_15); // UART4 // <-' Thread h_task1_thread (osPriorityRealtime, 20480L, NULL); Thread h_task2_thread (osPriorityHigh, 20480L, NULL); Thread h_task3_thread (osPriorityNormal, 20480L, NULL); Thread h_task4_thread (osPriorityLow, 20480L, NULL); Thread h_blink_thread (osPriorityNormal, 20480L, NULL); void blink_thread () { useled = 1; while (true) { Thread::signal_wait(0x1); useled = !useled; } } int main() { h_blink_thread.start(blink_thread); while(1) { bluled = 1; wait(0.2); bluled = 0; wait(0.2); h_blink_thread.signal_set(0x1); } }
Import programpeach_blink
This program does *not* run correctly if declarations are left in.
As always, thanks in advance for any help or suggestions.
1 Answer
7 years, 9 months ago.
You don't need to have both mbed and mbed-rtos. You should just import https://github.com/ARMmbed/mbed-os/#269f58d75b752a4e67a6a2d8c5c698635ffd6752, then you should have this as the top of your program:
#include "mbed.h
I don't remember the details now, but I thought I started that way and it didn't recognize the thread declaration. Maybe I still had the #include "rtos.h" line in, which would have made it mad.
Thanks!
posted by 03 Feb 2017Well, thread declaration has changed a bit in the past year. I am seeing your issue though. I believe the InterruptIn line is the actual culprit. This needs investigation.
posted by 03 Feb 2017https://github.com/ARMmbed/mbed-os/issues/3694\ I've created an issue that you can track here.
posted by 03 Feb 2017