cancel
Showing results for 
Search instead for 
Did you mean: 

store

syedhashmiraza
Associate II

hello in this code not storing string after power cut and poer on in eeprom not storing and in this code how to use printf?

 

/* Includes ------------------------------------------------------------------*/

#include "main.h"

#include <stdio.h>

/** @addtogroup EEPROM_Emulation

* @{

*/

 

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

 

/* Virtual address defined by the user: 0xFFFF value is prohibited */

uint16_t VirtAddVarTab[NB_OF_VAR] = {0x5555, 0x6666, 0x7777};

uint16_t VarDataTab[NB_OF_VAR] = {0, 0, 0};

uint16_t VarValue,VarDataTmp = 0;

/* Private function prototypes -----------------------------------------------*/

static void SystemClock_Config(void);

static void Error_Handler(void);

 

/* Private functions ---------------------------------------------------------*/

 

/**

* @brief Main program.

* @param None

* @retval None

*/

 

//char writeString[] = "Hello Hashmi";

char readString[64]={0};

 

 

int main(void)

{

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

 

/* Configure the system clock to 180 MHz */

SystemClock_Config();

 

/* Unlock the Flash Program Erase controller */

HAL_FLASH_Unlock();

 

/* Configure LED3 */

BSP_LED_Init(LED3);

 

/* EEPROM Init */

ifEE_Init() != EE_OK)

{

Error_Handler();

}

 

if (EE_ReadVariable(VirtAddVarTab[0], &VarDataTmp) != HAL_OK)

{

Error_Handler();

}

char writeString[] = "Hello";

for (int i = 0; i < sizeof(writeString); i++)

{

uint16_t charToWrite = (uint16_t)writeString[i];

 

// Pass the value, not the pointer

if (EE_WriteVariable(VirtAddVarTab[0] + i, charToWrite) != HAL_OK)

{

Error_Handler();

}

 

}

 

 

//printf("hello");

 

 

 

 

}

 

 

static void SystemClock_Config(void)

{

RCC_ClkInitTypeDef RCC_ClkInitStruct;

RCC_OscInitTypeDef RCC_OscInitStruct;

HAL_StatusTypeDef ret = HAL_OK;

 

/* Enable Power Control clock */

__HAL_RCC_PWR_CLK_ENABLE();

 

/* The voltage scaling allows optimizing the power consumption when the device is

clocked below the maximum system frequency, to update the voltage scaling value

regarding system frequency refer to product datasheet. */

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

 

/* Enable HSE Oscillator and activate PLL with HSE as source */

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

RCC_OscInitStruct.HSEState = RCC_HSE_ON;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

RCC_OscInitStruct.PLL.PLLM = 8;

RCC_OscInitStruct.PLL.PLLN = 360;

RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

RCC_OscInitStruct.PLL.PLLQ = 7;

HAL_RCC_OscConfig(&RCC_OscInitStruct);

ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);

 

if(ret != HAL_OK)

{

while(1) { ; }

}

 

/* Activate the Over-Drive mode */

HAL_PWREx_EnableOverDrive();

 

/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2

clocks dividers */

RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);

if(ret != HAL_OK)

{

while(1) { ; }

}

}

 

/**

* @brief This function is executed in case of error occurrence.

* @param None

* @retval None

*/

static void Error_Handler(void)

{

while(1)

{

/* Toggle LED3 fast */

BSP_LED_Toggle(LED3);

HAL_Delay(40);

}

}

 

#ifdef USE_FULL_ASSERT

 

/**

* @brief Reports the name of the source file and the source line number

* where the assert_param error has occurred.

* @param file: pointer to the source file name

* @param line: assert_param error line source number

* @retval None

*/

void assert_failed(uint8_t* file, uint32_t line)

{

/* User can add his own implementation to report the file name and line number,

exprintf("Wrong parameters value: file %s on line %d\r\n", file, line) */

 

/* Infinite loop */

while (1)

{

}

}

#endif

 

/**

* @}

*/

0 REPLIES 0