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.
8 years, 8 months ago.
Running RTOS onSTM32F429
Hi, I like use RTOS on STM32F429.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. 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(); }