程序造成cannot access memory的问题

2019-07-21 04:27发布

我烧写了一段程序造成了芯片无法再次烧写一直提示cannnot access memory或者cannot entry debug mode,最开始我还以为是硬件问题,结果换上一块芯片又是这样,程序很简单,也没有复用jtag引脚怎么会这样呢


main:
[mw_shl_code=c,true]int main(void){ Set_System(); SystemInit(); RCC_init(); GPIO_init(); USB_Interrupts_Config(); usart3_init(); USB_Init(); while(1){ } }[/mw_shl_code] [mw_shl_code=c,true]Set_System[/mw_shl_code] [mw_shl_code=c,true]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); }[/mw_shl_code]
[mw_shl_code=c,true]SystemInit,官方system_stm32f10x.c文件中[/mw_shl_code] RCC_init [mw_shl_code=c,true]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); }[/mw_shl_code] GPIO_init
[mw_shl_code=c,true]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); }[/mw_shl_code]
[mw_shl_code=c,true]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); }[/mw_shl_code]
[mw_shl_code=c,true]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); }[/mw_shl_code]
[mw_shl_code=c,true]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(); }[/mw_shl_code]







总体上就那么几个部分,比较不明白的是为什么会出现这种情况,我仔细看了一下代码,可能的原因有2个:一个是 Set_System();SystemInit();两个函数重复的初始化了时钟,另一个是管教初始化重复了(有一段重复了). 我想问一下到底是什么情况会遇到这种问题来注意让以后不要在发生,然后如何修复这个问题?不换新的芯片的话






友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
7条回答
jimmjimm
1楼-- · 2019-07-21 06:16
 精彩回答 2  元偷偷看……
正点原子
2楼-- · 2019-07-21 08:40
试试简单的代码,比如跑马灯吧.
正点原子
3楼-- · 2019-07-21 11:33
回复【3楼】jimmjimm:
---------------------------------
不能写的时候,B0接3.3V试试。
正点原子
4楼-- · 2019-07-21 16:49
回复【5楼】jimmjimm:
---------------------------------
Bunny17
5楼-- · 2019-07-21 18:28
留下脚印,等着备用
董董
6楼-- · 2019-07-21 23:25
 精彩回答 2  元偷偷看……

一周热门 更多>