AnsweredAssumed Answered

stm32f103ret6 flash erase problem

Question asked by Jian Chen on Oct 31, 2017
Latest reply on Nov 1, 2017 by Amel N

Hi,

I need to perform STM32F103RET6 flash memory operation: erase, write.  My erase failed.  Anybody has the EWARM project for internal bootloader(burnt to chip from factory)?  Or any working flash routines for STM32F103RET6?

 

I am using \AN4657-STM32Cube_IAP_using_UART\Projects\STM3210C_EVAL\IAP_Main project. And change USER_FLASH_END_ADDRESS from 0x08040000 to 0x08080000 to match the flash for STM32F103RET6.  I think this is the only change for the STM32F103RET6 device from STM32F107 device. All other #define macro should be the same.

 

But when I execute the statement “FLASH_If_Erase(APPLICATION_ADDRESS);” the program still went to Hard_Fault function. 

 

My code is:

int main(void) {

  HAL_Init();

  SystemClock_Config();

  FLASH_If_Init();

  FlashProtection = FLASH_If_GetWriteProtectionStatus();  // return to 0 indicate not write protected.

 FLASH_If_Erase(APPLICATION_ADDRESS);

while(1) {}

 }

 

void SystemClock_Config(void)

{

  RCC_ClkInitTypeDef clkinitstruct = {0};

  RCC_OscInitTypeDef oscinitstruct = {0};

 

  oscinitstruct.OscillatorType  = RCC_OSCILLATORTYPE_HSE;

  oscinitstruct.HSEState        = RCC_HSE_ON;

  oscinitstruct.HSEPredivValue  = RCC_HSE_PREDIV_DIV1;

  oscinitstruct.PLL.PLLState    = RCC_PLL_ON;

  oscinitstruct.PLL.PLLSource   = RCC_PLLSOURCE_HSE;

  oscinitstruct.PLL.PLLMUL      = RCC_PLL_MUL6;  // 8MHz*6=48MHz

  if (HAL_RCC_OscConfig(&oscinitstruct)!= HAL_OK)

  {

    sys_err_code |= ERR_RCC_OSC_CONFIG;

  }

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

  clkinitstruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

  clkinitstruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

  clkinitstruct.APB2CLKDivider = RCC_HCLK_DIV1;

  clkinitstruct.APB1CLKDivider = RCC_HCLK_DIV2; 

  if (HAL_RCC_ClockConfig(&clkinitstruct, FLASH_LATENCY_2)!= HAL_OK)

  {

    sys_err_code |= ERR_RCC_CLK_CONFIG;

  }

  RCC->CFGR &= ~0x0000C000;

  RCC->CFGR |= 0x00008000;      // pclk2/6 as ADC clock(=48/6=8MHz)

}

Outcomes