Report
4 years, 1 month ago.

Nucleo L152RE Flash issue

I'm trying to write some data on internal Flash of L152RE but after I reset the microcontroller either it hangs or whole flash is erased. It simple do nothing after reset.

Here is the sample code:

include the mbed library with this snippet


#include "mbed.h"

Serial pc(USBTX, USBRX);



int main()
{
				
	    uint32_t a[32]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32};
		
		uint32_t *rawdata=&a[0];
		
		HAL_StatusTypeDef status;
		
		FLASH_EraseInitTypeDef erase_pages;
		erase_pages.PageAddress=0x0807ff00;
		erase_pages.NbPages=1;
		erase_pages.TypeErase=TYPEERASE_PAGES;
		uint32_t *error; 
		
		HAL_FLASH_Unlock(); 
	    HAL_FLASHEx_Erase(&erase_pages, error);
		HAL_FLASH_Lock();
			
		
		HAL_FLASH_Unlock(); 
	    status=HAL_FLASHEx_HalfPageProgram(0x0807ff00,rawdata);
		HAL_FLASH_Lock(); 
			
		
		uint32_t address=0x0807ff00;
		for(int i=0;i<32;i++)
		{
		  uint32_t tmp = 0;
          tmp = *(__IO uint32_t*)address;
		  pc.printf("value=%d\n\r",tmp);
		  address=address+4;
		}
	
    
}

Kindly help. Thank you.

Why yo udont check what is the error value? Not handling error conditions?

posted by Martin Kojtal 09 Mar 2015

Actually the error was because of the 'error' value. I was passing 'error' without initializing it. Problem solved :)

posted by Naveed Anwar 09 Mar 2015
Comment on this question
Be the first to answer this question.

To post an answer, please log in.