cancel
Showing results for 
Search instead for 
Did you mean: 

software error keeps mcu in reset

ionutF
Associate III
Posted on November 01, 2016 at 15:11

Recently I have observed an odd phenomenon: I have a code (which I believe is faulty) , I program the MCU (which initially is fully erased ) with that code; 

after that the MCU can not be reprogrammed by programming environment (CooCox IDE).

So I have to use ST Link utility to erase the chip using connection under reset method, and after this CooCox can reprogram the MCU.(but just once)

If i remove from the source code the function which I believe is causing this behaviour , CooCox can reprogram my chip as many times as I want.

The MCU used is the one found on STM32F072 Disco Board.

The source code is :

int main(void)

{

  /*!< At this stage the microcontroller clock setting is already configured,

       this is done through SystemInit() function which is called from startup

       file (startup_stm32f0xx.s) before to branch to application main.

       To reconfigure the default setting of SystemInit() function, refer to

       system_stm32f0xx.c file

     */

gpio_config();

  /* Infinite loop */

u8 i=0;

  while (1)

{ }

}

void gpio_config(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

EXTI_InitTypeDef EXTI_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

GPIO_StructInit(&GPIO_InitStructure);

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOF,ENABLE);

/* Enable SYSCFG clock for EXTI controller */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

 GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_DOWN;

 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;//50MHz

 // PB3,4,12,13,14,15 PA8..13; PF6

 GPIO_InitStructure.GPIO_Pin = D1_Pin|SegA_Pin|SegB_Pin|SegD_Pin|SegE_Pin;

 GPIO_Init(GPIOA, &GPIO_InitStructure);

 GPIO_InitStructure.GPIO_Pin = D2_Pin|D3_Pin|D4_Pin|SegC_Pin|SegG_Pin;

 GPIO_Init(GPIOB, &GPIO_InitStructure);

 GPIO_InitStructure.GPIO_Pin = SegF_Pin;

/GPIO_Init(GPIOF, &GPIO_InitStructure);

 //K1 , K2 relays pins

 GPIO_InitStructure.GPIO_Pin = K1Pin|K2Pin;

 GPIO_InitStructure.GPIO_Mode = GPIO_OType_PP;

 GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_DOWN;

 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;//50MHz

 GPIO_Init(RelayPort, &GPIO_InitStructure);

 //buttons

 GPIO_InitStructure.GPIO_Pin= SW1Pin|SW2Pin|SW3Pin;

 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

 GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_DOWN;

 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;//50MHz

 GPIO_Init(SWPort, &GPIO_InitStructure);

//buttons interrupts

/* Configure EXTI7 line */

EXTI_InitStructure.EXTI_Line = EXTI_Line7;

EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;

EXTI_InitStructure.EXTI_LineCmd = ENABLE;

EXTI_Init(&EXTI_InitStructure);

 /* Configure EXTI6 line */

EXTI_InitStructure.EXTI_Line = EXTI_Line6;

EXTI_Init(&EXTI_InitStructure);

 /* Configure EXTI5 line */

EXTI_InitStructure.EXTI_Line = EXTI_Line5;

EXTI_Init(&EXTI_InitStructure);

 /* Enable and set EXTI4..15 Interrupt to the lowest priority */

 NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn;

 NVIC_InitStructure.NVIC_IRQChannelPriority = 0;

 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

 NVIC_Init(&NVIC_InitStructure);

}

and that it is all. USE_FULL_ASSERT is disabled 

phenomenon

phenomenon

1 REPLY 1
Posted on November 01, 2016 at 15:39

Pasting code without defines tends to limit static analysis

From the comments it suggests you use PA13 (SWDIO) which is part of the debug interface. Reprogramming the pins will break the debugger connectivity.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..