cancel
Showing results for 
Search instead for 
Did you mean: 

My MCU works fine in debug mode but out of debug mode it suddenly fails

parisa
Senior
Posted on March 25, 2017 at 21:09

Hi,

Something is driving me crazy.

Actually I have written a program that

it:

receive 100chars each 60ms from USART1 and 2 with RXNE interrupt(baudrate 57600)

receive100chars each 100ms from Ethernet with PHY and after processing it sends to USARTs port with TXNE interrupt

sends 120 chars to PC via Ethernet each 100ms with Timer.

it works fine when I connect my board via st-link in debug mode but when I get off out of debug mode it works for 1-2 hours and suddenly hangs and disables Ethernet communication.In this states I can't realize what  my problem is.

what is your idea about this strange states? why it works fine in debug mode?

Thanks in advance

20 REPLIES 20
Posted on March 25, 2017 at 22:00

The debugger will configure aspects of the hardware it needs, you may be depending on these.

Make sure you have initialized all the peripheral clocks you need.

Check also pins, and thing that may be altered by slightly different timings.

Use a USART to output diagnostic information, this will be independent of the debugger attachment, and also let you output register information so you can compare and contrast the two conditions.

Check the state of the BOOT0 pin.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal
Posted on March 26, 2017 at 11:38

I'm wondering the implementation of receiving ETH string pushed to UART TX by interrupt:

receive100chars each 100ms from Ethernet with PHY and after processing it sends to USARTs port with TXNE interrupt

Make sure in the implementation that each interrupt is very short in time. 

Make sure the mecanics to exchange information between main loop and interrupts, between interrupts if any.

For each interrupt ISR, toggle a unique GPIO pin to monitor what's happening.

Add SW checks for malfunctions such as buffer overflow or if cyclical snake biting tails situation...

You could also accelerate (stress) the code in debug mode to try to duplicate the phenomenon... or try to make it worse to understand how to make it better.

In general, for variables used in interrupt and used outside ISR, try 'volatile' or make sure one side 'sets' the other side 'resets' flags. If the phenomenon occurs rarely, does is always happen after the same amount of time? Is it random?

Another phenomenon might depends on the compiler. Is the toolchain having 'debug' and 'release' compile option with different optimisation by compiler? Are the global variables cleared by the 'C Startup' and the 'release' flavour skips this?

These are just thoughts, it is challenging to figure it out. Try to implant debugging schemes to find out the rootcause.

Max
ST Employee
Posted on March 27, 2017 at 03:52

I also suggest you check the errata of the MCU you are using. 

Hardware bugs often manifest as timing related or rare/sporadic failures...

regards,

Max

parisa
Senior
Posted on March 27, 2017 at 20:37

Dear Clive one Thanks for your replay.You are the best teacher ever.

Actually I think that I've config all peripheral clocks carefully and I check their operation when they work and communication with other MCU.In addition I pulled down Boot0 with a 10k resistor.

for example for Here is my config:

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD |RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOA |RCC_APB2Periph_AFIO,ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);

    GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE);

    RCC_HSEConfig(RCC_HSE_ON);

    while(RCC_WaitForHSEStartUp()==ERROR);

    

    RCC_PREDIV2Config(RCC_PREDIV2_Div5);

    RCC_PLL2Config(RCC_PLL2Mul_8);

    RCC_PLL2Cmd(ENABLE);

    

    while(RCC_GetFlagStatus( RCC_FLAG_PLL2RDY)!=SET);

    

    RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2,RCC_PREDIV1_Div5);    

    RCC_PLLConfig(RCC_PLLSource_PREDIV1,RCC_PLLMul_9);

    RCC_PLLCmd(ENABLE);

    

    while(RCC_GetFlagStatus( RCC_FLAG_PLLRDY)!=SET);

    

    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    RCC_HCLKConfig(RCC_SYSCLK_Div1);

    RCC_PCLK1Config(RCC_HCLK_Div2);

    RCC_PCLK2Config(RCC_HCLK_Div1);

    

    while (RCC_GetSYSCLKSource() != 0x08);

    

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);

    NVIC.NVIC_IRQChannel = USART1_IRQn;

    NVIC.NVIC_IRQChannelPreemptionPriority =2;

    NVIC.NVIC_IRQChannelSubPriority = 0;

    NVIC.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC);

    

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);

    NVIC.NVIC_IRQChannel = USART3_IRQn;

    NVIC.NVIC_IRQChannelPreemptionPriority = 2;

    NVIC.NVIC_IRQChannelSubPriority = 1;

    NVIC.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC);    

    

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);

    NVIC.NVIC_IRQChannel = TIM2_IRQn;

    NVIC.NVIC_IRQChannelPreemptionPriority = 3;

    NVIC.NVIC_IRQChannelSubPriority = 0;

    NVIC.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC);   

