cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103RCT6 simple blinking led problem.

LDani.1
Associate

Hi. First of all I want to thank you for giving time to this post. When i create bare metal program for blinking an LED don't work. The LED don't blink but when i enter DEBUG Mode with KEIL uVision the bit 0 in ODR resgister for GPIOC toggle every 1 second but the LED wont bright at all even though the ODR bit 0 is set.

Same program made with CubeMX (Clock initialization generated by CubeMX but without generating code for GPIO) same problem.

The only way to make the LED to blink is when i use HAL Library and CubeMX to configure the specific GPIOC bit.

Bellow i attached code. I would be very grateful if you could help me. I am sorry for my bad English.

#include "stm32f10x.h"
 
 
void Config(void);
void Delay_in_ms(uint16_t valoare);   //Timer count on each 1 ms 
 
 
int main()
{
	Config();          //Peripheral configuration
	while(1)
	{
		
		GPIOC->BSRR |= 1<<0;            // Set pin0 of GPIOC
		Delay_in_ms(1000);
		GPIOC->BSRR |= 1<<16;           // Cleat pin0 of GPIOC
		Delay_in_ms(1000);
		
	}
	
}
 
 
 
 
void Delay_in_ms(uint16_t valoare)
{
	TIM6->ARR = (valoare)*10;    // Load ARR register with the value needed in delay(ms)
	TIM6->CR1 |= 1<<0;           // Enable TIM6 (now TIM6 start counting)
	while(!(TIM6->SR));					 // Stays here until UEV has been set so the counter reached the desired value in ms)
	TIM6->SR = 0;								 // Clear flag
}
 
void Config(void)
{
	// Flash Config
	FLASH->ACR |= 1<<4;                   	// Enable prefetch buffer
	while( !((FLASH->ACR)&(1<<5)) );      	// Stays here until prefetch buffer is enabled.
	FLASH->ACR |= 1<<1;											// Set LATENCY to 2 wait states
	
	// RCC Config
	RCC->CR |= 1<<16;												// Enable high-speed external clock (HSE)
	while( !((RCC->CR)&(1<<17)) );        	// Stays here until HDE Clock is ready to use
	RCC->CFGR |= ((1<<20)|(1<<16)|(1<<10)); // Configure the PLL (multiply input of PLL by 4, select HSE as PLL input clock, and divide the APB1 clock by 2)
	RCC->CR |= 1<<24;												// Enable PLL
	while( !((RCC->CR)&(1<<25)) );					// Stays here until PLL PLL get locked (when PLL locked, exit the loop)
	RCC->CFGR |= 1<<1;											// Select PLL_Clock as System Clock (SYSCLK)
	while( !((RCC->CFGR)&(1<<3)) );         // Stays here until PLL is used as system clock (if PLL drives the SYSCLK then exit loop)
	
	// TIM6 Config (Basic timer config used to generate delays in ms)
	RCC->APB1ENR |= 1<<4;                   // Enable clock for TIM6_Basic_Timer
	TIM6->CR1 |= ((1<<7)|(1<<3)|(1<<2));    // Enable buffering for ARR, Counter stops counting at the next UEV, only under/over flow generates UEV
	TIM6->PSC  = 7199;        							// Timer count each 100us which is equivalent to 0.1 ms
	
	// GPIOC Config ( PC0, PC1, PC2 output with PU )
	RCC->APB2ENR |= ((1<<4)|(1<<2)|(1<<5));    // Activeaza ceasul pentru PORT_C
	GPIOC->CRL |= ((1<<1)|(1<<5)|(1<<9));          // PC0 & PC1 & PC2 output push-pull
	
	
}

1 ACCEPTED SOLUTION

Accepted Solutions

Read out and check the GPIO registers in debugger. Compare them between working and non-working version.

JW

View solution in original post

3 REPLIES 3

Read out and check the GPIO registers in debugger. Compare them between working and non-working version.

JW

LDani.1
Associate

Hi. Thank you for your response. I found out that the CRL register  has 0x44444444 at reset so all pins was configured as AF.

Thanks for coming back with the solution.

Please select your post as Best so that the thread is marked as solved.

JW