2012-05-24 07:39 AM
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
2012-05-24 08:01 AM
I tried with this too, but no luck for now
#define OPT2 0x4803
FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);
FLASH_Unlock (FLASH_MEMTYPE_DATA);
//FLASH_ProgramOptionByte(OPT2+1, 0xFD);
FLASH_ProgramOptionByte(OPT2, 0x02);
FLASH_Lock (FLASH_MEMTYPE_DATA); FLASH.
k=FLASH_ReadOptionByte(OPT2);
I still getting 0xFDin k variable. Maybe the read option byte function returns the complemented value, i will check it.
But then when i debug i continue getting the 2 errors that i commented in previous port (communication and flash problems).
2012-05-24 08:10 AM
The problem is here
void TIM2_OC3Init(TIM2_OCMode_TypeDef TIM2_OCMode,
TIM2_OutputState_TypeDef TIM2_OutputState,
u16 TIM2_Pulse,
TIM2_OCPolarity_TypeDef TIM2_OCPolarity)
{
/* Check the parameters */
assert_param(IS_TIM2_OC_MODE_OK(TIM2_OCMode));
assert_param(IS_TIM2_OUTPUT_STATE_OK(TIM2_OutputState));
assert_param(IS_TIM2_OC_POLARITY_OK(TIM2_OCPolarity));
/* Disable the Channel 1: Reset the CCE Bit, Set the Output State, the Output Polarity */
TIM2->CCER2 &= (u8)(~( TIM2_CCER2_CC3E | TIM2_CCER2_CC3P));
/* Set the Output State & Set the Output Polarity */
TIM2->CCER2 |= (u8)((TIM2_OutputState & TIM2_CCER2_CC3E ) | (TIM2_OCPolarity & TIM2_CCER2_CC3P ));
/* Reset the Output Compare Bits & Set the Output Compare Mode */
TIM2->CCMR3 = (u8)((TIM2->CCMR3 & (u8)(~TIM2_CCMR_OCM)) | (u8)TIM2_OCMode);
/* Set the Pulse value */
TIM2->CCR3H = (u8)(TIM2_Pulse >> 8);
TIM2->CCR3L = (u8)(TIM2_Pulse);
}
Just on line 13
-> Continue...
** Application stopped: Breakpoint 4, TIM2_OC3Init (TIM2_OCPolarity=TIM2_OCPOLARITY_LOW, TIM2_Pulse=750, TIM2_OutputState=TIM2_OUTPUTSTATE_ENABLE,
-> Step over source...Error: gdi-error [40127]: flash memory not accessible while core is running
** Application stopped
And this is what i get when trying to read using STVPPROJECT:
no project
CONFIGURATION:
Hardware: ST-LINK
Programming mode: SWIM
Device name: STM8S105x6
Port: USB
PROGRAM MEMORY status:
[0x008000 - 0x00FFFF]
No File
Not programmed
Memory checksum: 0x0
DATA MEMORY status:
[0x004000 - 0x0043FF]
No File
Not programmed
Memory checksum: 0x0
OPTION BYTE status:
No File
Not programmed
Option byte 0: 00
Option byte 1: 00
Option byte 2: 00
Option byte 3: 00
Option byte 4: 00
Option byte 5: 00
Option byte 6: 00
Option byte 7: 00
Option byte 8: 00
Memory checksum: 0x0
Hardware configuration set to <
ST-LINK
on USB with STM8S105x6 plugged in and SWIM protocol>.
Blank check before programming (when available) is OFF
Verify after programming is ON.
Clear memory before loading a file is ON.
Erase device memory before programming (when available) is OFF
Display a popup window when an error occurs is OFF
Log activity is OFF
> Reading PROGRAM MEMORY area...
Error : Error on Option Bytes (complementary bytes). Reprogram Option Bytes of device
Error : < PROGRAM MEMORY reading failed.
Error : < Operation aborted.