Logging and flash filesystem

Goals

Documentation

To complete this assignment, you may need to check the slides discuss in the lectures and the official API documentation:

Logging to UART

Basic logging

Start from your basic (single-task) matrix multiply code (Lab 2). Insert ESP_LOG calls at least at 3 levels: ERROR, INFO and VERBOSE.

Modify logging level via menuconfig

Use menuconfig to select INFO as the minimum log level. Check that the VERBOSE messages are not shown

Multimodule

Create a new .c file in your project. Include there a couple of functions from your code. Remind to declare. a new TAG there. Include LOG macros in both files.

Modify logging level at runtime

Use esp_log_level_set()to set WARNING as the log level for the main file and VERBOSE for the other file. Check that the log output is correct.

Stop and sync

All previous exercises must be finished DURING the lecture (not afterwards) and shown to the teacher during the Zoom meeting. AFTER they are shown to be working during the lecture, the Recorder of the group will send an email with the source code of the last section (Modify logging level at runtime). Remind that plagiarism is strictly prohibited: the code of each group must be solely developed by members of that group.

Mounting FAT filesystem

In this step you will mount a FAT filesystem in a new partition created in the SPI FLASH existing in the board. Follow the example Wear Levelling ( [wear levelling example])https://github.com/espressif/esp-idf/tree/master/examples/storage/wear_levelling) ) and create a PlatformIO project to run it in your board:

Build, upload and execute. Monitor the output and check that the messages are the ones expected.

Questions

Once you finished the code, try to answer the following questions. Include them in the report of this assignment.

  • What is the name of the file you are creating in this example?
  • What is the path of the file? Why? When was that folder created?
  • What is the difference between printf() and fprintf()
  • Why there are two calls to `fopen()? What is the difference between them?
  • What is fgets()doing?
  • Write a code that creates a new file called timestamp.txt whose content is a timestamp (time elapsed since boot). How can we later modify its content?
  • Try to open a file after the call èsp_vfs_fat_spiflash_umount()*. What happens?

Redirecting the log to FLASH (optional)

This assignment is optional, but required if you want to obtain more than 6 / 10 in this assignment.

Starting from your chronometer code (or equivalent), include LOG messages (using ESP_LOG macros) and redirect the log to a file called log.txt that you will create in a FAT partition in SPI FLAG. Use esp_log_set_vprintf() to do the redirection. You should LOG:

Note that you can still use printf() to write to the terminal.

Also, after 1 minute of functioning, you will read the first 5 lines of the log file and write them to the terminal (using printf()).

Homework (Optional)

Once finished, the Speaker will contact me to explain (orally) the code developed