cancel
Showing results for 
Search instead for 
Did you mean: 

Flash eeprom initialization on STM32

luisf
Associate II
Posted on December 30, 2011 at 22:41

Hi, i am using ST lib to emulate a eeprom with the flash of a STM32 device. However, i am going to use that eerprom to save a comunication key, and i should set a initial value. How can i set the initial value on the flash?

Thank you!
5 REPLIES 5
Posted on December 30, 2011 at 23:49

You could add some records to the HEX file.

Add a memory region within the development system (scatter file / linker script), and do a static initialization in your code.

If stuff is critical, then consider adding code to identify it is missing, and write default data.

If it is part unique, then you should consider programming the data as part of the factory configuration/programming step. Use the system ROM's programming protocol, or add some code in your own app to pull data from an external source, or prompt for input.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
luisf
Associate II
Posted on December 31, 2011 at 02:48

Thank you for your reply, 

No, for sure the default value should not be uinique. I will go for the ''code only'' solution. It is the same idea as the RTC initialization.

That should solve my problem. Thank you! 

hernandez_nava_itt
Associate II
Posted on January 02, 2012 at 18:55

hello clive1

happy new year

I have a problem in communication USART

I want to send data to a microcontroller but is not detected, I think is the program I'm using lite atollic truestudio

Here I send you my code I am using the stm32l152rb

/* Includes */

#include ''stm32l1xx.h''

#include <stdio.h>

#include ''discover_board.h''

#include ''stm32l1xx_gpio.h''

#include ''stm32l1xx_usart.h''

#include ''stm32l1xx_flash.h''

#include ''stm32l1xx_rcc.h''

#include ''misc.h''

/* funciones privadas*/

void RCC_Configuration(void);

void GPIO_Configuration(void);

void NVIC_Configuration(void);

void USART1_IRQHandler(void);

static volatile uint32_t TimingDelay;

 RCC_ClocksTypeDef RCC_Clocks;

 void Config_Systick()

 {

   RCC_GetClocksFreq(&RCC_Clocks);

   SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);

 }

 void Delay(uint32_t nTime)

 {

   TimingDelay = nTime;

   while(TimingDelay != 0);

 }

/**

**===========================================================================

**

**  main program

**

**===========================================================================

*/

int main(void)

{

    /* configuracion contiene la structura USART*/

    USART_InitTypeDef USART_InitStructure;

    //GPIO_InitTypeDef GPIO_InitStructure;   //salidas

    /* HW configuration */

    RCC_Configuration();

    GPIO_Configuration();

    NVIC_Configuration();

    /* Configuracion USART ---------------------------------------------------*/

    USART_InitStructure.USART_BaudRate = 115200;

    USART_InitStructure.USART_WordLength = USART_WordLength_8b;

    USART_InitStructure.USART_StopBits = USART_StopBits_1;

    USART_InitStructure.USART_Parity = USART_Parity_No ;

    USART_InitStructure.USART_HardwareFlowControl =

    USART_HardwareFlowControl_None;

    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

    /* Configura y habilita USART1 */

    USART_Init(USART1, &USART_InitStructure);

    USART_Cmd(USART1, ENABLE); /* habilita interrupcion USART1 */

    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

    while (1);

    {

        /* escribe el caracter 'ch' en el  'f' file*/

        int fputc(int ch, FILE * f)

        {

            /* transmite el caracter por el USART*/

            USART_SendData(USART1, ch);

            /* espera hasta que la transmision a terminado */

            while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

            return ch;

        }

    }

}

/* configuracion fuente clock*/

void RCC_Configuration(void)

{

    /* error status */

    ErrorStatus

    HSEStartUpStatus;

    RCC_DeInit();

    RCC_HSEConfig(RCC_HSE_ON);

    HSEStartUpStatus = RCC_WaitForHSEStartUp();

    if (HSEStartUpStatus == SUCCESS)

    {

    //FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer, ENABLE);

    FLASH_SetLatency(FLASH_Latency_1);

    RCC_HCLKConfig(RCC_SYSCLK_Div1);

    RCC_PCLK2Config(RCC_HCLK_Div1);

    RCC_PCLK1Config(RCC_HCLK_Div2);

    RCC_PLLConfig(RCC_PLLSource_HSE, RCC_PLLMul_8, RCC_PLLDiv_2);

    RCC_PLLCmd(ENABLE);

    while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    while (RCC_GetSYSCLKSource() != 0x08);

    }

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

}

/* configuracion puerto I/O */

void GPIO_Configuration(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

/* configurar USART1_Tx como funcion alternante push-pull' */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Configurar USART1_Rx como entrada flotante*/

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOA, &GPIO_InitStructure);

}

/* configuracion NVIC  */

void NVIC_Configuration(void)

{

    NVIC_InitTypeDef NVIC_InitStructure;

    /* Place the vector table into FLASH */

    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);

    /* habilitar la interrupcion para USART1 */

    NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

}

/*

// convertir un char a binario

void int2bin(int value, char buffer[])

{

    int i = 8; buffer[i] = 0;

    while (i--)

    { buffer[i] = '0' + (value & 0x01);

    value >>= 1;

    }

}*/

/* Handles interrupcion para USART */

void USART1_IRQHandler(void)

{

    int data; char buf[9];

    /* resivir el caracter en binario*/

    data = USART_ReceiveData(USART1);

    //int2bin(data, buf);

    /* mandar el mensaje */

    printf(''Character: %c - dec: %03i - hex: %#04x - bin: %s\r\n'', (data >= 0x20 ? data : 0x20), data, data, buf);

}

void TimingDelay_Decrement(void)

{

  if (TimingDelay != 0x00)

  {

    TimingDelay--;

  }

}

Posted on January 02, 2012 at 22:24

That should really go in it's own thread.

Couple of observations, you need to fix that fputc() code you've pasted in the while() loop in main(). You definately don't want to be using printf() in an interrupt.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hernandez_nava_itt
Associate II
Posted on January 03, 2012 at 01:06

I am new to

programming

I

use

printf

to display

on screen

the data

receiver

I want to do

is

receives a

data