2014-10-27 07:22 PM
STM32Cube USB FREERTOS
For practice I wish to use cube to generate FS USB (device) and 4 analog inputs with FREERTOS. For now my target is the STM32F4 Discovery board. Perhaps adding FREERTOS to the project was a mistake.I am okay with waiting for a command from the host then reading the 4 ADC inputs and outputting all 4 halfwords to the host. Even better would be to read the ADC values every millisecond and output the last read values to the host.I have read STM32F4xxx analog ports before. Indeed, I used my own simple RTOS to implement a 4-port DTMF decode on STM32F405 parts. I see 3 places in main.c where I can (likely must) perform some kind of action. ==> What kinds of things go into each section?==> How do I wait for the USB host to send a request?==>And while I�m asking, how does a task wait for the ADC�s DMA ISR? The FREERTOS docs I have been able to find say very little. To make things worse the docs seem to assume that I understand much about FREERTOS. #stm32cube-usb-freertos2014-10-28 07:14 AM
Hi
Is there a question in there somewhere, or are you just having a moan? ''The FREERTOS docs I have been able to find say very little.'' ''I see 3 places in main.c where I can (likely must) perform some kind of action. '' If you are using FreeRTOS, the main context is not available. Instead, you must create Task(s) and do things in that Task(s). ''How do I wait for the USB host to send a request?'' Tasks can be made to wait for a message to come in on a Queue. The USB driver should post a message from the ISR to a task. ''And while I’m asking, how does a task wait for the ADC’s DMA ISR? '' ISRs can post a message to a task. The Task should wait for a message to process. The ISR can take the ADC result and post it is a message to a task. It is up to the software designer to design the tasks, message structures and inter-task messaging in a way that works for the problem at hand.2014-11-01 05:51 AM
Hi,
Per description of your project, activating FreeRTOS is a mistake. I would disable it and rewrite to dont need the RTOS.You need FreeRTOS if you need ''Multitasking'', Its like threads in Windows.RTOS is needed if you have to warranty that an event is handled within a specific time or You have so many different jobs with different accuracies that its difficult to manage by ISR or poling.The USB connection to the PC is like a serial communication over RS-232. What you send at t his side, you get on the other side and vice versa. You have to manage the protocol yourself as you want.In my opinion, if you want receive from PC every millisecond 4 ADC values, it would normally no problem for a PC. Did you think about what happens, when windows start its garbage collection or the receiving task is disabled for say 1 second (is only a guess) by disk read/write operation? What do you do with the 1000 values which are in the receive queue or probably partly lost?I would do this job without FreeRTOS. I would write ISRs which reads with DMA or Interrupt the ADC values and put it to a buffer and transfer to a ''work buffer'' after all values are read and set a flag that they are valid.For PC-communication I would use an interrupt which receives the request from PC and take the values from work buffer and set them into Tx buffer and initiate transmit to PC by DMA or Interrupt.Please take care to disable interrupts when you take the values to work because new values can come in which will update your work buffer during using them an produce data garbage.Your main programm is basicly used for initiation of the process and manage triggering, timeouts and errors.You see? there is no need for RTOS.I hope this would help you.