2022-09-07 03:41 AM
I'm using an STM32G070CB for a project and need to store 6 bytes worth of data to the flash memory. The MikroPascal PRO for ARM compiler that I'm using has a flash library for this (I assume it's their version of the HAL procedures that I've seen elsewhere), but it doesn't work so I'm trying to do it myself using the registers whilst I wait for a response from their developers. I've had a look through various forums and haven't seen anyone trying with just the registers.
I think I've initialised everything properly, then followed the process from section 3.3.7 of the reference manual, but the reset doesn't seem to occur. I've attached a copy of the code showing how I'm setting the registers. When I then go to write new data to the page, an error pops up saying "write to flash skipped".
If anyone has any ideas as to what I might have forgotten or why it may not be working let me know.
Regards,
James
2022-09-07 06:40 AM
Hi @JSimp.1 ,
the code looks sensible, but I can't really say for sure it's correct since it's not exactly CMSIS 1:1 copy. I don't know what you mean by the error popup, I'd suggest looking at the status registers, either in your IDE or using STM32CubeProgrammer.
BR,
J
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2022-09-07 07:04 AM
Hi @JHOUD,
Thanks for having a look at the code.
By the looks of what the status registers show in the debugger on MikroPascal when stepping through, they are all getting set properly. There's possibly something wrong on their end, there have been a few other things wrong that have had to be sorted, I'll see what they say when they get back to me. I'll have a look at the STM32Cube in the meantime and see if I can figure anything out in the meantime.
Regards,
James
2022-09-07 07:23 AM
Hi @JSimp.1 ,
I'm not familiar with this IDE (I haven't touched Pascal in 20 years now) but it may have some error in mapping of the registers. Less convenient but more reliable way to check on registers is directly in memory view.
BR,
J
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2022-09-07 07:57 AM
Hi @JHOUD,
No worries, I've just had a check of the mapping and everything seems ok from what I can see. Ill give the memory view a look tomorrow.
Regards,
James
2022-09-07 12:52 PM
Instead of various forums, first read the reference manual!
Do not set the PG bit, when you are doing erase.
2022-09-08 12:18 AM
I went through the whole flash section of the reference manual several times before looking on the forums.
I don't know why I've put the PG bit before the erase, I'll move it to before the write and see if that sorts it.
2022-09-09 06:10 AM
Turns out the registers were being set properly, was just the debug mode on the IDE wasn't updating itself properly. Transmitted out using UART to see what they were and managed to get everything sorted. For some reason I'd commented out the line that was clearing the PER bit so it flagged up an error when I was going to write.
Thanks for the help @JHOUD !