cancel
Showing results for 
Search instead for 
Did you mean: 

Very Long Reset with NVIC_SystemReset();

MPoul.2
Associate II

Hello,

I work on a project using SPI to communicate Data acquired and processed with Motion FX. When an incomming signal is received, i want to reset my STM32 MCU with a software reset. However, when i do so using NVIC_SystemReset(), the spi communication can't be turned on before at least 15-20 seconds have passed. Would you know why does it behave this way?

Thank you for your help

14 REPLIES 14
Javier1
Principal

>, when i do so using NVIC_SystemReset(), the spi communication can't be turned on before at least 15-20

So if you do another kind of reset it takes less time?Maybe 20ms is the time it takes for your app to reset.

What if you initialice SPI sooner in your programm?

we dont need to firmware by ourselves, lets talk

Thank you for your answer.

That would be acceptable, except that those are seconds and not ms. I don't have any other method to do software reset, or at least didn't found any easy to code. Would you happen to know one? I work with an STM32 L476.

*$%t, thats a long time indeed.

I dont have experience with Motion FX, but for others to help you might want to post your code.(at least the init part previsous to SPI)

What about debugging, set a some breakpoints and figure out where is your code spending those 20secs

we dont need to firmware by ourselves, lets talk
MPoul.2
Associate II
int main(void)
{
  /* USER CODE BEGIN 1 */
	uint8_t ReturnSPI;
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_CRC_Init();
  MX_SPI1_Init();
  MX_TIM3_Init();
  MX_RTC_Init();
  /* USER CODE BEGIN 2 */
  MX_MEMS_Init();
  initCalib = 0;
  /* USER CODE END 2 */
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  // MX_MEMS_Process(); // Here not working
 
	  ReturnSPI = HAL_SPI_Receive(&hspi1, &input, 1, 11);
 
        //Here, if it receives an SPI request to calibrate again, i call a function to do so
       if (command)...
             clearCalib();
 
    MX_MEMS_Process();
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
 
 
 
 
void clearCalib()
{
	HAL_FLASH_Unlock();
 
	__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
	/* Get the 1st page to erase */
	FirstPage = GetPage(ADDR_Calib_1);
	/* Get the number of pages to erase from 1st page */
	NbOfPages = GetPage(ADDR_Calib_4+8) - FirstPage + 1;
	/* Get the bank */
	BankNumber = GetBank(0x0801F800);
	/* Fill EraseInit structure*/
	EraseInitStruct.TypeErase   = FLASH_TYPEERASE_PAGES;
	EraseInitStruct.Banks       = BankNumber;
	EraseInitStruct.Page        = FirstPage;
	EraseInitStruct.NbPages     = NbOfPages;
 
	if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) == HAL_OK)
	{
 
	}
 
	else
	{
		testWriteFlash = 11;
	}
	HAL_FLASH_Lock();
	NVIC_SystemReset();
	//////////////////////////////////////////////////////////////////
}

This part has nothing to do with motion FX as it is not used before rebooting once the spi message is received.

The main issue is i don't know if it's the SPI that doesn't reboot or if the MCU itself did'nt boot, as my only access is from SPI connection.

MPoul.2
Associate II

Is there another way to reboot? Instead of NVIC_SystemReset function i mean?

TDK
Guru

I don't think resetting via other methods will help. See what is taking so long in your code to reach the SPI calls. Instrument it or run a debugger and hit pause during those 15-20 seconds to see where it is.

If you feel a post has answered your question, please click "Accept as Solution".
simosilva
Senior

The NVIC_SystemReset is istantaneous, you're missing something here.

First of all try to power off the board and check the SPI delay from poweron to working state, it must be the same 15-20 seconds, than search for the cause of this delay in your code and so try to reduce timings.

Thanks for your answer. Thats my issue, In the first boot, my SPI connexion is instantaneous. So I really don't know what could go wrong...

Okay, thanks. As i don't have a debugger available ( I work on a custom board made by my team) i'm not sure if i'll be able to do so...