learning freertos using pic24 and microsticii 232 comm

Hi, could use help in making my pic24 and microstickii 232 com. I have followed the manual for FreeRTOS and the EX16 BOARD. I have been able to get my micrstickii with p24fj64gb002 working with the single led showing my scheduler working with simple delays. I would like to be able to use the demo programs in the manual with the ability for vPrintSprint() to give the needed feed back which helps affirm I have the understanding of the exercises. I can see how great FreeRTOS will be when i can understand it better, very fun. If anyone can give me a few pointers it would be greatly appreciated. Thank You very much, Lenj

learning freertos using pic24 and microsticii 232 comm

thats vPrintString() oops

learning freertos using pic24 and microsticii 232 comm

vPrintString() just outputs text. What is available on your hardware for text output? For example, is there a UART, or a USB CDC (virtual COM port) port, or something else?

learning freertos using pic24 and microsticii 232 comm

I have UART1. In the EX16 demo UART2 is used with the predefined pins connected to U2RX and U2TX. I added in the user init() my remapped pins UIRX pin RB10(RP10), and U1TX pin RB11(RP11) and also added the U1MODE and U1STA regs to try to get the com running. I believe that the regs should be under control of the FreeRTOS but i thought maybe this would work. Thank You so much for replying. I donated to SourceForge once for RealTerm but as I get my training moving forward on FreeRTOS I’ll donate again for this wonderful tool. Len

learning freertos using pic24 and microsticii 232 comm

FreeRTOS won’t know about those registers or your hardware, so as long as you can get characters out of the port you have available you can implement vPrintString() to use that port. You need to be careful about thread safety though. The simple thing to do would be to lock the scheduler while the UART was being used, so only one task can use the UART at a time – however if you are using a low baud rate that simple technique might not be practical because of the transmit time – in which case you could add strings to a circular buffer and transmit the strings asynchronously using an interrupt. That way a critical section can be used just to cover the time taken to copy the strings into the circular buffer.

learning freertos using pic24 and microsticii 232 comm

Thank you very much for your reply. I have tried to recieve from the rtos but i must be missing something. In the my init hardware function I put the details for my microstickii hook up(remap ports and U1MODE , U1STA, BRG) which values I have used with just the chip and my com worked fine. The last command for the UART1 is to enable it. Am I doing this right in the init() for hardware setup? I was able to setup my TRIS and PORT reg there to use the led flash scheduler delay functions. It seems like the UART1 may not be chosen by the FreeRTOS. I went through the serial.c file for the EX16 board and changed all the UART2 reg values to UART1 which would get the FreeRTOS looking at the UART1. Is there any other file that would effect which UART is being used? Again your help is very much appreciated, Len

learning freertos using pic24 and microsticii 232 comm

Forget the RTOS at the moment. It has no knowledge of the UART. From your post it sounds like the UART is working when you have an application that is not using the UART. Can you confirm that? So you have something like this pseudo code: main() { inituart(); for( ;; ) { sendcharactertouart( “a” ); } } …and the characters can be seen to be output. If so, then do example the same but in an RTOS task: main() { init_uart();
 xTaskCreate( my_uart_task, ...... );
 vTaskStartScheduler();
} void myuarttask( void *pvParameters ) { for( ;; ) { send_character_to_uart( “a” ); } } is the character still being transmitted?

learning freertos using pic24 and microsticii 232 comm

Correction:
From your post it sounds like the UART is working when you have an application that is not using the UART
Should read “…not using the RTOS”.

learning freertos using pic24 and microsticii 232 comm

Okay, I first did a complete config for my chip in its own configpic24() Which I added its prototype on the top of the demo. I defined it below the main(). I did your suggested sendcharacterto_uart(“a”) but i don’t have its definition so it would not compile. So i did char *testuart; //declared pointer testuart = “testing nown”; \ assigned string literal to pointer for( ; ; ) { printf(testuart); \use printf to print string pointed to } It printed fine. Did as you said and xTaskCreate(myuartask, ….) with for loop and printed fine. Where is the sendcharacterto_uart defined? I have the vPrintString() defined so should also work. How much hardware config does the FreeRTOS have and how do I modify it to meet my microstickii needs? I maybe wrong but i thought most of the config was in the FreeRTOS. I was lead to your FreeRTOS by going to the Microchip website. I also downloaded the Visual Studio IDE to help my training in FreeRTOS but am confused how to use it with your examples in the book. I get the files opened in the editor but it I dont find how to run the GCC compiler and then if it compiles how to run the example. Is this a function of te command prompt? What would you suggest i read as a little above novice programer to start working your examples. REALLY GOING TO HAVE FUN with FreeRTOS. I will have questions I know but now I can follow your book examples better. Thank you so much for your help. Len

learning freertos using pic24 and microsticii 232 comm

