]> git.sur5r.net Git - freertos/blobdiff - Demo/CORTEX_STM32F103_GCC_Rowley/main.c
Add in a basic USART driver and echo test task.
[freertos] / Demo / CORTEX_STM32F103_GCC_Rowley / main.c
index ba3761bc4b5cbb18dfddd51a7ce4e8dafe6a27ec..fda7808112887bb07f001b2b9ce9b0ae6ba82fca 100644 (file)
  * In addition to the standard demo tasks, the following tasks and tests are\r
  * defined and/or created within this file:\r
  *\r
- * "Check" task -  This only executes every five seconds but has the highest\r
+ * "Check" task - This only executes every five seconds but has the highest\r
  * priority so is guaranteed to get processor time.  Its main function is to \r
  * check that all the standard demo tasks are still operational. The check task\r
- * will toggle LED 7 (PB15) every five seconds so long as no errors have been\r
+ * will toggle LED 3 (PB11) every five seconds so long as no errors have been\r
  * detected.  The toggle rate will increase to half a second if an error has \r
  * been found in any task.\r
  *\r
+ * "Echo" task - This is a very basic task that simply echoes any characters \r
+ * received on COM0 (USART1).  This can be tested by transmitting a text file\r
+ * from a dumb terminal to the STM32 USART.\r
  */\r
 \r
 /* Standard includes. */\r
-#include <stdio.h>\r
+#include <string.h>\r
 \r
 /* Scheduler includes. */\r
 #include "FreeRTOS.h"\r
 #include "task.h"\r
 #include "queue.h"\r
-#include "semphr.h"\r
 \r
 /* Library includes. */\r
 #include "stm32f10x_it.h"\r
-#include "stm32f10x_tim.h"\r
 \r
 /* Demo app includes. */\r
 #include "BlockQ.h"\r
@@ -93,6 +94,9 @@
 #include "QPeek.h"\r
 #include "recmutex.h"\r
 \r
+/* Driver includes. */\r
+#include "STM32_USART.h"\r
+\r
 \r
 /* The time between cycles of the 'check' task - which depends on whether the\r
 check task has detected an error or not. */\r
@@ -107,9 +111,14 @@ check task has detected an error or not. */
 #define mainBLOCK_Q_PRIORITY                           ( tskIDLE_PRIORITY + 2 )\r
 #define mainCHECK_TASK_PRIORITY                                ( tskIDLE_PRIORITY + 3 )\r
 #define mainFLASH_TASK_PRIORITY                                ( tskIDLE_PRIORITY + 2 )\r
+#define mainECHO_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 1 )\r
 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
 #define mainGEN_QUEUE_TASK_PRIORITY                    ( tskIDLE_PRIORITY )\r
 \r
+/* COM port and baud rate used by the echo task. */\r
+#define mainCOM0                                                       ( 0 )\r
+#define mainBAUD_RATE                                          ( 115200 )\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
@@ -120,6 +129,10 @@ static void prvSetupHardware( void );
 /* The 'check' task as described at the top of this file. */\r
 static void prvCheckTask( void *pvParameters );\r
 \r
+/* A simple task that echoes all the characters that are received on COM0 \r
+(USART1). */\r
+static void prvUSARTEchoTask( void *pvParameters );\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 int main( void )\r
@@ -141,7 +154,10 @@ int main( void )
     vStartQueuePeekTasks();\r
     vStartRecursiveMutexTasks();\r
 \r
-       /* Create the 'check' task, which is defined within this file. */\r
+       /* Create the 'echo' task, which is also defined within this file. */\r
+       xTaskCreate( prvUSARTEchoTask, ( signed char * ) "Echo", configMINIMAL_STACK_SIZE, NULL, mainECHO_TASK_PRIORITY, NULL );\r
+\r
+       /* Create the 'check' task, which is also defined within this file. */\r
        xTaskCreate( prvCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
 \r
     /* Start the scheduler. */\r
@@ -153,6 +169,7 @@ int main( void )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+/* Described at the top of this file. */\r
 static void prvCheckTask( void *pvParameters )\r
 {\r
 portTickType xLastExecutionTime;\r
@@ -204,6 +221,49 @@ unsigned long ulTicksToWait = mainCHECK_DELAY_NO_ERROR;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+/* Described at the top of this file. */\r
+static void prvUSARTEchoTask( void *pvParameters )\r
+{\r
+signed char cChar;\r
+\r
+/* String declared static to ensure it does not end up on the stack, no matter\r
+what the optimisation level. */\r
+static const char *pcLongishString = \r
+"ABBA was a Swedish pop music group formed in Stockholm in 1972, consisting of Anni-Frid Frida Lyngstad, "\r
+"Björn Ulvaeus, Benny Andersson and Agnetha Fältskog. Throughout the band's existence, Fältskog and Ulvaeus "\r
+"were a married couple, as were Lyngstad and Andersson - although both couples later divorced. They became one "\r
+"of the most commercially successful acts in the history of popular music, and they topped the charts worldwide "\r
+"from 1972 to 1983.  ABBA gained international popularity employing catchy song hooks, simple lyrics, sound "\r
+"effects (reverb, phasing) and a Wall of Sound achieved by overdubbing the female singers' voices in multiple "\r
+"harmonies. As their popularity grew, they were sought after to tour Europe, Australia, and North America, drawing "\r
+"crowds of ardent fans, notably in Australia. Touring became a contentious issue, being particularly cumbersome for "\r
+"Fältskog, but they continued to release studio albums to widespread commercial success. At the height of their "\r
+"popularity, however, both relationships began suffering strain that led ultimately to the collapse of first the "\r
+"Ulvaeus-Fältskog marriage (in 1979) and then of the Andersson-Lyngstad marriage in 1981. In the late 1970s and early "\r
+"1980s these relationship changes began manifesting in the group's music, as they produced more thoughtful, "\r
+"introspective lyrics with different compositions.";\r
+\r
+       /* Just to avoid compiler warnings. */\r
+       ( void ) pvParameters;\r
+\r
+       /* Initialise COM0, which is USART1 according to the STM32 libraries. */\r
+       lCOMPortInit( mainCOM0, mainBAUD_RATE );\r
+\r
+       /* Try sending out a string all in one go, as a very basic test of the\r
+    lSerialPutString() function. */\r
+    lSerialPutString( mainCOM0, pcLongishString, strlen( pcLongishString ) );\r
+\r
+       for( ;; )\r
+       {\r
+               /* Block to wait for a character to be received on COM0. */\r
+               xSerialGetChar( mainCOM0, &cChar, portMAX_DELAY );\r
+\r
+               /* Write the received character back to COM0. */\r
+               xSerialPutChar( mainCOM0, cChar, 0 );\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 static void prvSetupHardware( void )\r
 {\r
        /* RCC system reset(for debug purpose). */\r
@@ -262,9 +322,6 @@ static void prvSetupHardware( void )
 \r
        /* SPI2 Periph clock enable */\r
        RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE );\r
-\r
-       /* Initialize the SPI FLASH driver */\r
-       SPI_FLASH_Init();\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r