void kmy_FlashEraseBulk(void) { kmy_FlashWriteEnable(); FLASH_CS_LOW(); spi_Write(FLASH_CMD_BE); FLASH_CS_HIGH(); kmy_FlashWaitForWriteEnd(); }
void kmy_FlashInit(void) { GPIO_InitTypeDef GPIO_InitStructure; FLASH_CS_HIGH(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = FLASH_SCK_PIN|FLASH_CS_PIN|FLASH_MOSI_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(FLASH_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = FLASH_MISO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(FLASH_PORT, &GPIO_InitStructure); FLASH_CS_LOW(); spi_Write(FLASH_CMD_WRSR); spi_Write(0x02); FLASH_CS_HIGH(); }
static void kmy_FlashWaitForWriteEnd(void) { unsigned char flashstatus = 0; FLASH_CS_LOW(); spi_Write(FLASH_CMD_RDSR); do{ flashstatus = spi_Read(); } while ((flashstatus & FLASH_WIP_FLAG) == SET); FLASH_CS_HIGH(); }
void kmy_FlashEraseSector(uint32_t SectorAddr) { kmy_FlashWriteEnable(); FLASH_CS_LOW(); spi_Write(FLASH_CMD_SE); spi_Write((SectorAddr & 0xFF0000) >> 16); spi_Write((SectorAddr & 0xFF00) >> 8); spi_Write(SectorAddr & 0xFF); FLASH_CS_HIGH(); kmy_FlashWaitForWriteEnd(); }
void kmy_FlashReadBuffer(unsigned char* pBuffer, unsigned int ReadAddr, unsigned int NumByteToRead) { FLASH_CS_LOW(); spi_Write(FLASH_CMD_READ); spi_Write((ReadAddr & 0xFF0000) >> 16); spi_Write((ReadAddr& 0xFF00) >> 8); spi_Write(ReadAddr & 0xFF); while (NumByteToRead--){ *pBuffer = spi_Read(); pBuffer++; ReadAddr++; } FLASH_CS_HIGH(); }
/******************************************************************************* * @brief : Initialise the Adesto Data Flash. * @param : Aucun. * @return : Rien. ******************************************************************************/ void LBF_FLASH_IOcfg(void) { GPIO_InitTypeDef GPIO_InitStruct; // PB7 = /CS // Std CMOS output, no pull-up/-down resistor, high speed GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Pin = FLASH_CS_PIN; HAL_GPIO_Init(FLASH_CS_PORT, &GPIO_InitStruct); /* Initialise pin in high (inactive) state */ FLASH_CS_HIGH(); }
/******************************************************************************* * @brief : Configure the page size of ADESTO DataFlash. * @param : None. * @return : None. ******************************************************************************/ void FLASH_ConfigurePageSize(void) { /* Select the FLASH: Chip Select low */ FLASH_CS_LOW(); /* Send Page Size Configuration Command for 512 bytes/page */ FLASH_SendByte(FLASH_CMD_PAGESIZE1); FLASH_SendByte(FLASH_CMD_PAGESIZE2); FLASH_SendByte(FLASH_CMD_PAGESIZE3); FLASH_SendByte(FLASH_CMD_PAGESIZE4); /* Deselect the FLASH: Chip Select high */ FLASH_CS_HIGH(); /* Wait the end of Flash writing */ FLASH_WaitForWriteEnd(); }
void kmy_FlashWritePage(const unsigned char* pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite) { kmy_FlashWriteEnable(); FLASH_CS_LOW(); spi_Write(FLASH_CMD_WRITE); spi_Write((WriteAddr & 0xFF0000) >> 16); spi_Write((WriteAddr & 0xFF00) >> 8); spi_Write(WriteAddr & 0xFF); while (NumByteToWrite--){ spi_Write(*pBuffer); pBuffer++; } FLASH_CS_HIGH(); kmy_FlashWaitForWriteEnd(); }
static void kmy_FlashWriteEnable(void) { FLASH_CS_LOW(); spi_Write(FLASH_CMD_WREN); FLASH_CS_HIGH(); }