Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] STM32f103 wont start

Status
Not open for further replies.

An_RF_Newbie

Member level 3
Joined
Sep 1, 2020
Messages
65
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
525
Hello,
I designed a simple board based on STM32F103 and produce some of them and all of them work fine. In my new design I use PB4 and PA8 pins but other parts of my circuit is the same as the old one. However, the old program doesn't work properly( I can program my MCU correctly (it verifies my program after programming) and I can see a 8Mhz sine wave on OSC1 and OSC2(200mV peak-to-peak). But the MCU won't run anything. I need to know what causes this problem. Here is my simple program (not my main program) which doesn't work too.

C:
''' #include <stdio.h> #include <string.h> #include "stm32f10x_gpio.h" #include "stm32f10x_rcc.h"

void GPIOSYS(void){ GPIO_InitTypeDef GPIOStruc;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
//GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);


GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);


RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);


GPIOStruc.GPIO_Mode=GPIO_Mode_Out_PP;
GPIOStruc.GPIO_Pin=GPIO_Pin_7 | GPIO_Pin_0 | GPIO_Pin_1 ;
GPIOStruc.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIOStruc);

GPIOStruc.GPIO_Mode=GPIO_Mode_IPU;
GPIOStruc.GPIO_Pin=GPIO_Pin_6 ;
GPIOStruc.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIOStruc);


GPIO_PinRemapConfig(GPIO_Remap_USART2,ENABLE);
//GPIO_PinRemapConfig(GPIO_Remap_USART2,DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);


GPIOStruc.GPIO_Mode=GPIO_Mode_IPU; GPIOStruc.GPIO_Pin=GPIO_Pin_5 ; GPIOStruc.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIOStruc);    //UDP 1 input

GPIOStruc.GPIO_Mode=GPIO_Mode_Out_PP; GPIOStruc.GPIO_Pin=GPIO_Pin_6 ; GPIOStruc.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIOStruc);    //Define UDP

GPIOStruc.GPIO_Mode=GPIO_Mode_IPU; GPIOStruc.GPIO_Pin=GPIO_Pin_7 ; GPIOStruc.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIOStruc);

GPIOStruc.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIOStruc.GPIO_Pin=GPIO_Pin_11; GPIOStruc.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOB,&GPIOStruc);
GPIOStruc.GPIO_Mode=GPIO_Mode_Out_PP;
GPIOStruc.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_10;
GPIOStruc.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIOStruc);

GPIOStruc.GPIO_Mode=GPIO_Mode_IPD;
GPIOStruc.GPIO_Pin=GPIO_Pin_3;
GPIOStruc.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIOStruc);

GPIO_SetBits(GPIOA,GPIO_Pin_2);
GPIO_ResetBits(GPIOA,GPIO_Pin_6); //Is not TCP   

}

void CLOCK(void){ RCC_HSEConfig(RCC_HSE_ON); while(RCC_WaitForHSEStartUp()==ERROR);
FLASH_SetLatency(FLASH_Latency_0);

RCC_PLLCmd(DISABLE);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,9);
RCC_PLLCmd(ENABLE);

while(RCC_GetFlagStatus( RCC_FLAG_PLLRDY)!=SET);

FLASH_SetLatency(FLASH_Latency_2);

RCC_ClockSecuritySystemCmd(ENABLE);
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);


RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK is = SYSCLK
RCC_PCLK1Config(RCC_HCLK_Div2); // PCLK is 30MHZ, and timer3 clk should be 2x PCLK ( 60 MHZ)
RCC_PCLK2Config(RCC_HCLK_Div2);


while (RCC_GetSYSCLKSource() != 0x08);
SystemCoreClockUpdate();

}

void Delay(){ int i; for(i=0;i<5;i++); }

void delay(){ int i,j; for(i=0;i<100;i++); for(j=0;j<1;j++); }

void LDelay(){ int i,z; for(z=0;z<=20;z++) for(i=0;i<1000;i++); }

int main(void){ int i; CLOCK(); GPIOSYS();
GPIO_SetBits(GPIOA,GPIO_Pin_10);  //PC
GPIO_SetBits(GPIOB,GPIO_Pin_0); //UDP
GPIO_SetBits(GPIOB,GPIO_Pin_1); //UDP

//  SysTick_Config(SystemCoreClock / (14000));
while(1){
delay();
GPIO_SetBits(GPIOA,GPIO_Pin_10); //PC
delay();
GPIO_ResetBits(GPIOA,GPIO_Pin_10); //PC

}

}
 

I'm sorry for the curiosity, but which compiler/IDE is using it?
 

Hi,

I'd say there is a bigger chance that the cause is a hardware problem than a software problem.

Klaus
 

My curiosity is just to know which compiler or IDE, so that I can test this code on my pc.
 

Hi,

I'd say there is a bigger chance that the cause is a hardware problem than a software problem.

Klaus
Thank you very much. it was the clock configuration problem and I am wonder how the old one works.

I am using the keil editor with SPL library.
 

Hi,

I'm glad you found the issue.

Wrong clock configuration (and other issues) does not mean it immediately stops to work.
It may work on one chip, but not with another, ...it may work at one temperature it may work with one power supply...but seem to randomly refuse to work, thus such problems may be hard to find.

Klaus
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top