API  2.2
TSmarT Software Library
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
int_flash.c

Example showing how to initialize, erase and write data in the internal flash memory.

/*
* @file int_flash.c
* @author TST
* @version V0.0
* @date 20/06/2012
* @brief Internal flash example. This is an example showing how to write data in the internal flash
* memory. It is necessary to use the memory browser to check the results.
*
*/
/* This file includes all the necessary headers (System, STM32, FreeRTOS, TS_Drivers, TS_Boards, TS_Devices
* and TS_Utils) so the program can work properly */
#include "tsmart.h"
/*
* Task function. Main process to erase and write data in the internal flash memory.
*
*/
void vINT_FLASH_EXAMPLE(void *pvParameters){
/* Variables */
uint32_t buff_write[50];
uint32_t buff_read[50];
uint32_t addr = 0x0801D000; /* Base address */
uint32_t pages = 1; /* Pages to be erased */
uint32_t i;
/* Erase flash. It is mandatory to erase the flash area to be used before writing.
* In this example 1 page is erased */
/* Data to write. In this example numbers from 1 to 49 are written in each memory position */
for(i=0; i<50; i++){
buff_write[i]=i;
}
/* Write process. User must indicate a base address to start writing.
* Use the memory browser at 0x0801D000 address to check the results */
TSMART_INT_FLASH_WriteRegion((uint32_t *)buff_write, sizeof(buff_write), addr);
while(1);;
}
/*
* @brief init() function
*
* This is the first thing that the user must do for using TSmarT.
* It initializes the specific hardware resources (GPRS, GPS, AI, DIO, MODBUS, MSA...)
* and software resources (queues, mutex, tasks...) for the user application.
*
* The way to fill in this function properly is to initialize first
* hardware resources and after that software resources.
*
* This function must return: TSMART_PASS when every thing is OK or
* TSMART_FAIL when a failure happened.
*
* @return
* @arg TSMART_PASS
* @arg TSMART_FAIL
*/
int32_t init() {
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* Initialize internal flash memory */
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* Create the INT_FLASH_EXAMPLE task */
if(xTaskCreate(vINT_FLASH_EXAMPLE, "EXT_FLASH_EXAMPLE", 1024, NULL, 7, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}