Dear KIC8462852 EPIC204278916

Thanks for your excelent tips and explanation

And here is my network config

    netInitialize ();

    sock_tcp = netTCP_GetSocket (tcp_cb_func);

    if (sock_tcp >= 0) {

      netTCP_Listen (sock_tcp, 4050);

    netTCP_SetOption (sock_tcp, netTCP_OptionTimeout, 10);

    }

uint32_t tcp_cb_func (int32_t socket, netTCP_Event event,const NET_ADDR *addr, const uint8_t *buf, uint32_t len) {

   switch (event) {

    case netTCP_EventConnect:DataAvailable=0;return (1);

    case netTCP_EventData:DataAvailable=1;Len=len;memcpy(Message, buf,len);netTCP_ResetReceiveWindow(sock_tcp);break;

        }

  return (0);

}

and In the man project I only check if DataAvailable=1 then send Characters with USART

    if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET)

  {

            if(Count<=130 && Transfer==1){

                if(Msg[Count]=='\0' ){USART_ITConfig(USART1, USART_IT_TXE, DISABLE);Transfer=0;}    

                    USART_SendData(USART1,Msg[Count]);    

                    Uount=Count+1;             

            }            

            else

            {

                    Transfer=0;

                    USART_ITConfig(USART1, USART_IT_TXE, DISABLE);

            }

    }

All my variables that I think that I maybe use them in ISR I declared them volatile and I use keil without any optimization. I will check again my interrupts with different LEDs.

would it be possible that ground wire between Ethernet and my board cause a problem during process?something like this:

0690X00000606dmQAA.png

and Dear max thanks for you tip that I never pay attention to them before. is it possible how can I define for my MCU(stm32f10x)?

Thanks in advance

Posted on March 28, 2017 at 05:01

There are erratasheets for most microcontrollers describing functional problems discovered on the device.

You can find it on the product page on ST.COM in the erratasheet section. You can also get it using the

http://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-utilities/st-mcu-finder.html

in the doc and resources section.

For example you will find the

http://www.st.com/content/ccc/resource/technical/document/errata_sheet/8d/85/aa/39/f4/58/40/e8/CD00238166.pdf/files/CD00238166.pdf/jcr:content/translations/en.CD00238166.pdf

on the

http://www.st.com/content/st_com/en/products/microcontrollers/stm32-32-bit-arm-cortex-mcus/stm32f1-series/stm32f105-107/stm32f105r8.html

page. It has erratas for the USART and the Ethernet.

You should check that you are not falling into one of them...

Posted on March 28, 2017 at 07:05

Dear Max , Thanks for your useful information about MCU peripheral activity and your good program suggestion.

Actually I have used SPL library for Ethernet communication and I trust it that it doesn't violate any Hardware and software criteria.

Thanks a lot again for your explanation and contributions

AvaTar
Lead
Posted on March 28, 2017 at 09:45

it works fine when I connect my board via st-link in debug mode but when I get off out of debug mode it works for 1-2 hours and suddenly hangs and disables Ethernet communication.In this states I can't realize what  my problem is.

I'm not sure if there is a causality - meaning, it would probably fail in the debugger as well. But hardly any one  - including me - does that long debug watch sessions.

Beside the already given recommendations, I suspect an application problem. Especially ethernet is quite capable of flooding your MCU with interrupts & data. Depending on the network environment, the traffic is hardly predictable.

You might get rare ethernet overflows if a UART interrupt takes too long, or from the ethernet interrupt alone. If your code doesn't handle this conditions properly, communication stops. It would be revealing to know where exactly the MCU is if the error occurs, either in 'normal' working code or a fault handler.

I wouldn't even rule out a 'normal' fault like stack overflow or access to illegal addresses, triggered by your error conditions.

Perhaps instrumenting your code and inspecting the output helps.

parisa
Senior
Posted on March 31, 2017 at 20:04

Thanks all for your comments and help

Actually I haven't fix Ethernet disconnection yet. I will thank you see my codes and if there is no problem help me to fix my mistakes.

0690X00000606glQAA.png

https://www.4shared.com/rar/RT93A6MKca/1_online.html

 

Thanks in advance

parisa
Senior
Posted on April 03, 2017 at 08:20

Thanks for your replay and your contribution

Here is

user name:

mailto:parisa.mohamadi227@gmail.com

password:stm32forum

I have set USART and Timer different interrupt priorities. But I didn't set anything for ETH , doesn't SPL Ethernet library set it correctly at high priority?