the main(). I did your suggested sendcharacterto_uart(“a”) but i don’t have its definition so it would not compile. So i did
It is pseudo code, intended to describe what I’m suggesting you do. It is not a function that actually exists.
char *testuart; //declared pointer testuart = “testing nown”; assigned string literal to pointer for( ; ; ) { printf(testuart); use printf to print string pointed to } It printed fine. Did as you said and xTaskCreate(myuartask, ….) with for loop and printed fine.
So the characters are being output from your UART both with and without the RTOS running? You need to be careful with how printf() is implemented. Some implementations are very stack hungry, can bring in all floating point libraries bloating your code massively, and are almost never thread safe. For something as simple as sending fixed strings it is best to write to the UART directly (send characters to the UART regsiters directly) rather than indirectly using printf.
Where is the sendcharacterto_uart defined?
As above, it doesn’t exist, which is why I said it was pseudo code, so you wouldn’t think it did exist.
I have the vPrintString() defined so should also work.
Going back to the start of this thread. You have to provide an implementation of vPrintString() that works for your application. Now you have characters being output from the UART you can go ahead and implement vPrintString() to call your printf() function … >>>>BUT<<<< note all the other advice in this thread such as it is better NOT to use printf() but write to the UART directly, copy other implementations of vPrintString() to ensure it is FAST AND THREAD SAFE, etc.
How much hardware config does the FreeRTOS have and how do I modify it to meet my microstickii needs?
Please read and re-read this thread and take note of what is being said, all I can do is keep repeating myself. FreeRTOS does nothing with the peripherals on your hardware other than the clock used to generate the tick interrupt. I maybe wrong but i thought most of the
config was in the FreeRTOS.
Yep, you were wrong, it has been mentioned once or twice ;o)

learning freertos using pic24 and microsticii 232 comm

Thank you for your reply. Yes both with FreeRTOS and without I get my output. Ill study on to write directly to the uart regs and modify how i send and receive. Being a training programer some of my questions may seem simplistic in nature to you and forgive me for that but everyone goes through these steps I believe. One more question, setting my uart BRG with my Fcy of 16Mz @ 19200 gave me BRG = 51. This works fine the terminal prints. So my chip is producing 16Mz. When I use a vTaskDelay() or vTaskDelayUntil() utilizing the pdMSTOTICKS() I find my delays are way off. The tick interrupt period should be 1ms . How do I confirm this and if it is not correct how would i correct it? Thanks again for your time. Len

learning freertos using pic24 and microsticii 232 comm

You may want to look here for more info on serial ports for dsPic and PIC24 https://interactive.freertos.org/hc/en-us/community/posts/210026586-dsPIC-PIC24-two-port-serial-drivers https://interactive.freertos.org/hc/en-us/community/topics/200480206-Microchip tom lafleur

learning freertos using pic24 and microsticii 232 comm

A few more thing… Use a scope or logic analyzer to check tick time… Toggle a pin in the tick interrupt loop and look at it… On baud rate, most UART can tolerate +-10% clock without an issue… Look at the datasheet for the part your using, read the section on UART, lots of info there on baud rate. ​FreeRTOS run very well on dsPIC33 and PIC24 without the ​EDS memory, and works well with it if you careful on using it. https://interactive.freertos.org/hc/en-us/community/posts/210026846-FreeRTOS-V8-2-0-port-for-ALL-16-bit-PICs-with-hardware-stack-checking-SPLIM-

learning freertos using pic24 and microsticii 232 comm

Hi, I tested my interrupt tick time by not using my pdMSTOTICKS() but inserted just 1000 for the ticks, 1 second, it works. Right now I have my vTaskDelayUntil() going with the 2nd pram pdMSTOTICKS(100000 * 15) and I have roughly 1 second delay. With the vTaskDelay() same pram same 1 second. When downloading the drivers only the dspPIC serialdrivers opened, the other 2 my zip could not open them. Thank you ver much, Len

learning freertos using pic24 and microsticii 232 comm

Found that projdefs.h was not in demo delays works fine now.

learning freertos using pic24 and microsticii 232 comm

Hi again, Finding my way through the book. Wonderfully written and now that i downloaded the ref man, again wonderfully written, I can answer most of my questions. I am studying interrupt semaphores exam 16 but can’t find sema.h file. I can find the individual files but when i look for the sema.h file in the includes for my port it is not listed. Is that because my port does not need it? Thanks for attending to these simple questions of mine. Thank You for your time, Len

learning freertos using pic24 and microsticii 232 comm

The file is called semphr.h and its in FreeRTOS/source/include (in the main download at least).

learning freertos using pic24 and microsticii 232 comm

Thanks, found it.

learning freertos using pic24 and microsticii 232 comm

Hi again, looking for yield from ISR but only found portYIELD(). Is this ISR safe for my port? Thanks

learning freertos using pic24 and microsticii 232 comm

