i write a short program into my mcu then i cause keil cant not write program again always shows cannot access memory and cannot entry debug mode, it not cause by hardware i sure, two board with same problem and i check my program not use jtag port also there are my program codes:
main: int main(void){ Set_System(); SystemInit(); RCC_init(); GPIO_init(); USB_Interrupts_Config(); usart3_init(); USB_Init(); while(1){ } }
Set_System: void Set_System(void) { RCC_DeInit(); /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp();
if (HSEStartUpStatus == SUCCESS) {
/* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2);
/* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */ RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */ while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { }
/* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) { } } else { while (1) { } }
/* enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); }
SystemInit, in file system_stm32f10x.c
RCC_init void RCC_init(void){ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB|RCC_APB1Periph_USART3, ENABLE); RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5); }
GPIO_init void GPIO_init(void){ GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; //¾àÀëָʾºìµÆ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_SetBits(GPIOB,GPIO_Pin_15);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //¾àÀëָʾÂÌµÆ GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_ResetBits(GPIOC,GPIO_Pin_13);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //¾àÀëָʾÀ¶µÆ GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_ResetBits(GPIOB,GPIO_Pin_8);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; //״ָ̬ʾºìµÆ GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_SetBits(GPIOC,GPIO_Pin_14);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //״ָ̬ʾÂÌµÆ GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_ResetBits(GPIOC,GPIO_Pin_13);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //test_LED GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_ResetBits(GPIOB,GPIO_Pin_5);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; //¾àÀëָʾºìµÆ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //usb test GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_SetBits(GPIOA,GPIO_Pin_8);
}
void USB_Interrupts_Config(void)
{ NVIC_InitTypeDef NVIC_InitStructure;
/* 2 bit for pre-emption priority, 2 bits for subpriority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
/* Enable the USB interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }
void usart3_init(void){ GPIO_InitTypeDef GPIO_InitStruct; USART_InitTypeDef USART_InitStruct; NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //¿ªIOʱÖÓ
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStruct); // tx
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11; // Rx GPIO_Init(GPIOB, &GPIO_InitStruct);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);//¿ªUSARTʱÖÓ USART_InitStruct.USART_BaudRate = 38400; USART_InitStruct.USART_StopBits = USART_StopBits_1; USART_InitStruct.USART_WordLength = USART_WordLength_8b; USART_InitStruct.USART_Parity = USART_Parity_No; USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; USART_Init(USART3, &USART_InitStruct); USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);//ʹÄܽÓÊÕÖÐ¶Ï USART_Cmd(USART3, ENABLE);//ʹÄÜ´®¿Ú3
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
void USB_Init(void) { pInformation = &Device_Info; pInformation->ControlState = 2; pProperty = &Device_Property; pUser_Standard_Requests = &User_Standard_Requests; /* Initialize devices one by one */ pProperty->Init(); }
there are content of my codes, i check found two problem re-init rcc clock and re-init gpio i think re-init gpio should not cause this problem so is this problem cause by re-init rcc clock? and how to solve it without replace a new mcu?
To help your fellow forum followers, it helps if you
put persnickety problem code in "pre" tags
__asm volatile ( //"headSP:\n\t" "push {r0,r1,r2,r3}\n\t"
see:
http://www.keil.com/forum/tips.asp