8 years, 11 months ago.  This question has been closed. Reason: Unclear question

RTOS on STM32F429 not working after recent updates on mbed

Hi, I was using RTOS on STM32F429, and recently i got the massage that mbed was updated.When I put the updated version RTOS stop Working.I am here with sending the part of the code that i was used with previous mbed. Your Help is much appreciated.Thank you.

RTOS

#include "mbed.h"
#include "QEI.h"
#include "Timer.h"
#include "SDFileSystem.h"
#include "rtos.h"

//creating objects
QEI wheelR (PC_8,PD_13,NC,400,QEI::X2_ENCODING);
QEI wheelL (PE_2,PB_3,NC ,400,QEI::X2_ENCODING );
SDFileSystem sd(PF_9, PF_8, PF_7, PF_6, "sd");
Timer timer;
AnalogOut  aoutR(PA_4);
AnalogOut  aoutL(PA_5);
DigitalIn pb(PA_0);
DigitalOut led1(PG_14);
DigitalOut led2(PG_5);
Ticker tiker;

//Second Thread
   void task2_thread(void const *args)
{
    
    tiker.attach_us(&attime,400.0);
    
}
int main(void const *args)
{
    Thread thread(task2_thread,NULL,osPriorityRealtime,(DEFAULT_STACK_SIZE*2.25));
    osThreadSetPriority(osThreadGetId(), osPriorityIdle);
    mkdir("/sd/mydir", 0777);
    FILE *fp= fopen("/sd/mydir/sdtest.txt", "w"); 
    timer.start();//max 30 min:reset after 30 min
    
    while(!pb) 
    {
           
          fprintf(fp,"%.6f %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n",timer.read(),x_cmd,x_res,y_cmd,y_res,dynamicToqure_right,V,A_filterout);
           led1=!led1;
    }
    fclose(fp);
    aoutR.write(0.5);
    aoutL.write(0.5);
    timer.stop();
    tiker.detach();

}

//ticker funtion
void attime()
{           
    led2=!led2;
    Timepaste=timer.read();
    pathGenaration();
    Werror();
    WpGain();
    WdGain();
    WiGain();
    WPIDresponse();
    InvJaco();
    intigrate1();
    intigrate2();
    adaptiveControl();
    error();
    pGain();
    dGain();
    iGain();
    response();
    currentToAnaloge();
    ResVelocity();
    dob();
    rtob();
    jacobean();
    deadRecko();
    accelarationMeasure();
} 

This is hard to follow with the missing details. Can you post your whole code using the <<code>> <</code>> tags? Or at least something complete, that is representative of the problem. task2_thread, has no infinite loop. This will execute once and the thread will terminate. Was this the intent? You can save yourself the trouble and just call a function. Then the while loop appears to have nothing to limit the rate that you try to write to the file. Just a guess, but you might run into problems if you try to just slam tons of data at the SD card all at once like this. I don't know what "pb" is, but will the while loop ever exit? If "while (!pb)" ever evaluates to 0, it looks like you will end up exiting your main function. I think this may cause undesirable behavior. Also I would look into recommended method for spawning threads. I believe the ctor you are using is marked as deprecated.

posted by Graham S. 28 Nov 2016

I'm sorry for the missing details.I edited the code, I want to run one thread for my control loop for motors and it should be highest priority.I need to run that control loop at fixed sampling time, thats why I used tiker with 400us, each 400us that controlled loop needed to be run.If time remains from that loop, then I want to run the main thread, to data writing for SD cards. pb is a push button, and I need to stop all threads when I press push button.That is what I try to do with this code.Please guide me to accomplish the task in correct way.Thank you.

posted by Arunya Senadeera 29 Nov 2016