From the following page: http://www.freertos.org/portpic24_dspic.html “Interrupt service routines that cannot cause a context switch have no special requirements and can be written as per the compiler documentation. Interrupt service routines that can cause a context switch must execute with priority portKERNELINTERRUPTPRIORITY, and only call taskYIELD() at the very end of the service routine after the interrupt source has been cleared. See the file serial.c included in the demo application for an example.” taskYIELD() and portYIELD() being the same thing – one calls the other. So the call needs to be at the very end of the ISR. The main FreeRTOS download contains example ISRs that you can use as a reference.

learning freertos using pic24 and microsticii 232 comm

Thank you, Is configKERNELINTERRUPTPRIORITY0x01 the same, I seem not to be able to find portKERNELINTERRUPTPRIORITY.

learning freertos using pic24 and microsticii 232 comm

Is there a macro in the portmacro.h for this?

learning freertos using pic24 and microsticii 232 comm

You have the file, open it up and have a look.

learning freertos using pic24 and microsticii 232 comm

Looked but not there. I assume it is used for the interrupts for my port. I was able to get example 16 working good using a 32bit timer and setting the IP to configKernalPriority +1. Iam still using vPrintString() until i grasp how to use the serial driver. Works okay for now. When i try to use the daemon task though the interrupt timing was good but the use of the vPrintString() comes up not right probably due to the use of the print functions. Now I am on example 18 using the daemon task again but now in my ISR for TMR3 Interrupt the xTimerPendFunctionCallFromISR() is used, errors seems to tell me to add the MPU_wrappers.h and .c files. They must be used for my Chip. I add them which makes most of the errors go away but I am left with the xPortRaisePrivilege(). I try to find the definition must be looking in the wrong area the portable.h does not have it. Your help is greatly appreciated. Len

learning freertos using pic24 and microsticii 232 comm

I found my mistake, I was unaware of the need to configTimerPend FunctionCallFromISR() in FreeRTOSConfig.h. Working fine. Does portYIELD() use xHigherPriorityTaskWoken? Thanks

learning freertos using pic24 and microsticii 232 comm

Does portYIELD() use xHigherPriorityTaskWoken? Thanks
Not that I recall. The PIC24 port is older and I think you have to test xHigherPriorityTaskWoken manually before calling portYIELD(). Refer to the examples in the main FreeRTOS download.

learning freertos using pic24 and microsticii 232 comm

Going on to Example 19. Trying to use Queues with ISR put in the example and git alot of compiler warnings dealing with stdio.h files. They seem to deal with yvals.h . My stdio.h are lega-c includes from microchip. Havnt ever delt with these. Most be something dealing with the book example and my chip. Any suggestions would be greatful to understand this. Len

learning freertos using pic24 and microsticii 232 comm

Are you use the C files from the examples for the Win32 code (from the Mastering the FreeRTOS Real Time Kernel book, rather than the “Using the …” book)? I’m not sure why there would be any difference with how stdio was used in example 16 compared to others. I just looked at the file and it doesn’t seem to be used at all.

learning freertos using pic24 and microsticii 232 comm

I think it is used in the vPrintString() call where printf() is called.

learning freertos using pic24 and microsticii 232 comm

Why is that different for that particular example though? I think the print string function should be the same for all the examples. Or is that example also printing out a number, in addition to the string?

learning freertos using pic24 and microsticii 232 comm

My reply just got errased. I’ll start again. Found my problem and now able to get exampe 19 to compile. Would not run. I found that by commenting out the vStringPrinter task it would run. Looking into the while loop in the vStringPrinter the xQueuReceive task seems not to see the xStringQueue to have anything in it. I moved my attention to the ISR and put in a vPrintString(pcStrings[ulReceivedNumber] after theXQueueSendToBackFromISR() and ran it keeping the vStringPointer task commented out, gave me the strings printed as it should be. I must have something not quite right with my xQueueSendToBackFromISR() or theQueueReceive() did not receive from the ISR. Any thoughts? Thank you for your patience. Also I have been studying the serial.c and serial.h and would like to try and use them in a test example maybe just an echo program. Does any of the other ports have something simple for me to work with. Well again Thank you . Len

learning freertos using pic24 and microsticii 232 comm

correction that’s the for loop in the vStringPrinter task which i beleive is where the program stalls.

learning freertos using pic24 and microsticii 232 comm

After looking further my led is blinking the interrupt but my vStringPrinter stops all my messages. Moving on to understanding the serial .h and .c files for example teh xSerialGetChar(xComportHandle pxPort, signed char pcRxedChar, TickType_t xBlockTime) :: looking at the xComportHandle pxPort variable xComportHandle is typdef void *xComPortHandle this means to me that the varable pxPort now is typedef something to type void . So when I go to call this function instead if the placeholder xComportHandle xPort I would define a variable like xPort MYUART1; then MYUART1 is of type xComPortHandle which is a pointer to void my MYUART1 can be the return of lets say xSerialPortInitMinimal(). With all the casting and typedef it can be quite intense for my level right now is there any guidance to help move me forward. All in all enjoying my learning and looking forward to knowing this program better, Len

learning freertos using pic24 and microsticii 232 comm

I guess I most have lost you somewhere. If you do not want to help me get by this just let me know, Len