From 81b7377f1b3d2820dc2aacf48ffd85febfcdd823 Mon Sep 17 00:00:00 2001 From: L-diy Date: Mon, 13 Nov 2023 13:29:36 +0100 Subject: [PATCH] Init qspi flash --- project/Core/Src/main.c | 157 +++------------------------------ project/STM32F746NGHX_FLASH.ld | 6 ++ 2 files changed, 17 insertions(+), 146 deletions(-) diff --git a/project/Core/Src/main.c b/project/Core/Src/main.c index 6af0c87..914ceff 100644 --- a/project/Core/Src/main.c +++ b/project/Core/Src/main.c @@ -23,9 +23,10 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #define LOGGER_LEVEL_ALL +#include "../../Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_qspi.h" +#include "../../Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_lcd.h" #include "log.h" #include "llfs.h" -#include "../../Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_lcd.h" #include "lcd_api.h" /* USER CODE END Includes */ @@ -113,154 +114,18 @@ int main(void) MX_LWIP_Init(); MX_QUADSPI_Init(); /* USER CODE BEGIN 2 */ + + /* Initialize QSPI */ + BSP_QSPI_Init(); + BSP_QSPI_MemoryMappedMode(); + WRITE_REG(QUADSPI->LPTR, 0xFFF); + + /* Initialize the LCD */ lcd_init(true); - + + /* Initialize the filesystem */ llfs_init(); - - FILE *f = fopen("test.txt", "rw"); - if (f == NULL) { - LOG_INFO(TAG, "File not found test.txt"); - return 1; - } else { - LOG_INFO(TAG, "File found test.txt"); - } - - // Test POSIX file operations - // fgetc - int c; - printf("Printing file:\n"); - while ((c = fgetc(f)) != EOF) { - printf("%c", c); - } - LOG_INFO(TAG, "File printed"); - - // fseek - fseek(f, 0, SEEK_SET); - LOG_INFO(TAG, "File seeked to start"); - - // ftell - long pos = ftell(f); - LOG_INFO(TAG, "File position: %d", pos); - - // fread - char buf[100]; - size_t bytes_read = fread(buf, 1, 100, f); - LOG_INFO(TAG, "Read %d bytes from file", bytes_read); - printf("Read from file:\n"); - for (int i = 0; i < bytes_read; i++) { - printf("%c", buf[i]); - } - - // Rewind the file - LOG_INFO(TAG, "Before File rewinded, pos: %d", ftell(f)); - rewind(f); - LOG_INFO(TAG, "File rewinded, pos: %d", ftell(f)); - - // Get the file size fstat - struct stat st; - fstat(fileno(f), &st); - LOG_INFO(TAG, "File size: %d", st.st_size); - - - // Get a list of all files with the .bmp extension - llfs_file_t file_list[10]; - size_t num_files = llfs_file_list(file_list, 10, "*.bmp"); - LOG_INFO(TAG, "Found %d files with the .bmp extension", num_files); - for (int i = 0; i < num_files; i++) { - LOG_INFO(TAG, "File %d: %s", i, file_list[i].name); - } - - // Get a list of files with .txt or .html - num_files = llfs_file_list(file_list, 10, "*.txt"); - LOG_INFO(TAG, "Found %d files with the .txt or .html extension", num_files); - for (int i = 0; i < num_files; i++) { - LOG_INFO(TAG, "File %d: %s", i, file_list[i].name); - } - - // Loop over all files using the iterator - LOG_INFO(TAG, "Looping over all files, using the iterator"); - void *mem = NULL; - llfs_file_t *file; - while ((file = llfs_next_file(&mem, NULL)) != NULL) { - LOG_INFO(TAG, "File: %s", file->name); - } - - // Loop over all files with the .bmp extension using the iterator - LOG_INFO(TAG, "Looping over all files with the .bmp extension, using the iterator"); - mem = NULL; - while ((file = llfs_next_file(&mem, "*.bmp")) != NULL) { - LOG_INFO(TAG, "File: %s", file->name); - } - - // Get the number of files in the filesystem - size_t num_files_in_fs = llfs_file_count(); - LOG_INFO(TAG, "Number of files in the filesystem: %d", num_files_in_fs); - - - fclose(f); - - // Try opening multiple files - LOG_INFO(TAG, "Opening an closing multiple files"); - FILE * f1 = fopen("test.txt", "rw"); - if (f1 == NULL) { - LOG_INFO(TAG, "File not found f1"); - return 1; - } else { - LOG_INFO(TAG, "File found f1"); - } - // Get the fileno - int fd = fileno(f1); - LOG_INFO(TAG, "File descriptor f1: %d", fd); - - FILE * f2 = fopen("test.txt", "rw"); - if (f2 == NULL) { - LOG_INFO(TAG, "File not found f2"); - return 1; - } else { - LOG_INFO(TAG, "File found f2"); - } - // Get the fileno - fd = fileno(f2); - LOG_INFO(TAG, "File descriptorf2: %d", fd); - - LOG_INFO(TAG, "Closing f1"); - fclose(f1); - - FILE * f3 = fopen("test.txt", "rw"); - if (f3 == NULL) { - LOG_INFO(TAG, "File not found f3"); - return 1; - } else { - LOG_INFO(TAG, "File found f3"); - } - // Get the fileno - fd = fileno(f3); - LOG_INFO(TAG, "File descriptor f3: %d", fd); - - LOG_INFO(TAG, "Closing f2"); - fclose(f2); - - LOG_INFO(TAG, "Closing f3"); - fclose(f3); - - // Try opening a file multiple times, until it fails - int i = 0; - LOG_INFO(TAG, "Opening a file multiple times, until it fails"); - while (1) { - f = fopen("test.txt", "rw"); - LOG_INFO(TAG, "File descriptor: %d", fileno(f)); - if (f == NULL) { - LOG_INFO(TAG, "File not found test.txt"); - break; - } else { - LOG_INFO(TAG, "File found test.txt"); - } - i++; - } - LOG_INFO(TAG, "File opened %d times", i); - - /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ diff --git a/project/STM32F746NGHX_FLASH.ld b/project/STM32F746NGHX_FLASH.ld index 61cd040..db0038e 100644 --- a/project/STM32F746NGHX_FLASH.ld +++ b/project/STM32F746NGHX_FLASH.ld @@ -46,6 +46,7 @@ MEMORY { RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K + QSPI (xrw) : ORIGIN = 0x90000000, LENGTH = 16M } /* Sections */ @@ -182,4 +183,9 @@ SECTIONS } .ARM.attributes 0 : { *(.ARM.attributes) } + + .ext_qspi_flash : + { + *(.ext_qspi_flash) + } >QSPI }