Добавлен пример с выгрузкой программы МК в флеш
This commit is contained in:
@@ -59,6 +59,7 @@ void SystemClock_Config(void);
|
||||
W25_HandleTypeDef hw25;
|
||||
HAL_StatusTypeDef W25_RES;
|
||||
W25_WriteInitTypeDef writeInit;
|
||||
W25_WriteInitTypeDef MCUFlashToExternalFlashInit;
|
||||
|
||||
uint8_t read_buff[20] = {0};
|
||||
uint8_t write_buff[20] = {0x14,0x13,0x12,0x11,0x10,
|
||||
@@ -110,32 +111,44 @@ int main(void)
|
||||
hw25.GPIOs.MISO_PIN = GPIO_PIN_2;
|
||||
hw25.GPIOs.MOSI_PIN = GPIO_PIN_3;
|
||||
W25_Base_Init(&hw25);
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
|
||||
// Example for FLASH: using manufactire info CMD
|
||||
uint32_t w25_ID = W25_CMD_Read_JEDEC_ID(&hw25);
|
||||
uint64_t w25_unique_ID = W25_CMD_Read_Device_ID(&hw25);
|
||||
|
||||
// Example for FLASH: erase/program/read functions
|
||||
W25_RES = W25_FLASH_Erase_Sector(&hw25, 0, 1000);
|
||||
W25_RES = W25_FLASH_Program_Area(&hw25, 0xf9, write_buff, 15, 100);
|
||||
W25_CMD_Read_Data(&hw25, 0xf9, read_buff, 15);
|
||||
|
||||
// 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
|
||||
writeInit.fSavePrevoisData = 1;
|
||||
writeInit.pDataPtr = write_buff;
|
||||
writeInit.Data_Address = 0xfb;
|
||||
writeInit.Data_Size = 1;
|
||||
writeInit.Sector_Address = 0xf9;
|
||||
writeInit.Sector_Size = 15;
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
// Example for FLASH: using manufactire info CMD
|
||||
uint32_t w25_ID = W25_CMD_Read_JEDEC_ID(&hw25);
|
||||
uint64_t w25_unique_ID = W25_CMD_Read_Device_ID(&hw25);
|
||||
|
||||
// Example fpr FLASH: writting MCU Program to external FLASH
|
||||
MCUFlashToExternalFlashInit.pDataPtr = (uint8_t *)FLASH_BASE;
|
||||
MCUFlashToExternalFlashInit.Data_Address = 0;
|
||||
MCUFlashToExternalFlashInit.Data_Size = 0x2000;
|
||||
MCUFlashToExternalFlashInit.Sector_Address = 0;
|
||||
MCUFlashToExternalFlashInit.Sector_Size = 0x2000;
|
||||
W25_RES = W25_FLASH_Write(&hw25, &MCUFlashToExternalFlashInit, 5000);
|
||||
uint32_t FLASH_shift = 0;
|
||||
W25_RES = W25_FLASH_Read(&hw25, 0x0000+FLASH_shift, read_buff, 15, 100);
|
||||
|
||||
// Example for FLASH: erase/program/read functions
|
||||
W25_RES = W25_FLASH_Erase(&hw25, 0, 1, 1000);
|
||||
W25_RES = W25_FLASH_Program(&hw25, 0xf9, write_buff, 15, 100);
|
||||
W25_RES = W25_FLASH_Read(&hw25, 0xf9, read_buff, 15, 100);
|
||||
while (1)
|
||||
{
|
||||
{
|
||||
|
||||
// Example for FLASH: write area functions
|
||||
W25_FLASH_Write_Area(&hw25, &writeInit, 1000);
|
||||
HAL_Delay(10);
|
||||
W25_CMD_Read_Data(&hw25, 0xf9, read_buff, 15);
|
||||
W25_RES = W25_FLASH_Write(&hw25, &writeInit, 1000);
|
||||
W25_RES = W25_FLASH_Read(&hw25, 0xf9, read_buff, 15, 100);
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
@@ -144,6 +157,7 @@ int main(void)
|
||||
uint32_t generated_rng;
|
||||
HAL_RNG_GenerateRandomNumber(&hrng, &generated_rng);
|
||||
write_buff[7] = generated_rng&0xFF;
|
||||
write_buff[0] = (generated_rng>>16)&0xFF;
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user