STM32F767 flash programming issue - stm32

We are trying to program the MCU flash memory to write and save some data on it.
After a single write to a single sector(that might have failed), when we try to write/overwrite the same sector we fail.
We are using HAL_FLASHEx_Erase to delete the sector.
In particular, we use the ideas in this article https://controllerstech.com/flash-programming-in-stm32/
Looking for advice on how to proceed from here/ things to think about that we might have missed.
Thanks in advance.

Related

Can user code create a new memory segment?

I've been researching about memory segmentation, and it's been giving me lots of ideas for potential ways in which user code could benefit from swapping out segment registers. Specifically, I am interested in the x86-64 architecture because that's what I have.
Is there any way in which a user-mode program can create a new segment, for internal use?
To what extent can a program configure its own address space?
I imagine the GDT is way outside of a process' reach, but can a process modify the LDT?
Sorry if I sound naive, this is new stuff for me.
I also imagine that, if there even is a way to do this, it will almost certainly pass through OS specific functions. How would one do this in, say, Win32? I have found GetThreadSelectorEntry (https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getthreadselectorentry), but I haven't been able to find the equivalent SetThreadSelectorEntry.

Using EEPROM in STM32f10x

I'm using STM32f103 and in my program, I need to save some bytes in the internal flash memory. But as far as I know, I have to erase a whole page to write in it, which will take time.
This delay causes my display to blink.
Can anybody help me to save my data without consuming so much time?
Here is a list that may help:
1- MCU: STM32f103
2- IDE: Keil vision
3- using HAL driver provided by STM32CubeMx
4- sample data for saving in Flash: {0x53, 0xa0, 0x01, 0x54}
In the link below, you can find the code that I'm using.
FLASH_PAGE for Keil
The code you provide doesn't seem to be implemented well. It basically does 2 things each time you initiate a write operation:
Erase the page (this is the part that takes time)
Start form the given pointer, write until it hits a zero.
This is a very ineffective way of using the flash.
Probably the simplest and the most well-known way is to use the method described in ST's AN2594, although it has some limitations.
Still, at some point a page erase will be necessary regardless the method you use and there is no way to avoid some delay, unless your uC supports dual flash banks (STM32F103 don't have this feature). You need to plan the timing of flash writes and display refresh accordingly. If you need periodic writes to the flash, there is probably some high level error in your design.
To solve this problem, I used another library that STM itself presented. I had to include "eeprom.h" into your project and then add "eeprom.c" to it. You can easily find these files on the Internet.

What happens to a running program when my computer switches to Hibernate?

my laptop goes to hibernate when I'm running a matlab code because of overheating. when I turn it on again, matlab countinue to running my code. I'm worry about the results of my code! what do you think? is there any problem with hibernating and resuming the matlab code?
thank you.
I recommend looking at this: http://www.mathworks.com/matlabcentral/answers/46569-what-happens-to-a-running-program-when-my-computer-switches-to-hibernate
Theoretically, when the computer hibernates, the status of the memory and disk are saved. However, as it is pointed out in the link I provided, this is not very reliable and can lead to corruption of files and/or data.
Instead, I recommend that your program saves necessary variables from time to time using checkpoints, so that your program can run reliably even when your code is paused or your computer hibernates. Take a look at this link to see how to implement checkpoints: http://www.walkingrandomly.com/?p=5343.

I release all memory that I can, but my program need more, what can I do?

This is a philosophical question. My program send message that need more memory. I release all memory I can to it continue working correct. But, the program tell that need more memory again, and I have no one to release. What I do now?
This almost happens when I am using the camera with the ZBar library, so I don't have control with the ZBar (I can't release it's memory, only mine). And this really need a lot of memory to work. Because this, I don't know what I do.
The program didn't crash, but can run unstable.
Without more details to your problem, your answers are going to be vague :)
The obvious answer is to use less memory.
If depends on what you're using the memory for but you could consider putting it into a file on disk and only reading in the data that you need?
You should also check for leaks - you might be using memory without realising it.
If you post more information about your exact problem, we could probably help more.

iphone - how the file system responds to accessing the same file at the same time?

Suppose two asynchronous operations try to read or write in the same file on a given folder. How does iOS deals with that? Is the operations queued? The app crashes? the file get corrupted?
In case it is up to the programmer to deal with this, where do I find informations or an example on how to deal with race conditions, queues, etc.?
Can you guys give me a hint?
thanks.
I think that when trying to acquire the file descriptor for your file, it should fail if it is already in use.
As there is apparently no way to know if the file is already opened, there might be a way to lock a file.
Links that may help you:
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/LowLevelFileMgmt/Introduction.html
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSFileHandle_Class/Reference/Reference.html
http://developer.apple.com/library/ios/#documentation/Performance/Conceptual/FileSystem/FileSystem.html
http://developer.apple.com/library/ios/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/Glossary/Glossary.html
http://developer.apple.com/library/ios/#documentation/CoreFoundation/Reference/CFFileDescriptorRef/Reference/reference.html
The most likely answer is "the file gets corrupted". The OS will not do anything to prevent multiple threads from writing to a file simultaneously, and if they're writing to overlapping sections of the file, all bets are off.
So, your best bet is to enforce your own queueing on access to the file. There are lots of ways to to that. At a low level, you can use an NSLock to prevent simultaneous access, or you might want to use a Dispatch Queue. The Concurrency Programming Guide mentioned by Julio's answer is a good reference.