0

I am trying to write a piece of data to the option byte at 0x1FFFF804. If the data I want programming is 0x08AE the data written is 0x51AE. Note this is on a copy of an STM32F103 (a MindMotion MM32F103).

This is my code below.

if (Sleep == ECUSleep(SaveAdr, BkpData) == 1) {
   FLASH_Unlock();
   FLASH_OPTB_Enable();
   FLASH_EraseOptionBytes();
   FLASH_ProgramOptionHalfWord(0x1FFFF804, (u16)SaveData.SystemPulse);  //Sys Pulse
   GPIO_ResetBits(GPIOB,GPIO_Pin_3);
   Flash_Lock();
}

Am I missing something? It seems strange that 1 bit is correct and the other is not.

  • completely unfamiliar with your architecture, but you say you're writing a byte ... 0x08AE is probably two bytes, and 0xAE is getting written. Do you intend to write 2 bytes? Should you be using a different function rather than `_ProgramHalfWord`? How long is a word on this architecture? – yano Mar 29 '23 at 05:41
  • The condition looks weird: `if (Sleep == ECUSleep(SaveAdr, BkpData) == 1) {` - do you mean `if ((Sleep = ECUSleep(SaveAdr, BkpData)) == 1) {` ? – mmixLinus Mar 29 '23 at 06:50
  • Please post complete code containing all variable declarations. We cannot guess what types all variables in your snippet have and it's highly relevant to your question. – Lundin Mar 29 '23 at 08:38

2 Answers2

0

Is the FLASH_EraseOptionBytes(); completing?
Have you tried reading the Option bytes after FLASH_EraseOptionBytes() just to check they are erased?
Is it possible that the MSB is being corrupted, i.e it's being written to before it's fully erased.

What do you get if you run FLASH_ProgramOptionHalfWord(0x1FFFF804, 0x08AE); ?

Mike
  • 419
  • 3
  • 7
0

Sorry it's taken so long. I haven't had the time. I have come back with fresh eyes and realised the absolute blunder I have made.

I have 1 byte which as far as I know can store a value up to 255. I was trying to store values over 3000. Mystery solved. Still learning. If you can't tell

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 30 '23 at 11:55