Question
Alternate function remapping, OPT bytes, and PWM2
Posted on May 24, 2012 at 16:39
Hi again, i'm trying to set a pin to an alternate remapping pin, exactly i'm using TIM2 with PWM and i want channels in D2, D3 and D4. I have tried with this:
#define OPT2 0x4803
FLASH_Unlock (FLASH_MEMTYPE_DATA);
FLASH_ProgramOptionByte(OPT2, 0x02);
FLASH_ProgramOptionByte(OPT2+1, 0xFD);
FLASH_Lock (FLASH_MEMTYPE_DATA);
with no luck, evenI started to get problems with SWIM, it said that opt byte complement was different. Anyway using STVPI was able to remove that stuff. I was able to make it work byflashing my code and then chaning the opt byte with STVP....
Another problem is that after it works (0x02 in OPT2 register) ifI read itI get the complemented value (0xFD), so i tried to read data memory positions 0x4801, 0x4802, 0x4804 and 0x4805 with no luck (none of them was 0x02).
k=FLASH_ReadOptionByte(OPT2);
I dont know what is wrong.
Btw, afterI change OPT2 to 0x02I start to get SWIMerror messages (Error: Swim error [30007]: swim communicator error), but you can start debugging it and go step by step ... I get that error only if i press RUN or CONTINUE.
If you continue you get Error: gdi-error [40127]: flash memory not accessible while core is running.
......
1.
TIM2_OC3Init(TIM2_OCMODE_PWM2, TIM2_OUTPUTSTATE_ENABLE,CCR3_Val, TIM2_OCPOLARITY_LOW );
2.
TIM2_OC3PreloadConfig(ENABLE);
.....
The problem appears in line 1
#alternate-remapping-swim-opt2