From 6542bb4fff3ed24061d45695f296e119622198bc Mon Sep 17 00:00:00 2001 From: alexey Date: Tue, 13 Aug 2024 14:57:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A7=D1=83=D1=82=D1=8C=20=D1=81=D1=82=D1=80?= =?UTF-8?q?=D1=83=D0=BA=D1=82=D1=83=D1=80=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CubeKeil Example/Core/Src/main.c | 63 ++++++++++--------- .../MDK-ARM/flash eeprom Example.uvoptx | 43 +++++++++---- 2 files changed, 67 insertions(+), 39 deletions(-) diff --git a/CubeKeil Example/Core/Src/main.c b/CubeKeil Example/Core/Src/main.c index 684acfd..1c215d0 100644 --- a/CubeKeil Example/Core/Src/main.c +++ b/CubeKeil Example/Core/Src/main.c @@ -61,11 +61,18 @@ HAL_StatusTypeDef MEMSPI_RES; MEMSPI_WriteInitTypeDef writeInit; MEMSPI_WriteInitTypeDef MCUFlashToExternalFlashInit; +// buff to read uint8_t read_buff[20] = {0}; +// what writting in examples in while(1) uint8_t write_buff[20] = {0x14,0x13,0x12,0x11,0x10, 0x0F,0x0E,0x0D,0x0C,0x0B, 0x0A,0x09,0x08,0x07,0x06, 0x05,0x04,0x03,0x02,0x01}; + +uint32_t FLASH_write = 0; // where start writting (except MCU App - MCU App writing on 0x0) +uint32_t FLASH_mcu_size = 0x2000; // how many bytes from app write to flash +uint32_t FLASH_read = 0x100; // where read +uint32_t Timeout = 1000; // timeout for examples in while(1) /* USER CODE END 0 */ /** @@ -111,9 +118,17 @@ int main(void) hmemspi.GPIOs.MOSI_GPIOx = GPIOC; hmemspi.GPIOs.MOSI_PIN = GPIO_PIN_3; MEMSPI_Base_Init(&hmemspi); - // Example for FLASH: write area functions init - // writting on two pages: - // writing 15 bytes at 0xf9 - its writting 7 bytes at first page, and 8 bytes at second page + + /* USER CODE END 2 */ + + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ + + // Example for FLASH: using manufactire info CMD + uint32_t memspi_ID = MEMSPI_CMD_Read_JEDEC_ID(&hmemspi, 100); + uint64_t memspi_unique_ID = MEMSPI_CMD_Read_Device_ID(&hmemspi, 100); +#ifdef EXT_FLASH + // Example fpr FLASH: writting MCU Program to external FLASH writeInit.fSavePrevoisData = 1; writeInit.pDataPtr = write_buff; writeInit.Data_Address = 0xfb; @@ -121,46 +136,38 @@ int main(void) writeInit.Sector_Address = 0xf9; writeInit.Sector_Size = 15; - /* USER CODE END 2 */ - - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ - // Example for FLASH/EPROM: using manufactire info CMD - uint32_t memspi_ID = MEMSPI_CMD_Read_JEDEC_ID(&hmemspi, 100); - uint64_t memspi_unique_ID = MEMSPI_CMD_Read_Device_ID(&hmemspi, 100); - -#ifdef EXT_FLASH - // Example fpr FLASH: writting MCU Program to external FLASH MCUFlashToExternalFlashInit.pDataPtr = (uint8_t *)FLASH_BASE; MCUFlashToExternalFlashInit.Data_Address = 0; - MCUFlashToExternalFlashInit.Data_Size = 0x2000; + MCUFlashToExternalFlashInit.Data_Size = FLASH_mcu_size; MCUFlashToExternalFlashInit.Sector_Address = 0; - MCUFlashToExternalFlashInit.Sector_Size = 0x2000; - MEMSPI_RES = MEMSPI_FLASH_Write(&hmemspi, &MCUFlashToExternalFlashInit, 5000); - uint32_t FLASH_shift = 0; - MEMSPI_RES = MEMSPI_Read_Memory(&hmemspi, 0x0000+FLASH_shift, read_buff, 15, 100); + MCUFlashToExternalFlashInit.Sector_Size = FLASH_mcu_size; + MEMSPI_RES = MEMSPI_FLASH_Write(&hmemspi, &MCUFlashToExternalFlashInit, 5000, 1); + MEMSPI_RES = MEMSPI_Read_Memory(&hmemspi, FLASH_read, read_buff, 15, 100); // Example for FLASH: erase/program/read functions - MEMSPI_RES = MEMSPI_FLASH_Erase(&hmemspi, 0, 1, 1000); - MEMSPI_RES = MEMSPI_FLASH_Program(&hmemspi, 0xf9, write_buff, 15, 100); + // writting on two pages: + // writing 15 bytes at 0xf9 - its writting 7 bytes at first page, and 8 bytes at second page + MEMSPI_RES = MEMSPI_FLASH_Erase(&hmemspi, 0, 1, 1000, 1); + MEMSPI_RES = MEMSPI_FLASH_Program(&hmemspi, 0xf9, write_buff, 15, 100, 1); MEMSPI_RES = MEMSPI_Read_Memory(&hmemspi, 0xf9, read_buff, 15, 100); #endif #ifdef EXT_EEPROM // Example for EEPROM: writting MCU Program to external EEPROM - MEMSPI_RES = MEMSPI_EEPROM_Write(&hmemspi, 0, (uint8_t *)FLASH_BASE, 0x2000, 2000); - MEMSPI_RES = MEMSPI_Read_Memory(&hmemspi, 0, read_buff, 15, 100); + MEMSPI_RES = MEMSPI_EEPROM_Write(&hmemspi, 0, (uint8_t *)FLASH_BASE, FLASH_mcu_size, 2000, 0); + MEMSPI_RES = MEMSPI_Read_Memory(&hmemspi, FLASH_read, read_buff, 15, 100); + FLASH_read = 0x0; #endif while (1) - { + { #ifdef EXT_FLASH - // Example for FLASH: write area functions - MEMSPI_RES = MEMSPI_FLASH_Write(&hmemspi, &writeInit, 1000); - MEMSPI_RES = MEMSPI_Read_Memory(&hmemspi, 0xf9, read_buff, 15, 100); + // Example for FLASH: write/read functions + MEMSPI_RES = MEMSPI_FLASH_Write(&hmemspi, &writeInit, Timeout, 1); + MEMSPI_RES = MEMSPI_Read_Memory(&hmemspi, 0xf9, read_buff, 15, Timeout); #endif #ifdef EXT_EEPROM // Example for EEPROM: write/read functions - MEMSPI_RES = MEMSPI_EEPROM_Write(&hmemspi, 0xf9, write_buff, 15, 100); - MEMSPI_RES = MEMSPI_Read_Memory(&hmemspi, 0xf9, read_buff, 15, 100); + MEMSPI_RES = MEMSPI_EEPROM_Write(&hmemspi, FLASH_write, write_buff, 15, Timeout, 1); + MEMSPI_RES = MEMSPI_Read_Memory(&hmemspi, 0+FLASH_read, read_buff, 15, Timeout); #endif /* USER CODE END WHILE */ diff --git a/CubeKeil Example/MDK-ARM/flash eeprom Example.uvoptx b/CubeKeil Example/MDK-ARM/flash eeprom Example.uvoptx index f0bd1f9..4b5044c 100644 --- a/CubeKeil Example/MDK-ARM/flash eeprom Example.uvoptx +++ b/CubeKeil Example/MDK-ARM/flash eeprom Example.uvoptx @@ -152,9 +152,9 @@ 0 0 - 150 + 156 1 -
134229526
+
134230216
0 0 0 @@ -163,14 +163,14 @@ 1 ../Core/Src/main.c - \\flash_eeprom_Example\../Core/Src/main.c\150 + \\flash_eeprom_Example\../Core/Src/main.c\156
1 0 - 153 + 160 1 -
134229722
+
134230308
0 0 0 @@ -179,7 +179,23 @@ 1 ../Core/Src/main.c - \\flash_eeprom_Example\../Core/Src/main.c\153 + \\flash_eeprom_Example\../Core/Src/main.c\160 +
+ + 2 + 0 + 169 + 1 +
134230310
+ 0 + 0 + 0 + 0 + 0 + 1 + ../Core/Src/main.c + + \\flash_eeprom_Example\../Core/Src/main.c\169
@@ -216,22 +232,27 @@ 6 1 - writebuff + FLASH_write 7 1 - Timeout + FLASH_mcu_size 8 1 - tickstart + FLASH_read 9 1 - tickstart+Timeout + Timeout + + + 10 + 1 + \\flash_eeprom_Example\../Core/Src/main.c\read_buff @@ -270,7 +291,7 @@ 1 0 - 0x08000000 + 0x08001532 0