Dear all
I recently start programming STM32F103VB Arm based MCU, writing simple blinking led on my own HW for testing. it was OK, but i feel something goes wrong, for the reason writing so simple codes to test the outputs of mcu as follows:
#define ch1_led 8 void set_ports(void) { GPIO_PortClock(GPIOA,ENABLE); GPIO_PortClock(GPIOB,ENABLE); GPIO_PortClock(GPIOC,ENABLE); GPIO_PortClock(GPIOE,ENABLE); GPIOA->CRH &= ~(0xFul); // Set Port A.8 as USB_Mode Select GPIOA->CRH |= (0x1ul); // Output 10 Mhz PushPull Delay(1); GPIOB->CRH &= ~(0xFFul<<20); // Set Port B.13 as Sck and B13 as MISO GPIOB->CRH |= (0x83ul<<20); // Set Otput 50 Mhz PushPull for port B13 // Input for B14 GPIOB->ODR |= (1ul<<14); // Set Pullup input for Port B.14 GPIOB->BSRR |= (1ul<<29); // Set Sck to high GPIOC->CRL &= (0xFFul<<16); // Set Port C.0/C.1/C.2/C.3 as Channels LED and // C.6/C.7 as A2D C.S. and Fo Mode GPIOC->CRL |= (0x11001111ul); // Output 10 Mhz PushPull GPIOC->BSRR = (0x11ul<<6); // Set C.6 to disable A2D (CS Active Low) C.7 // to High Means Fo=50Hz GPIOC->CRH &= ~(0xFFul); // Set Port C.8 as A2d Gain and C.9 as USB LED GPIOC->CRH |= (0x11ul); // Output 10 Mhz PushPull GPIOE->CRH &= ~(0xFFFFul); // Set Port E.8/E.9/E.10/E.11 as MUX Selector GPIOE->CRH |= (0x1111ul); // Output 10 Mhz PushPull } void led_on(int ch) { unsigned long led; led=ch; GPIOC->BSRR=led; } int main(void) { SystemInit(); SystemCoreClockSetHSI(); SystemCoreClockUpdate(); set_ports(); led_on(ch1_led); while (1); }
it should turn on the led for ever but a 4 ms glitch on output with period of about 425 ms makes the led blink invisibly. does anyone could explain me why and how could prevent of such a glitches ?
best regards
It behaves more like if the processor constantly restarts.
Are you really sure that you do have that while loop at the end of mail()? And that you haven't any enabled w-dog timer? (Note - you may not write the word w-a-t-c-h-d-o-g on the forum, because the forum will then fail to accept your post because of a stupid spam filter rule).
Dear Per
I placed while loop at the end of main() procedure, but I'm not sure about W.D. , may be the SystemInit(); SystemCoreClockSetHSI(); SystemCoreClockUpdate(); functions enable the W.D. which i should check, do you know the exact job of those functions? (against of W.D.)
best Regards
Would have thought CMSIS code would have called SystemInit() before main(). The while(1); is fine, it stops the code dropping out of main() and going who knows where.
Is this using some commercial board? or some home brewed board?
If you scope the NRST/NRESET line is it stable and high while this behaviour is observed?
As Per suggests, perhaps you have other code enabling a IWDG or WWDG.
Tried using a debugger?
I found that IWDG make the system reset by reloadig the register in while loop;
while (1) IWDG->KR = 0xAAAA;
this is not fine code, I'm trying to find a better way to disable this type reset. is there any solution?
best regards;
Thanks of all
finding that updating option byte in programmer solved my reset problem.
best regards to all