打印
[STM32F0]

STM32F030XX烧录不了啊,求救!!!

[复制链接]
7130|14
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主

void MemoryRemapConfig(void)
{
        uint32_t i = 0;
        uint32_t Data,Address;

//        VectorTable = (unsigned int *)0x20000000;  //RAM
  for(i = 0; i < 48; i++)
  {
    Data=*(__IO unsigned int*)(0x08000000+i*4);
                Address=0x20000000+(i*4);
                *(__IO unsigned int*)Address=(uint32_t)Data;
  }
  /* Enable the SYSCFG peripheral clock*/
//  RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  /* Remap SRAM at 0x00000000 */
        SYSCFG_MemoryRemapConfig(SYSCFG_MemoryRemap_SRAM);//RAM映射到0x0000 0000

}

void I2C_Configuration(void)
{
  I2C_InitTypeDef  I2C_InitStruct;

  GPIO_InitTypeDef  GPIO_InitStruct;
        NVIC_InitTypeDef NVIC_InitStructure;
       
        /* Enable  GPIOA clock */
          RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);       
//         /* Configure the I2C clock source. The clock is derived from the HSI */
//   RCC_I2CCLKConfig(RCC_I2C1CLK_HSI);      
  /*!< sEE_I2C Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2 , ENABLE);

/* Connect PXx to I2C_SCL*/
  GPIO_PinAFConfig( GPIOB , GPIO_PinSource10, GPIO_AF_1);
  /* Connect PXx to I2C_SDA*/
   GPIO_PinAFConfig( GPIOB ,GPIO_PinSource11, GPIO_AF_1);
  /*!< GPIO configuration */  
  /*!< Configure sEE_I2C pins: SCL */
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
                GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
                GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStruct.GPIO_Speed = GPIO_Speed_Level_3;
  GPIO_Init(GPIOB , &GPIO_InitStruct);
  
  /*!< Configure sEE_I2C pins: SDA */
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11;
  GPIO_Init(GPIOB , &GPIO_InitStruct);
       
         
        NVIC_InitStructure.NVIC_IRQChannel = I2C2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
//        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);               
         
  /* I2C configuration */
        I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStruct.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
  I2C_InitStruct.I2C_DigitalFilter = 0x00;
  I2C_InitStruct.I2C_OwnAddress1 =0x00;
  I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;       
  I2C_InitStruct.I2C_Timing = 0x60801B30;//0x10D05D84;100KHz
  /* Apply I2C configuration after enabling it */
  I2C_Init(I2C2, &I2C_InitStruct);
  /* I2C Peripheral Enable */
  I2C_Cmd(I2C2, ENABLE);

}

void Dmx_Config(void)
{
                GPIO_InitTypeDef  GPIO_InitStructure;
                USART_InitTypeDef USART_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
                                               
                RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOB, ENABLE);
                RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE );
       
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;//control
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
                GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
                GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_Init(GPIOC, &GPIO_InitStructure);
                                               
                GPIO_PinAFConfig(GPIOB,GPIO_PinSource6,GPIO_AF_0);
                GPIO_PinAFConfig(GPIOB,GPIO_PinSource7,GPIO_AF_0);        
/*               
                *  USART1_TX -> PB6, USART1_RX ->        PB7
                */
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //发送引脚              
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
                GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
                GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_Init(GPIOB, &GPIO_InitStructure);   

                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;                 
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
                GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
                GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
                GPIO_Init(GPIOB, &GPIO_InitStructure);  
               
                NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
                NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
        //        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
                NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
                NVIC_Init(&NVIC_InitStructure);               
                       
                USART_InitStructure.USART_BaudRate = 250000;//设置串口波特率
                USART_InitStructure.USART_WordLength = USART_WordLength_9b;//设置数据位
                USART_InitStructure.USART_StopBits = USART_StopBits_1;//设置停止位
                USART_InitStructure.USART_Parity = USART_Parity_No;//设置效验位
                USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//设置流控制
                USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//设置工作模式
                USART_Init(USART1, &USART_InitStructure); //配置入结构体

                USART_Cmd(USART1, ENABLE);//使能串口1
                USART_ClearITPendingBit(USART1, USART_IT_TC);
                USART_ITConfig(USART1, USART_IT_TC, ENABLE);
                USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
}

