Skip to main content
AE104
Associate III
April 15, 2022
Question

Store Codes in the Flash Memory in the STM32

  • April 15, 2022
  • 13 replies
  • 4280 views

Hello,

I am using stm32f767 as a microprocessor. After power off, the codes are deleted from the microprocessor. But when I checked with the STlink Utility, I saw that the codes are stored in the Flash memory. Is the reason of non operative processor after power off related with some parts of the code not stroing flash memory properly or hardware issue?

Thank you,

This topic has been closed for replies.

13 replies

Tesla DeLorean
Guru
April 15, 2022

Make sure BOOT0 pin is pulled low.

Check Option Bytes for boot and banking options.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
AE104
AE104Author
Associate III
April 15, 2022

Boot0 is grounded through 100kOhms. How can I check this "Check Option Bytes for boot and banking options.​"? @Community member​ 

Tesla DeLorean
Guru
April 15, 2022

I believe the bits in the option bytes are in the RM, you'd start perhaps by inspecting the values in the unit(s)

I'd pick something significantly more aggressive for a pull-down.

It could be your code is actually starting, but dies in Error_Handler() or HardFault_Handler(), have some GPIO's toggle there so you know if it started and failed.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
AE104
AE104Author
Associate III
April 16, 2022

Thank you @Community member​ and @TDK​ !

I have attached the STM32CubeProgrammer screenshots. My impression is that all settings are correct to write the codes in the FLASH memory.

Sorry, I mistyped the resistor value. There is 10kOhm resistor at BOOT0 pin.

When the debugger connected and in the debug mode, the code is stuck at void HardFault_Handler(void). Attached the screenshots

0693W00000Ly9yiQAB.png 

0693W00000Ly9ydQAB.png 

0693W00000Ly9ynQAB.png0693W00000LyA00QAF.png

TDK
April 16, 2022

Use the information that it's providing you. What is at main.c line 284?

"If you feel a post has answered your question, please click ""Accept as Solution""."
AE104
AE104Author
Associate III
April 16, 2022

Oh now I recognized that on the error. There is a calculation. @TDK​ 

AmpModFreqCalculation = round((1000000 / (ModulationFreq * 128)));  

So, the ModulationFreq value doesn't have a value every time. In a certain condition, the variable has value. Is it because of that?

TDK
April 16, 2022

Do you mean that sometimes it has a value of 0? Divide by zero can cause a hard fault. Using floating point instructions when FPU is not enabled can also cause a hard fault.

"If you feel a post has answered your question, please click ""Accept as Solution""."
AE104
AE104Author
Associate III
April 16, 2022

Yes. For testing purposes, I set the AmpModFreqCalculation as 78, and the error was gone. Thank you @TDK​ !

But the system is still not working after power off and on. Basically, I hit the 'Run' on the CubeIDE. At the end of its process, I removed the debugger from the connector. Then, I powered off the system and powered on back. I can connect to Bluetooth successfully with an interface. But there is no receiving and transmission. Interesting thing is that when I connect the debugger after powering off and on, the system works.

AE104
AE104Author
Associate III
April 16, 2022

After a quick research, I found this link, https://electronics.stackexchange.com/questions/446048/stm32f4-discovery-board-only-works-in-debug-mode

Then I check the system tick timer, its preemption priority is 15. So this may cause the problem? @TDK​ 

AE104
AE104Author
Associate III
April 16, 2022

By the way, how the equation should define ideally and enable FPU? @TDK​ 

Edit: I fixed with

double AmpModFreqCalculation = 0;

AmpModFreqCalculation = round((1000000.0 / (ModulationFreq * 128.0)));

Piranha
Principal III
April 16, 2022

For hardware and C language there is no such a thing as "no value". If the variable is uninitialized, it could also be zero. Division by zero is typically unacceptable and should be avoided.