learning freertos using pic24 and microsticii 232 comm

gatolen wrote on Monday, January 09, 2017:

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

gatolen wrote on Monday, January 09, 2017:

thats vPrintString() oops

rtel wrote on Monday, January 09, 2017:

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?

gatolen wrote on Monday, January 09, 2017:

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

rtel wrote on Monday, January 09, 2017:

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.

gatolen wrote on Friday, January 13, 2017:

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

rtel wrote on Friday, January 13, 2017:

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()
{
init_uart();
for( ;; )
{
send_character_to_uart( “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 my_uart_task( void *pvParameters )
{
for( ;; )
{
send_character_to_uart( “a” );
}
}

is the character still being transmitted?

rtel wrote on Friday, January 13, 2017:

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”.

gatolen wrote on Sunday, January 15, 2017:

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 send_character_to_uart(“a”) but i don’t have its definition so it would not compile. So i did

char *testuart; //declared pointer
testuart = “testing now\n”; \ assigned string literal to pointer
for( ; ; )
{
printf(testuart); \use printf to print string pointed to
}

It printed fine. Did as you said and xTaskCreate(my_uart_ask, …)
with for loop and printed fine. Where is the send_character_to_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

rtel wrote on Sunday, January 15, 2017:

the main(). I did your suggested send_character_to_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 now\n”; \ assigned string literal to pointer
for( ; ; )
{
printf(testuart); \use printf to print string pointed to
}

It printed fine. Did as you said and xTaskCreate(my_uart_ask, …)
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 send_character_to_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)

gatolen wrote on Sunday, January 15, 2017:

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
pdMS_TO_TICKS() 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

tlafleur wrote on Sunday, January 15, 2017:

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

tlafleur wrote on Sunday, January 15, 2017:

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-

gatolen wrote on Sunday, January 15, 2017:

Hi, I tested my interrupt tick time by not using my pdMS_TO_TICKS() but inserted just 1000 for the ticks, 1 second, it works. Right now I have my vTaskDelayUntil() going with the 2nd pram pdMS_TO_TICKS(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

gatolen wrote on Monday, January 16, 2017:

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

gatolen wrote on Thursday, January 19, 2017:

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

rtel wrote on Thursday, January 19, 2017:

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

gatolen wrote on Friday, January 20, 2017:

Thanks, found it.

gatolen wrote on Friday, January 20, 2017:

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

rtel wrote on Friday, January 20, 2017:

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 portKERNEL_INTERRUPT_PRIORITY, 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.