#include "eeprom.h"


void putIntoEeprom(uint16_t lenght, uint16_t* param)
{	
uint32_t adr = FLASH_EEPROM_BASE;
//uint32_t p = FLASH_STARTO;
HAL_StatusTypeDef	flash_ok = HAL_ERROR;	
	
		while(flash_ok != HAL_OK)
			{flash_ok = HAL_FLASH_Unlock();}
			
			FLASH_EraseInitTypeDef erase;
			uint32_t pageError = 0x0;
			erase.TypeErase = FLASH_TYPEERASE_PAGES;
			erase.PageAddress = FLASH_EEPROM_BASE;
			erase.NbPages = 0x01;		
			flash_ok = HAL_FLASHEx_Erase(&erase, &pageError);		
		
			flash_ok = HAL_ERROR;
		while(flash_ok != HAL_OK)
			{flash_ok = HAL_FLASH_Lock();}
		
		
		flash_ok = HAL_ERROR;	
	while(flash_ok != HAL_OK)
		{flash_ok = HAL_FLASH_Unlock();}
	
			flash_ok = HAL_ERROR;
		while(flash_ok != HAL_OK)			
		{			
			for(int i=0; i<(lenght); i++)
			{
				flash_ok = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, adr, *param);
				param++;
				adr += 0x2;
			}
		}
	
		flash_ok = HAL_ERROR;
	while(flash_ok != HAL_OK)
		{flash_ok = HAL_FLASH_Lock();}
}

uint16_t watInTheFlash(uint32_t adress)
{	
	return (*(uint32_t*) adress);	
}

