cancel
Showing results for 
Search instead for 
Did you mean: 

Maintain Codes After Power Off

AE104
Senior

Hello,

I developed a custom-designed system with an STM32F767 microprocessor and controlled its parameters with a user interface through a Bluetooth module. When I power off then power on the system, I couldn't communicate with the circuit board. Is there a way to store codes without affecting power off?

Thank you,

15 REPLIES 15
TDK
Guru

> custom-designed system

Is BOOT0 held low?

> does the DMA mode operation solve the problem?

All modes work. Switching from one to another is not the correct method to solve a bug in your code.

I have to say the question here is really hard to follow. You experienced a UART issue and instead asked how to store data in flash? And you're not even storing it into bank 2. 0x08000000 is bank 1. Could be missing something.

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

"Is BOOT0 held low?" Yes. @TDK​ 

My purpose is that my custom system is supposed to work after power off.

AE104
Senior

One more thing is that I learned that I can download the HEX file to the microprocessor through STLink Utility. When I selected target -> Program & Verify option and download the hex file, I got this message. Do you think that the problem is related to this message?

Are you referring to the checksum message? No, that is informational and not a cause for concern.
The message about verification being OK means data read from the flash matches what was put there.
If you feel a post has answered your question, please click "Accept as Solution".
AE104
Senior

Now, I placed a LED toggling function in the while loop of the main code, the LED is blinking even powered off and on the system. I verified that the codes are in the flash memory of the processor with an LED.

I increased the UART timeout session 10000 to 1000000. Because I suspect that the timeout session was not enough long. But it didn't work.

When I powered off and on the circuit, I sent commands from my user interface at the PC to the circuit, it received variable new values but not transmit back to the user interface. Do you have any other suggestions?

Should BOOT0 be high during flashing the codes in the processor and then return back to low during normal operation? Like in this link, https://scienceprog.com/flashing-programs-to-stm32-embedded-bootloader/

Thank you,

AE104
Senior

I diagnosed the problem. In my code, I used .c and .h files to generate microsecond delays. When I disabled the initialization of this function and replaced with HAL_Delay, the codes worked after powered off and then on. Could you check the function .c and .h files contents to show what they are missing? Because I need microsecond delays.

.c file:

#include "dwt_stm32_delay.h"
 
 
/**
 * @brief  Initializes DWT_Clock_Cycle_Count for DWT_Delay_us function
 * @return Error DWT counter
 *         1: clock cycle counter not started
 *         0: clock cycle counter works
 */
uint32_t DWT_Delay_Init(void) {
  /* Disable TRC */
  CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk; // ~0x01000000;
  /* Enable TRC */
  CoreDebug->DEMCR |=  CoreDebug_DEMCR_TRCENA_Msk; // 0x01000000;
 
  /* Disable clock cycle counter */
  DWT->CTRL &= ~DWT_CTRL_CYCCNTENA_Msk; //~0x00000001;
  /* Enable  clock cycle counter */
  DWT->CTRL |=  DWT_CTRL_CYCCNTENA_Msk; //0x00000001;
 
  /* Reset the clock cycle counter value */
  DWT->CYCCNT = 0;
 
     /* 3 NO OPERATION instructions */
     __ASM volatile ("NOP");
     __ASM volatile ("NOP");
  __ASM volatile ("NOP");
 
  /* Check if clock cycle counter has started */
     if(DWT->CYCCNT)
     {
       return 0; /*clock cycle counter started*/
     }
     else
  {
    return 1; /*clock cycle counter not started*/
  }
}
 
/* Use DWT_Delay_Init (); and DWT_Delay_us (microseconds) in the main */

.h file:

#ifndef DWT_STM32_DELAY_H
#define DWT_STM32_DELAY_H
 
#ifdef __cplusplus
extern "C" {
#endif
 
 
#include "stm32f7xx_hal.h"
 
/**
 * @brief  Initializes DWT_Cycle_Count for DWT_Delay_us function
 * @return Error DWT counter
 *         1: DWT counter Error
 *         0: DWT counter works
 */
uint32_t DWT_Delay_Init(void);
 
 
 
/**
 * @brief  This function provides a delay (in microseconds)
 * @param  microseconds: delay in microseconds
 */
__STATIC_INLINE void DWT_Delay_us(volatile uint32_t microseconds)
{
  uint32_t clk_cycle_start = DWT->CYCCNT;
 
  /* Go to number of cycles for system */
  microseconds *= (HAL_RCC_GetHCLKFreq() / 1000000);
 
  /* Delay till end */
  while ((DWT->CYCCNT - clk_cycle_start) < microseconds);
}
 
 
#ifdef __cplusplus
}
#endif
 
#endif