void Panel16v8_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  /* Enable the GPIO Clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
       
  /* Configure the GPIO pin 输出*/
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
       
        GPIO_InitStructure.GPIO_Pin = (1 << DD_SCK);
        GPIO_Init(GPIOpinCM006SCK, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin = (1 << DD_MOSI);
        GPIO_Init(GPIOpinCM006MOSI, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = (1 << PinCM006Hold0);
        GPIO_Init(GPIOpinCM006Hold0, &GPIO_InitStructure);
        GPIO_InitStructure.GPIO_Pin = (1 << PinCM006Hold1);
        GPIO_Init(GPIOpinCM006Hold1, &GPIO_InitStructure);
        GPIO_InitStructure.GPIO_Pin = (1 << PinCM006Hold2);
        GPIO_Init(GPIOpinCM006Hold2, &GPIO_InitStructure);
        GPIO_InitStructure.GPIO_Pin = (1 << PinCM006Hold3);
        GPIO_Init(GPIOpinCM006Hold3, &GPIO_InitStructure);
       
//输入
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
//  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//GPIO_PuPd_NOPULL;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Pin = 1 << PinCM006KeyMenu;
        GPIO_Init(GPIOpinCM006KeyMenu, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = 1 << PinCM006KeyIncrease;
        GPIO_Init(GPIOpinCM006KeyIncrease, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = 1 << PinCM006KeyDecrease;
        GPIO_Init(GPIOpinCM006KeyDecrease, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = 1 << PinCM006KeyEnter;
        GPIO_Init(GPIOpinCM006KeyEnter, &GPIO_InitStructure);
       


       
}



void PFIO_Config(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  /* Enable the GPIO Clock */
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOC, ENABLE);

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

// 电机驱动
       
        GPIO_InitStructure.GPIO_Pin  = (1 << PinMotorDriveEnable);
        GPIO_Init(GPIOpinMotorDriveEnable, &GPIO_InitStructure);
        MotorDriveDisable();

//输入
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
       
        GPIO_InitStructure.GPIO_Pin = (1 << PinPanHomeSense);          // Pan
        GPIO_Init(GPIO_PanHomeSense, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin = (1 << PinTiltHomeSense);    // Tilt
        GPIO_Init(GPIO_TiltHomeSense, &GPIO_InitStructure);       

// MIC AD
       

        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN ;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Pin = (1 << PinAD);
        GPIO_Init(GPIOpinAD, &GPIO_InitStructure);       
       
}



void IoInitial(void)
{
       
                /*--------系统时钟设置 20000 == 50us*/
        if (SysTick_Config(SystemCoreClock / 20000))
  {
   while (1);
  }
        MemoryRemapConfig();//升级用的?
       
        I2C_Configuration();
        Dmx_Config();
       
        AdcInitial();
        PFIO_Config();
        Panel16v8_Config();
}
我程序的初始化时这样的,一开始板子是刚焊好,没程序的,烧录进去之后,重新烧写就不行了。是不是我增加了MemoryRemapConfig();//升级用的?这里导致后面用STlink连接都连接不上

有谁知道吗,搞不明白了
沙发
戈卫东| | 2016-5-30 23:06 | 只看该作者
应该不是吧?没有仔细看。
可能是JTAG/SWD管脚被占了?

使用特权

评论回复
板凳
泰山特曲123| | 2016-5-31 12:42 | 只看该作者
用镊子将芯片的复位脚短接到地,让他保持复位,然后再用st link擦除

使用特权

评论回复
地板
wahe2008| | 2016-5-31 16:10 | 只看该作者
可能是软件复位失灵了,手动复位一下看看

使用特权

评论回复
5
xmshao| | 2016-5-31 16:12 | 只看该作者
可能你的代码起作用了。
你代码里到底做了些什么知道否?

你长按住复位键,没键用镊子也行,然后点击TARGET/connect ,同时松开复位,应该可以连上的。

使用特权

评论回复
6
mohanwei| | 2016-5-31 18:34 | 只看该作者
不用看了,肯定是你没接nReset这个引脚
其它系列接SWCLK,SWDIO,GND这3个针就行。F0要加上nReset

使用特权

评论回复
7
lizhenming|  楼主 | 2016-5-31 19:07 | 只看该作者
xmshao 发表于 2016-5-31 16:12
可能你的代码起作用了。
你代码里到底做了些什么知道否?

如果跑程序的时候那两个引脚需要作为IO口使用,程序怎么设置SWD

使用特权

评论回复
8
lizhenming|  楼主 | 2016-5-31 19:07 | 只看该作者
mohanwei 发表于 2016-5-31 18:34
不用看了,肯定是你没接nReset这个引脚
其它系列接SWCLK,SWDIO,GND这3个针就行。F0要加上nReset ...

不关reset的事呢

使用特权

评论回复
9
desertsailor| | 2016-6-1 22:22 | 只看该作者
lizhenming 发表于 2016-5-31 19:07
如果跑程序的时候那两个引脚需要作为IO口使用,程序怎么设置SWD

如果下载口的IO在应用程序中配置为输出的模式可能导致这种情况,但此时仍可用串口下载程序,如果非得使用这些IO,建议在系统初始化之前加一定时间的延时,确保芯片上电后有一段时间下载口IO是没有配置为输出模式的,这样下载程序时只要按压板子上的复位按钮,然后再迅速使用仿真器连接就可以下载了。

使用特权

评论回复
10
xmshao| | 2016-6-2 15:07 | 只看该作者
lizhenming 发表于 2016-5-31 19:07
如果跑程序的时候那两个引脚需要作为IO口使用,程序怎么设置SWD

你如果想把SWD的那两个脚做IO是也可以的,通过GPIOX_MODER配置就好

对于空片的话,第一次用SWD口烧录的话没啥不方便。 当第二次烧录SWD口被当io用的程序时可能有点不方便。但也能烧,摁住复位键,连接的同时释放复位键也可以。

当然,你也可以通过其它串口ISP的方式进行程序烧录。

使用特权

评论回复
11
flydream0| | 2016-6-2 17:40 | 只看该作者
3种方法任你选择:
1: 确保烧录器有连接reset线,在STM32 ST-Link Utility工具下
Targett->Settings->Mode 下拉列表选择 Connect Under Reset
这样在烧录试试。

2 手动按住reset不放,在点击烧录的瞬间放开,没试个20次不要说已经试过了。

3 使用串口bootloader ISP 工具将芯片擦除后再烧录。

使用特权

评论回复
12
lizhenming|  楼主 | 2016-6-15 11:53 | 只看该作者
desertsailor 发表于 2016-6-1 22:22
如果下载口的IO在应用程序中配置为输出的模式可能导致这种情况,但此时仍可用串口下载程序,如果非得使用 ...

按住RESET,迅速放开是可以的,但是这样太麻烦了,我不想在板子上搞个复位按钮,因为这样太麻烦了,延时一段时间应该是可以的

使用特权

评论回复
13
flydream0| | 2016-6-15 12:08 | 只看该作者
Connect Under Reset,界面提示这个,你有没有试下?记得要连上复位线。

使用特权

评论回复
14
E-Kaia| | 2016-6-15 22:24 | 只看该作者
你用的是什么样的下载硬件了?

使用特权

评论回复
15
capturesthe| | 2016-6-16 08:35 | 只看该作者
和程序没关系,开始我用stlink也下载不了,后来用cmsis-dap就可以了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

22

主题

127

帖子

2

粉丝