Добавлен пример для SPI EEPROM
This commit is contained in:
@@ -56,10 +56,10 @@ void SystemClock_Config(void);
|
|||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
/* Private user code ---------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN 0 */
|
/* USER CODE BEGIN 0 */
|
||||||
W25_HandleTypeDef hw25;
|
MEMSPI_HandleTypeDef hmemspi;
|
||||||
HAL_StatusTypeDef W25_RES;
|
HAL_StatusTypeDef MEMSPI_RES;
|
||||||
W25_WriteInitTypeDef writeInit;
|
MEMSPI_WriteInitTypeDef writeInit;
|
||||||
W25_WriteInitTypeDef MCUFlashToExternalFlashInit;
|
MEMSPI_WriteInitTypeDef MCUFlashToExternalFlashInit;
|
||||||
|
|
||||||
uint8_t read_buff[20] = {0};
|
uint8_t read_buff[20] = {0};
|
||||||
uint8_t write_buff[20] = {0x14,0x13,0x12,0x11,0x10,
|
uint8_t write_buff[20] = {0x14,0x13,0x12,0x11,0x10,
|
||||||
@@ -99,18 +99,18 @@ int main(void)
|
|||||||
MX_CRC_Init();
|
MX_CRC_Init();
|
||||||
MX_RNG_Init();
|
MX_RNG_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
// FLASH W25 INIT
|
// FLASH MEMSPI INIT
|
||||||
hw25.hspi.Instance = SPI2;
|
hmemspi.hspi.Instance = SPI2;
|
||||||
hw25.hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
|
hmemspi.hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
|
||||||
hw25.GPIOs.CS_GPIOx = GPIOA;
|
hmemspi.GPIOs.CS_GPIOx = GPIOA;
|
||||||
hw25.GPIOs.CLK_GPIOx = GPIOB;
|
hmemspi.GPIOs.CS_PIN = GPIO_PIN_4;
|
||||||
hw25.GPIOs.MISO_GPIOx = GPIOC;
|
hmemspi.GPIOs.CLK_GPIOx = GPIOB;
|
||||||
hw25.GPIOs.MOSI_GPIOx = GPIOC;
|
hmemspi.GPIOs.CLK_PIN = GPIO_PIN_13;
|
||||||
hw25.GPIOs.CS_PIN = GPIO_PIN_4;
|
hmemspi.GPIOs.MISO_GPIOx = GPIOC;
|
||||||
hw25.GPIOs.CLK_PIN = GPIO_PIN_13;
|
hmemspi.GPIOs.MISO_PIN = GPIO_PIN_2;
|
||||||
hw25.GPIOs.MISO_PIN = GPIO_PIN_2;
|
hmemspi.GPIOs.MOSI_GPIOx = GPIOC;
|
||||||
hw25.GPIOs.MOSI_PIN = GPIO_PIN_3;
|
hmemspi.GPIOs.MOSI_PIN = GPIO_PIN_3;
|
||||||
W25_Base_Init(&hw25);
|
MEMSPI_Base_Init(&hmemspi);
|
||||||
// Example for FLASH: write area functions init
|
// Example for FLASH: write area functions init
|
||||||
// writting on two pages:
|
// writting on two pages:
|
||||||
// writing 15 bytes at 0xf9 - its writting 7 bytes at first page, and 8 bytes at second page
|
// writing 15 bytes at 0xf9 - its writting 7 bytes at first page, and 8 bytes at second page
|
||||||
@@ -125,30 +125,43 @@ int main(void)
|
|||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
/* USER CODE BEGIN WHILE */
|
/* USER CODE BEGIN WHILE */
|
||||||
// Example for FLASH: using manufactire info CMD
|
// Example for FLASH/EPROM: using manufactire info CMD
|
||||||
uint32_t w25_ID = W25_CMD_Read_JEDEC_ID(&hw25);
|
uint32_t memspi_ID = MEMSPI_CMD_Read_JEDEC_ID(&hmemspi, 100);
|
||||||
uint64_t w25_unique_ID = W25_CMD_Read_Device_ID(&hw25);
|
uint64_t memspi_unique_ID = MEMSPI_CMD_Read_Device_ID(&hmemspi, 100);
|
||||||
|
|
||||||
|
#ifdef EXT_FLASH
|
||||||
// Example fpr FLASH: writting MCU Program to external FLASH
|
// Example fpr FLASH: writting MCU Program to external FLASH
|
||||||
MCUFlashToExternalFlashInit.pDataPtr = (uint8_t *)FLASH_BASE;
|
MCUFlashToExternalFlashInit.pDataPtr = (uint8_t *)FLASH_BASE;
|
||||||
MCUFlashToExternalFlashInit.Data_Address = 0;
|
MCUFlashToExternalFlashInit.Data_Address = 0;
|
||||||
MCUFlashToExternalFlashInit.Data_Size = 0x2000;
|
MCUFlashToExternalFlashInit.Data_Size = 0x2000;
|
||||||
MCUFlashToExternalFlashInit.Sector_Address = 0;
|
MCUFlashToExternalFlashInit.Sector_Address = 0;
|
||||||
MCUFlashToExternalFlashInit.Sector_Size = 0x2000;
|
MCUFlashToExternalFlashInit.Sector_Size = 0x2000;
|
||||||
W25_RES = W25_FLASH_Write(&hw25, &MCUFlashToExternalFlashInit, 5000);
|
MEMSPI_RES = MEMSPI_FLASH_Write(&hmemspi, &MCUFlashToExternalFlashInit, 5000);
|
||||||
uint32_t FLASH_shift = 0;
|
uint32_t FLASH_shift = 0;
|
||||||
W25_RES = W25_FLASH_Read(&hw25, 0x0000+FLASH_shift, read_buff, 15, 100);
|
MEMSPI_RES = MEMSPI_Read_Memory(&hmemspi, 0x0000+FLASH_shift, read_buff, 15, 100);
|
||||||
|
|
||||||
// Example for FLASH: erase/program/read functions
|
// Example for FLASH: erase/program/read functions
|
||||||
W25_RES = W25_FLASH_Erase(&hw25, 0, 1, 1000);
|
MEMSPI_RES = MEMSPI_FLASH_Erase(&hmemspi, 0, 1, 1000);
|
||||||
W25_RES = W25_FLASH_Program(&hw25, 0xf9, write_buff, 15, 100);
|
MEMSPI_RES = MEMSPI_FLASH_Program(&hmemspi, 0xf9, write_buff, 15, 100);
|
||||||
W25_RES = W25_FLASH_Read(&hw25, 0xf9, read_buff, 15, 100);
|
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);
|
||||||
|
#endif
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
#ifdef EXT_FLASH
|
||||||
// Example for FLASH: write area functions
|
// Example for FLASH: write area functions
|
||||||
W25_RES = W25_FLASH_Write(&hw25, &writeInit, 1000);
|
MEMSPI_RES = MEMSPI_FLASH_Write(&hmemspi, &writeInit, 1000);
|
||||||
W25_RES = W25_FLASH_Read(&hw25, 0xf9, read_buff, 15, 100);
|
MEMSPI_RES = MEMSPI_Read_Memory(&hmemspi, 0xf9, read_buff, 15, 100);
|
||||||
|
#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);
|
||||||
|
#endif
|
||||||
/* USER CODE END WHILE */
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
/* USER CODE BEGIN 3 */
|
||||||
|
|||||||
@@ -152,41 +152,9 @@
|
|||||||
<Bp>
|
<Bp>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
<Type>0</Type>
|
<Type>0</Type>
|
||||||
<LineNumber>140</LineNumber>
|
|
||||||
<EnabledFlag>1</EnabledFlag>
|
|
||||||
<Address>134230654</Address>
|
|
||||||
<ByteObject>0</ByteObject>
|
|
||||||
<HtxType>0</HtxType>
|
|
||||||
<ManyObjects>0</ManyObjects>
|
|
||||||
<SizeOfObject>0</SizeOfObject>
|
|
||||||
<BreakByAccess>0</BreakByAccess>
|
|
||||||
<BreakIfRCount>1</BreakIfRCount>
|
|
||||||
<Filename>../Core/Src/main.c</Filename>
|
|
||||||
<ExecCommand></ExecCommand>
|
|
||||||
<Expression>\\flash_eeprom_Example\../Core/Src/main.c\140</Expression>
|
|
||||||
</Bp>
|
|
||||||
<Bp>
|
|
||||||
<Number>1</Number>
|
|
||||||
<Type>0</Type>
|
|
||||||
<LineNumber>138</LineNumber>
|
|
||||||
<EnabledFlag>1</EnabledFlag>
|
|
||||||
<Address>134230628</Address>
|
|
||||||
<ByteObject>0</ByteObject>
|
|
||||||
<HtxType>0</HtxType>
|
|
||||||
<ManyObjects>0</ManyObjects>
|
|
||||||
<SizeOfObject>0</SizeOfObject>
|
|
||||||
<BreakByAccess>0</BreakByAccess>
|
|
||||||
<BreakIfRCount>1</BreakIfRCount>
|
|
||||||
<Filename>../Core/Src/main.c</Filename>
|
|
||||||
<ExecCommand></ExecCommand>
|
|
||||||
<Expression>\\flash_eeprom_Example\../Core/Src/main.c\138</Expression>
|
|
||||||
</Bp>
|
|
||||||
<Bp>
|
|
||||||
<Number>2</Number>
|
|
||||||
<Type>0</Type>
|
|
||||||
<LineNumber>150</LineNumber>
|
<LineNumber>150</LineNumber>
|
||||||
<EnabledFlag>1</EnabledFlag>
|
<EnabledFlag>1</EnabledFlag>
|
||||||
<Address>134230760</Address>
|
<Address>134229430</Address>
|
||||||
<ByteObject>0</ByteObject>
|
<ByteObject>0</ByteObject>
|
||||||
<HtxType>0</HtxType>
|
<HtxType>0</HtxType>
|
||||||
<ManyObjects>0</ManyObjects>
|
<ManyObjects>0</ManyObjects>
|
||||||
@@ -198,79 +166,47 @@
|
|||||||
<Expression>\\flash_eeprom_Example\../Core/Src/main.c\150</Expression>
|
<Expression>\\flash_eeprom_Example\../Core/Src/main.c\150</Expression>
|
||||||
</Bp>
|
</Bp>
|
||||||
<Bp>
|
<Bp>
|
||||||
<Number>3</Number>
|
<Number>1</Number>
|
||||||
<Type>0</Type>
|
<Type>0</Type>
|
||||||
<LineNumber>198</LineNumber>
|
<LineNumber>153</LineNumber>
|
||||||
<EnabledFlag>1</EnabledFlag>
|
<EnabledFlag>1</EnabledFlag>
|
||||||
<Address>134229880</Address>
|
<Address>134229626</Address>
|
||||||
<ByteObject>0</ByteObject>
|
<ByteObject>0</ByteObject>
|
||||||
<HtxType>0</HtxType>
|
<HtxType>0</HtxType>
|
||||||
<ManyObjects>0</ManyObjects>
|
<ManyObjects>0</ManyObjects>
|
||||||
<SizeOfObject>0</SizeOfObject>
|
<SizeOfObject>0</SizeOfObject>
|
||||||
<BreakByAccess>0</BreakByAccess>
|
<BreakByAccess>0</BreakByAccess>
|
||||||
<BreakIfRCount>1</BreakIfRCount>
|
<BreakIfRCount>1</BreakIfRCount>
|
||||||
<Filename>..\..\spi_flash\spi_flash.c</Filename>
|
<Filename>../Core/Src/main.c</Filename>
|
||||||
<ExecCommand></ExecCommand>
|
<ExecCommand></ExecCommand>
|
||||||
<Expression>\\flash_eeprom_Example\../../spi_flash/spi_flash.c\198</Expression>
|
<Expression>\\flash_eeprom_Example\../Core/Src/main.c\153</Expression>
|
||||||
</Bp>
|
|
||||||
<Bp>
|
|
||||||
<Number>4</Number>
|
|
||||||
<Type>0</Type>
|
|
||||||
<LineNumber>151</LineNumber>
|
|
||||||
<EnabledFlag>1</EnabledFlag>
|
|
||||||
<Address>0</Address>
|
|
||||||
<ByteObject>0</ByteObject>
|
|
||||||
<HtxType>0</HtxType>
|
|
||||||
<ManyObjects>0</ManyObjects>
|
|
||||||
<SizeOfObject>0</SizeOfObject>
|
|
||||||
<BreakByAccess>0</BreakByAccess>
|
|
||||||
<BreakIfRCount>0</BreakIfRCount>
|
|
||||||
<Filename>..\..\spi_flash\spi_flash.c</Filename>
|
|
||||||
<ExecCommand></ExecCommand>
|
|
||||||
<Expression></Expression>
|
|
||||||
</Bp>
|
|
||||||
<Bp>
|
|
||||||
<Number>5</Number>
|
|
||||||
<Type>0</Type>
|
|
||||||
<LineNumber>171</LineNumber>
|
|
||||||
<EnabledFlag>1</EnabledFlag>
|
|
||||||
<Address>0</Address>
|
|
||||||
<ByteObject>0</ByteObject>
|
|
||||||
<HtxType>0</HtxType>
|
|
||||||
<ManyObjects>0</ManyObjects>
|
|
||||||
<SizeOfObject>0</SizeOfObject>
|
|
||||||
<BreakByAccess>0</BreakByAccess>
|
|
||||||
<BreakIfRCount>0</BreakIfRCount>
|
|
||||||
<Filename>..\..\spi_flash\spi_flash.c</Filename>
|
|
||||||
<ExecCommand></ExecCommand>
|
|
||||||
<Expression></Expression>
|
|
||||||
</Bp>
|
</Bp>
|
||||||
</Breakpoint>
|
</Breakpoint>
|
||||||
<WatchWindow1>
|
<WatchWindow1>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>0</count>
|
<count>0</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>hw25</ItemText>
|
<ItemText>hmemspi</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>1</count>
|
<count>1</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>W25_RES</ItemText>
|
<ItemText>memspi_ID</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>2</count>
|
<count>2</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>read_buff</ItemText>
|
<ItemText>MEMSPI_RES</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>3</count>
|
<count>3</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>write_buff</ItemText>
|
<ItemText>read_buff</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>4</count>
|
<count>4</count>
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>sector_buff</ItemText>
|
<ItemText>write_buff</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>5</count>
|
<count>5</count>
|
||||||
@@ -282,6 +218,21 @@
|
|||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>writebuff</ItemText>
|
<ItemText>writebuff</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>7</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>Timeout</ItemText>
|
||||||
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>8</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>tickstart</ItemText>
|
||||||
|
</Ww>
|
||||||
|
<Ww>
|
||||||
|
<count>9</count>
|
||||||
|
<WinNumber>1</WinNumber>
|
||||||
|
<ItemText>tickstart+Timeout</ItemText>
|
||||||
|
</Ww>
|
||||||
</WatchWindow1>
|
</WatchWindow1>
|
||||||
<WatchWindow2>
|
<WatchWindow2>
|
||||||
<Ww>
|
<Ww>
|
||||||
@@ -374,6 +325,18 @@
|
|||||||
<pSingCmdsp></pSingCmdsp>
|
<pSingCmdsp></pSingCmdsp>
|
||||||
<pMultCmdsp></pMultCmdsp>
|
<pMultCmdsp></pMultCmdsp>
|
||||||
<SystemViewers>
|
<SystemViewers>
|
||||||
|
<Entry>
|
||||||
|
<Name>System Viewer\GPIOA</Name>
|
||||||
|
<WinId>35903</WinId>
|
||||||
|
</Entry>
|
||||||
|
<Entry>
|
||||||
|
<Name>System Viewer\GPIOB</Name>
|
||||||
|
<WinId>35902</WinId>
|
||||||
|
</Entry>
|
||||||
|
<Entry>
|
||||||
|
<Name>System Viewer\GPIOC</Name>
|
||||||
|
<WinId>35904</WinId>
|
||||||
|
</Entry>
|
||||||
<Entry>
|
<Entry>
|
||||||
<Name>System Viewer\SPI2</Name>
|
<Name>System Viewer\SPI2</Name>
|
||||||
<WinId>35905</WinId>
|
<WinId>35905</WinId>
|
||||||
|
|||||||
@@ -643,4 +643,13 @@
|
|||||||
<files/>
|
<files/>
|
||||||
</RTE>
|
</RTE>
|
||||||
|
|
||||||
|
<LayerInfo>
|
||||||
|
<Layers>
|
||||||
|
<Layer>
|
||||||
|
<LayName>flash eeprom Example</LayName>
|
||||||
|
<LayPrjMark>1</LayPrjMark>
|
||||||
|
</Layer>
|
||||||
|
</Layers>
|
||||||
|
</LayerInfo>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user