Чуть структурирован проект example
This commit is contained in:
@@ -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 */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user