123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- /*
- * eeprom.c
- *
- * Created on: 2020. 4. 22.
- * Author: parkyj
- */
- #include <stdio.h>
- #include <string.h>
- #include "main.h"
- #include "eeprom.h"
- #include "stm32f1xx_hal.h"
- #include "stm32f1xx_hal_gpio.h"
- /* Includes ------------------------------------------------------------------*/
- HAL_StatusTypeDef EEPROM_M24C08_ByteRead(uint16_t devid,uint16_t Address,uint8_t* data,uint8_t size);
- BLUESTATUS_st bluecell_Currdatastatus;
- extern I2C_HandleTypeDef hi2c2;
- typedef enum{
- HFR_BANK1_SEL = 1,
- HFR_BANK2_SEL = 2,
- HFR_AUTO_SEL = 3,
- }HFR_BootSelIndex_;
- void EEPROM_M24C08_Init(void){
- EEPROM_M24C08_Read(EEPROM_M24C08_ID,EEPROM_WINDOW_STATUS_ADDRESDS,&bluecell_Currdatastatus.bluecell_header,sizeof(BLUESTATUS_st) );
- printf("bluecell_Currdatastatus.CPU_Bank_Select : %d \r\n",bluecell_Currdatastatus.CPU_Bank_Select);
-
- if(bluecell_Currdatastatus.CPU_Bank_Select == HFR_BANK1_SEL){
- printf("Write Start \r\n");
- MBIC_BankBooting_Flash_write((uint32_t*)FLASH_USER_BANK1_START_ADDR,FLASH_MBICUSER_START_ADDR);
- bluecell_Currdatastatus.CPU_Bank_Select = 5;
- }else if(bluecell_Currdatastatus.CPU_Bank_Select == HFR_BANK2_SEL){
- printf("Write Start \r\n");
- MBIC_BankBooting_Flash_write((uint32_t*)FLASH_USER_BANK2_START_ADDR,FLASH_MBICUSER_START_ADDR);
- bluecell_Currdatastatus.CPU_Bank_Select = 6;
- }
- else if (bluecell_Currdatastatus.CPU_Bank_Select == HFR_AUTO_SEL){
- if(bluecell_Currdatastatus.CPU_Bank_Select == HFR_BANK1_SEL){
- printf("Write Start \r\n");
- MBIC_BankBooting_Flash_write((uint32_t*)FLASH_USER_BANK2_START_ADDR,FLASH_MBICUSER_START_ADDR);
- bluecell_Currdatastatus.CPU_Bank_Select = 6;
- }else{
- printf("Write Start \r\n");
- MBIC_BankBooting_Flash_write((uint32_t*)FLASH_USER_BANK1_START_ADDR,FLASH_MBICUSER_START_ADDR);
- bluecell_Currdatastatus.CPU_Bank_Select = 5;
- }
- }
- EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_WINDOW_STATUS_ADDRESDS),&bluecell_Currdatastatus.bluecell_header,sizeof(BLUESTATUS_st));
- printf("EEPROM INIT COMPLETE\r\n");
- }
- #define MAXEEPROM_LENG 32
- HAL_StatusTypeDef EEPROM_M24C08_Read(uint8_t devid,uint16_t Address,uint8_t* data,uint16_t size){
- HAL_StatusTypeDef ret = HAL_ERROR;
- // uint16_t sizecnt = 0,
- //uint16_t sizeremain = 0;
- // uint16_t addrees_inc = 0;
- // ret = HAL_I2C_Mem_Read(&hi2c2, devid | ((Address & 0x0300) >> 7),((Address )), I2C_MEMADD_SIZE_8BIT, &data[0], size, 1024);
- ret = HAL_I2C_Mem_Read(&hi2c2, devid ,((Address )), I2C_MEMADD_SIZE_16BIT, &data[0], size, 1024);
- // EEPROM24XX_Load( Address,data, size);
- if(ret == HAL_ERROR)
- printf("Write ERR\r\n");
- else
- HAL_Delay(20);
- return ret;
- }
- HAL_StatusTypeDef EEPROM_M24C08_write(uint8_t devid,uint16_t Address,uint8_t* data,uint16_t size){
- HAL_StatusTypeDef ret = HAL_ERROR;
- uint8_t sizecnt = 0,sizeremain = 0;
- uint16_t addrees_inc = 0;
- sizecnt = size /MAXEEPROM_LENG;
- sizeremain = size % MAXEEPROM_LENG;
- addrees_inc = 0;
- if(sizecnt > 0){
- for(int i = 0 ; i < sizecnt; i++ ){
- addrees_inc = i * MAXEEPROM_LENG;
- ret = HAL_I2C_Mem_Write(&hi2c2, devid ,((Address + addrees_inc) & 0xFFFF) , I2C_MEMADD_SIZE_16BIT, &data[addrees_inc], MAXEEPROM_LENG, 1024);
- if(ret == HAL_ERROR)
- printf("Write ERR\r\n");
- else
- HAL_Delay(20);
- }
- addrees_inc += MAXEEPROM_LENG;
- }
- // printf("Remain Data Index : %d \r\n",sizeremain);
-
- if(sizeremain > 0){
- // printf("Remain Data Write Start ");
- for(int i = 0; i < sizeremain; i++){
- ret = HAL_I2C_Mem_Write(&hi2c2, devid ,((Address + addrees_inc + i)& 0xFFFF) , I2C_MEMADD_SIZE_16BIT, &data[addrees_inc + i], 1, 1024);
- // EEPROM24XX_Save( Address,data, size);
- if(ret == HAL_ERROR)
- printf("Write ERR\r\n");
- else
- HAL_Delay(20);
- }
- }
- return ret;
- }
- HAL_StatusTypeDef EEPROM_M24C08_Zerowrite(uint8_t devid,uint16_t Address){
- HAL_StatusTypeDef ret = HAL_ERROR;
- // uint8_t sizeremain = 0;
- uint16_t addrees_inc = 0;
- addrees_inc = 0;
- uint8_t data[4096] = {0,};
- for(int i = 0 ; i < 128; i++ ){
- addrees_inc = i * MAXEEPROM_LENG;
- ret = HAL_I2C_Mem_Write(&hi2c2, devid ,((Address + addrees_inc) & 0xFFFF) , I2C_MEMADD_SIZE_16BIT, &data[0], MAXEEPROM_LENG, 1024);
- if(ret == HAL_ERROR)
- printf("Write ERR\r\n");
- else
- HAL_Delay(20);
- }
- return ret;
- }
|