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.

3
  • 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? Commented Mar 29, 2023 at 5:41
  • The condition looks weird: if (Sleep == ECUSleep(SaveAdr, BkpData) == 1) { - do you mean if ((Sleep = ECUSleep(SaveAdr, BkpData)) == 1) { ? Commented Mar 29, 2023 at 6: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. Commented Mar 29, 2023 at 8:38

2 Answers 2

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); ?

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.