Lab 3: Move Application into an RTOS

Step 8: Build and Run the Application


Clean and build your application by clicking on the Main_Rebuild_Project.png Clean and Build Project button.


Program your device with the built application binary by clicking on the Main_Program_Target_Project.png Make and Program Device button.


Now, open the serial terminal application on your computer and connect to the serial port as shown in Figure 3 (Tera Term is used here for reference).

Figure 1: Open USB Serial Port using Tera Term

Note: It is not required to adjust the Baud rate as you are using a USB connection.


Remove the SD card from the IO1 Xplained Pro board.


Press the switch SW1 (the upper one) to start reading the temperature sensor value. The application informs the SD card is not inserted.

Figure 2: Verify the output when SD card is not plugged


Insert the SD card into the microSD slot of the IO1 Xplained Pro board and observe the data are logged into the SD card.

Figure 3: Verify the output when SD card is plugged


Press the switch SW1 again. That will stop the log.


Remove the SD card from the IO1 Xplained Pro board and insert the media to a host machine.
Observe and verify the content of the media drive. It should contain the file dir1/log.txt.

Figure 4: Verify the content of the SD card


Open the file dir1/log.txt in any text editor and observe the temperature sensor values recorded every 10 seconds as expected.

Figure 5: Observe the log.txt


Safely remove the SD card media from the Host machine.
Insert the SD card into the microSD slot of the IO1 Xplained Pro board.
Reset the PIC32 WFI32E Curiosity Board using the MLCR button.
Press the switch SW1 to start the log.

Note: You can find the solution of the Lab 3 in the folder: <your unzipped folder path>\getting_started_pic32_wfi32e\Lab3\solution.


You should be able to verify the temperature logs were successfully recorded into the SD card.


In this lab, you have successfully enhanced the application to run in an RTOS environment. The new application writes the temperature sensor values along with current system time to a file on the SD card using the File System interface. The SDSPI Driver with the SPI2 Peripheral Library was used to perform operations on the SD card. The RTC Peripheral Library was used to get the current system time. The File System service was used to write the current system time along with temperature sensor values received from the Sensor Task to a file created on the SD card using the SDSPI Driver.

Three RTOS Threads were created:

  • I2C sensor application reads the temperature value, notifies the SD card Thread using the SD card message queue, and goes to sleep for 1 second.
  • SD card application is waiting to receive data in the SD card queue. Once the queue is filled, the application logs the temperature value to a file.
  • USB application handles the messages to print on the USB console with the help of another message queue.

In the next lab, you will add an HTTP Web Server to visualize data.


In this lab, you have successfully developed a full-fledged MPLAB Harmony application. This gives you a fair idea of how MPLAB Harmony helps application development. If you need FreeRTOS support for any of your existing applications, this lab can be used as a reference. This can also be a starting point for your IoT applications.

Next Step >

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.