Добавлены проверки на режим прерывания (пока ниче не работает)
This commit is contained in:
@@ -65,14 +65,20 @@ MEMSPI_WriteInitTypeDef MCUFlashToExternalFlashInit;
|
||||
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};
|
||||
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_write = 0x1000; // 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 FLASH_read = 0x1100; // where read
|
||||
uint32_t Timeout = 1000; // timeout for examples in while(1)
|
||||
|
||||
void SPI2_IRQHandler(void)
|
||||
{
|
||||
MEMSPI_Handler(&hmemspi);
|
||||
}
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@@ -107,16 +113,16 @@ int main(void)
|
||||
MX_RNG_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
// FLASH MEMSPI INIT
|
||||
hmemspi.hspi.Instance = SPI2;
|
||||
hmemspi.hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
|
||||
hmemspi.GPIOs.CS_GPIOx = GPIOA;
|
||||
hmemspi.GPIOs.CS_PIN = GPIO_PIN_4;
|
||||
hmemspi.GPIOs.CLK_GPIOx = GPIOB;
|
||||
hmemspi.GPIOs.CLK_PIN = GPIO_PIN_13;
|
||||
hmemspi.GPIOs.MISO_GPIOx = GPIOC;
|
||||
hmemspi.GPIOs.MISO_PIN = GPIO_PIN_2;
|
||||
hmemspi.GPIOs.MOSI_GPIOx = GPIOC;
|
||||
hmemspi.GPIOs.MOSI_PIN = GPIO_PIN_3;
|
||||
hmemspi.sspi.hspi.Instance = SPI2;
|
||||
hmemspi.sspi.hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
|
||||
hmemspi.CS_GPIOx = GPIOA;
|
||||
hmemspi.CS_PIN = GPIO_PIN_4;
|
||||
hmemspi.sspi.CLK_GPIOx = GPIOB;
|
||||
hmemspi.sspi.CLK_PIN = GPIO_PIN_13;
|
||||
hmemspi.sspi.MISO_GPIOx = GPIOB;
|
||||
hmemspi.sspi.MISO_PIN = GPIO_PIN_14;
|
||||
hmemspi.sspi.MOSI_GPIOx = GPIOB;
|
||||
hmemspi.sspi.MOSI_PIN = GPIO_PIN_15;
|
||||
MEMSPI_Base_Init(&hmemspi);
|
||||
|
||||
/* USER CODE END 2 */
|
||||
@@ -124,48 +130,68 @@ int main(void)
|
||||
/* 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;
|
||||
writeInit.Data_Size = 1;
|
||||
writeInit.Sector_Address = 0xf9;
|
||||
writeInit.Sector_Size = 15;
|
||||
// Example for FLASH (interrupt): using manufactire info CMD
|
||||
uint32_t memspi_ID;
|
||||
uint64_t memspi_unique_ID;
|
||||
MEMSPI_CMD_Read_JEDEC_ID_IT(&hmemspi, &memspi_ID);
|
||||
HAL_Delay(100);
|
||||
MEMSPI_CMD_Read_Device_ID_IT(&hmemspi, &memspi_unique_ID);
|
||||
HAL_Delay(100);
|
||||
|
||||
// Example for FLASH (interrupt/blocking): erase/program/read functions
|
||||
// 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, 100);
|
||||
MEMSPI_RES = MEMSPI_FLASH_Program(&hmemspi, 0xf9, write_buff, 15, 100, 1);
|
||||
MEMSPI_RES = MEMSPI_Read_Memory_IT(&hmemspi, 0xf9, read_buff, 15);
|
||||
MEMSPI_WaitOnFlagsUntilTimeout(&hmemspi, MEMSPI_SR_BUSY, 0, NULL, NULL);
|
||||
|
||||
|
||||
// Example for FLASH (blocking): using manufactire info CMD
|
||||
memspi_ID = MEMSPI_CMD_Read_JEDEC_ID(&hmemspi, 100);
|
||||
memspi_unique_ID = MEMSPI_CMD_Read_Device_ID(&hmemspi, 100);
|
||||
MEMSPI_RES = MEMSPI_CMD_Write_Status_Register(&hmemspi, 0, 100);
|
||||
#ifdef EXT_FLASH
|
||||
// Example fpr FLASH (blocking): writting MCU Program to external FLASH
|
||||
MCUFlashToExternalFlashInit.pDataPtr = (uint8_t *)FLASH_BASE;
|
||||
MCUFlashToExternalFlashInit.Data_Address = 0;
|
||||
MCUFlashToExternalFlashInit.Data_Address = FLASH_write;
|
||||
MCUFlashToExternalFlashInit.Data_Size = FLASH_mcu_size;
|
||||
MCUFlashToExternalFlashInit.Sector_Address = 0;
|
||||
MCUFlashToExternalFlashInit.Sector_Address = FLASH_write;
|
||||
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
|
||||
// Example for FLASH (blocking): erase/program/read functions
|
||||
// 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);
|
||||
|
||||
// Example for FLASH (blocking) (while(1)): write/read functions
|
||||
#endif
|
||||
#ifdef EXT_EEPROM
|
||||
// Example for EEPROM: writting MCU Program to external EEPROM
|
||||
MEMSPI_RES = MEMSPI_EEPROM_Write(&hmemspi, 0, (uint8_t *)FLASH_BASE, FLASH_mcu_size, 2000, 0);
|
||||
// Example for EEPROM (blocking): writting MCU Program to external EEPROM
|
||||
MEMSPI_RES = MEMSPI_EEPROM_Write(&hmemspi, FLASH_write, (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)
|
||||
{
|
||||
FLASH_read = FLASH_write;
|
||||
#ifdef EXT_FLASH
|
||||
// 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);
|
||||
// Example for FLASH (blocking): write/read functions
|
||||
writeInit.fSavePrevoisData = 1;
|
||||
writeInit.pDataPtr = write_buff;
|
||||
writeInit.Data_Address = FLASH_write;
|
||||
writeInit.Data_Size = 1;
|
||||
writeInit.Sector_Address = FLASH_write;
|
||||
writeInit.Sector_Size = 15;
|
||||
// MEMSPI_RES = MEMSPI_FLASH_Write(&hmemspi, &writeInit, Timeout, 1);
|
||||
// MEMSPI_RES = MEMSPI_Read_Memory(&hmemspi, FLASH_read, read_buff, 15, Timeout);
|
||||
#endif
|
||||
#ifdef EXT_EEPROM
|
||||
// Example for EEPROM: write/read functions
|
||||
// Example for EEPROM (blocking): write/read functions
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user