cancel
Showing results for 
Search instead for 
Did you mean: 

Flash write protection for STM32f103zc

hemant
Associate II
Posted on May 22, 2009 at 07:21

Flash write protection for STM32f103zc

4 REPLIES 4
hemant
Associate II
Posted on May 17, 2011 at 13:12

Hello,

I want to store calibration constants on the Flash, and then write protect that page.

I could store calibration constants using Flash Write routines using PDL ver2.0.3 sample code.

But when i tried the sample code from PDL ver. 2.0.3 to ''write protect the flash'', it gave FLASHSTATUS = FLASH_ERROR_PG, during debug (& standalone also)

The write protect the code did NOT work and write protect option byte was =0xFFFFFFFF.

The code is as follows:.....

//------------------------------------------------------------------------

myHardwareInit();

FLASHStatus = FLASH_COMPLETE;

MemoryProgramStatus = PASSED;

Data = 0x1753;

EraseCounter = 0x0;

/* Unlock the Flash Program Erase controller */

FLASH_Unlock();

/* Define the number of page to be erased */

NbrOfPage = (EndAddr - StartAddr) / FLASH_PAGE_SIZE;

FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP|FLASH_FLAG_PGERR |FLASH_FLAG_WRPRTERR);

/* Get pages write protection status */

WRPR_Value = FLASH_GetWriteProtectionOptionByte();

ProtectedPages = WRPR_Value & 0x000000C0;

if (ProtectedPages != 0x00)

{/* Pages not write protected */

/* Enable the pages write protection */

FLASHStatus = FLASH_EnableWriteProtection(FLASH_WRProt_Pages12to13 |FLASH_WRProt_Pages14to15);

/* Generate System Reset to load the new option byte values */

NVIC_GenerateSystemReset();

}

//------------------------------------------------------------------------

when executed it always resets the system.

Can someone help?????

Hemant.

16-32micros
Associate III
Posted on May 17, 2011 at 13:12

Hi Hemant,

You can check first that your HSI ( internal High Speed RC) is Enabled and not disabled else the Flash programming will fail.

the Reset the system at the end is normal as you have issued a system reset :) by calling NVIC_GenerateSystemReset() routine.

Cheers,

STOne-32.

hemant
Associate II
Posted on May 17, 2011 at 13:12

Hello,

Meanwhile i tried Read protection for the device and landed up with more trouble.

Now, i can NOT even program the flash. The worst part is that it shows that the flash is erased and NOT protected, still it does not program.

Please refer to the dump produced in the Eclipse IDE....

Open On-Chip Debugger 0.1.0 (2009-01-21-21:15) Release

BUGS? Read

http://svn.berlios.de/svnroot/repos/openocd/trunk/BUGS

$URL:

https://svn.berlios.de/svnroot/repos/openocd/tags/openocd-0.1.0/src/openocd.c

$

500 kHz

500 kHz

Info : JTAG tap: stm32.cpu tap/device found: 0x3ba00477 (Manufacturer: 0x23b, Part: 0xba00, Version: 0x3)

Info : JTAG Tap/device matched

Info : JTAG tap: stm32.bs tap/device found: 0x06414041 (Manufacturer: 0x020, Part: 0x6414, Version: 0x0)

Error: JTAG tap: stm32.bs got: 0x06414041 (mfg: 0x020, part: 0x6414, ver: 0x0)

Error: JTAG tap: stm32.bs expected 1 of 1: 0x16410041 (mfg: 0x020, part: 0x6410, ver: 0x1)

Error: trying to validate configured JTAG chain anyway...

Info : JTAG tap: stm32.cpu tap/device found: 0x3ba00477 (Manufacturer: 0x23b, Part: 0xba00, Version: 0x3)

Info : JTAG Tap/device matched

Info : JTAG tap: stm32.bs tap/device found: 0x06414041 (Manufacturer: 0x020, Part: 0x6414, Version: 0x0)

Error: JTAG tap: stm32.bs got: 0x06414041 (mfg: 0x020, part: 0x6414, ver: 0x0)

Error: JTAG tap: stm32.bs expected 1 of 1: 0x16410041 (mfg: 0x020, part: 0x6410, ver: 0x1)

Error: trying to validate configured JTAG chain anyway...

target state: halted

target halted due to debug-request, current mode: Handler HardFault

xPSR: 0x01000003 pc: 0xfffffffe

verify Capture-IR is disabled

target state: halted

target halted due to debug-request, current mode: Handler HardFault

xPSR: 0x01000003 pc: 0xfffffffe

Info : device id = 0x10016414

Error: SWJ-DP STICKY ERROR

Error: dcb_dhcsr 0x30003, nvic_shcsr 0x20000, nvic_cfsr 0x1, nvic_bfar 0xe000edf8

Warn : STM32 flash size failed, probe inaccurate - assuming 512k flash

Info : flash size = 512kbytes

stm32x mass erase complete

Error: SWJ-DP STICKY ERROR

Error: dcb_dhcsr 0x30003, nvic_shcsr 0x20000, nvic_cfsr 0x1, nvic_bfar 0xe000edf8

Error: SWJ-DP STICKY ERROR

Error: dcb_dhcsr 0x30003, nvic_shcsr 0x20000, nvic_cfsr 0x1, nvic_bfar 0xe000edf8

Warn : Block read error address 0x8000000, count 0x100

unknown error when checking erase state of flash bank #0 at 0x08000000

# 0: 0x00000000 (0x800 2kB) erased

# 1: 0x00000800 (0x800 2kB) erased

# 2: 0x00001000 (0x800 2kB) erased

Note: the same message for sectors 3 to 252 are removed to save space

#253: 0x0007e800 (0x800 2kB) erased

#254: 0x0007f000 (0x800 2kB) erased

#255: 0x0007f800 (0x800 2kB) erased

successfully checked protect state

#0: stm32x at 0x08000000, size 0x00080000, buswidth 0, chipwidth 0

# 0: 0x00000000 (0x800 2kB) not protected

# 1: 0x00000800 (0x800 2kB) not protected

# 2: 0x00001000 (0x800 2kB) not protected

# 3: 0x00001800 (0x800 2kB) not protected

Note: the same message for sectors 3 to 252 are removed to save space

#253: 0x0007e800 (0x800 2kB) not protected

#254: 0x0007f000 (0x800 2kB) not protected

#255: 0x0007f800 (0x800 2kB) not protected

stm32x (High Density) - Rev: Z

Error: timed out while waiting for target halted

Error: error executing stm32x flash write algorithm

Error: flash writing failed with error code: 0xfffffc7a

Error: error writing to flash at address 0x08000000 at offset 0x00000000 (-902)

The program segments i used is attached herewith.

Regards,

Hemant.

gareth
Associate II
Posted on May 17, 2011 at 13:12

I got around this by adding a different programming algorithm (STM32F10x Flash Options) to the target options. (this is in uVision) Their seems to be a different algorhthm for the flash options bytes, adding this, together with the STM32F10xOPT.s file helped. I did have to remove the normal programming algorithm and run jst this one first before adding back in both to get it working.

hope this helps