AnsweredAssumed Answered

Alternate function remapping, OPT bytes, and PWM2

Question asked by lopez.pedro.001 on May 30, 2012
Latest reply on Jun 4, 2012 by lopez.pedro.001
Hi, since i dont get a response in discovery forum, i will repaste here. 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_ProgramOptionByte(OPT2, 0x02);    
FLASH_ProgramOptionByte(OPT2+1, 0xFD);

with no luck, even I started to get problems with SWIM, it said that opt byte complement was different. Anyway using STVP I was able to remove that stuff. I was able to make it work by flashing my code and then chaning the opt byte with STVP....

Another problem is that after it works (0x02 in OPT2 register) if I read it I 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).


I dont know what is wrong.

Btw, after I change OPT2 to 0x02 I start to get SWIM error 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.


The problem appears in line 1 .

Checking the function:

01.void TIM2_OC3Init(TIM2_OCMode_TypeDef TIM2_OCMode, 
02.                  TIM2_OutputState_TypeDef TIM2_OutputState, 
03.                  u16 TIM2_Pulse, 
04.                  TIM2_OCPolarity_TypeDef TIM2_OCPolarity) 
06.    /* Check the parameters */ 
07.    assert_param(IS_TIM2_OC_MODE_OK(TIM2_OCMode)); 
08.    assert_param(IS_TIM2_OUTPUT_STATE_OK(TIM2_OutputState)); 
09.    assert_param(IS_TIM2_OC_POLARITY_OK(TIM2_OCPolarity)); 
10.    /* Disable the Channel 1: Reset the CCE Bit, Set the Output State, the Output Polarity */ 
11.    TIM2->CCER2 &= (u8)(~( TIM2_CCER2_CC3E  | TIM2_CCER2_CC3P)); 
12.    /* Set the Output State & Set the Output Polarity */ 
13.    TIM2->CCER2 |= (u8)((TIM2_OutputState  & TIM2_CCER2_CC3E   ) |  (TIM2_OCPolarity   & TIM2_CCER2_CC3P   )); 
15.    /* Reset the Output Compare Bits & Set the Output Compare Mode */ 
16.    TIM2->CCMR3 = (u8)((TIM2->CCMR3 & (u8)(~TIM2_CCMR_OCM)) | (u8)TIM2_OCMode); 
18.    /* Set the Pulse value */ 
19.    TIM2->CCR3H = (u8)(TIM2_Pulse >> 8); 
20.    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 STVP

no project 
Hardware: ST-LINK 
Programming mode: SWIM 
Device name: STM8S105x6 
Port: USB 
[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.  

I tried with this too, but no luck for now

#define OPT2  0x4803  
 //FLASH_ProgramOptionByte(OPT2+1, 0xFD);
 FLASH_ProgramOptionByte(OPT2, 0x02); 

I still getting 0xFD in 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).


In last things, read value is sent to a u16 variable where high is normal value and low is complemented value, so thats ok, but i'm still getting errors from STVP and STVD when i program them. I have sent the questions to my stm8 provider