An_RF_Newbie
Member level 3
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.
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
}
}