cancel
Showing results for 
Search instead for 
Did you mean: 

Debug problem in Keil

Linda
Associate II
Posted on June 22, 2014 at 18:08

Hi,

I am debugging my project. I can ''step one line'' each time to walk through it, but when I let it run freely, or ''step over the current line'', or ''step out of current function'', it crash.

Please help.
15 REPLIES 15
Posted on June 22, 2014 at 21:30

Crash how and where? Where is it when you hit stop?

If you end up in the Hard Fault Handler, and that's just a while(1) loop then you need to use a better handler like the one's demonstrated by Joseph Yiu. When you can see the faulting assembler instructions, and the processor registers you might better place to describe the failure.

Do you have all the interrupt handlers in place? Is your stack big enough?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Linda
Associate II
Posted on June 22, 2014 at 21:38

It is not end up in the Hard Fault Handler. When I hit the stop, it go to: line 431 of  startup_stm32f429xx.s

~~~~~~~~~~~

                B       .

                ENDP

                ALIGN

~~~~~~~~~~~~~~~~~~~~~~~

I am using Keil to debug STM32F429 i Discovery.

If stack is not big enough, how to fix it?

Posted on June 22, 2014 at 22:44

I'd suspect you have enabled an interrupt for which you don't provide an IRQHandler (stm32f4xx_it.c?)

The stack is defined in startup_stm32f4xx.s, but you're not getting a Hard Fault
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Linda
Associate II
Posted on June 23, 2014 at 00:33

Further information:

It crash when I call ADC second times. The code is:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  /* Check if ADC peripheral is disabled in order to enable it and wait during

     Tstab time the ADC's stabilization */

  if((hadc->Instance->CR2 & ADC_CR2_ADON) != ADC_CR2_ADON)

  {  

    /* Enable the Peripheral */

    __HAL_ADC_ENABLE(hadc);

    

    /* Delay inserted to wait during Tstab time the ADC's stabilazation */

    for(; i <= 540; i++)

    {

      __NOP();

    }

  }

~~~~~~~~~~~~~~~~~~~

It stays in the loop of _NOP();

Linda
Associate II
Posted on June 24, 2014 at 08:43

Dear Clive 1,

Yes, I did enable a interup of ADC_DMA, but how to add a IRQHandler in stm32f4xx_it.c? The following is some code in ADC_DMA:

~~~~~~~~~~~~~~~~~~~

/* Definition for ADCx clock resources */

#define ADCx                            ADC3

#define ADCx_CLK_ENABLE()               __ADC3_CLK_ENABLE()

#define DMAx_CLK_ENABLE()               __DMA2_CLK_ENABLE()     

#define ADCx_CHANNEL_GPIO_CLK_ENABLE()  __GPIOC_CLK_ENABLE()

     

#define ADCx_FORCE_RESET()              __ADC_FORCE_RESET()

#define ADCx_RELEASE_RESET()            __ADC_RELEASE_RESET()

/* Definition for ADCx Channel Pin */

#define ADCx_CHANNEL_PIN                GPIO_PIN_3

#define ADCx_CHANNEL_GPIO_PORT          GPIOC

/* Definition for ADCx's Channel */

#define ADCx_CHANNEL                    ADC_CHANNEL_13

/* Definition for ADCx's DMA */

#define ADCx_DMA_CHANNEL                DMA_CHANNEL_2

#define ADCx_DMA_STREAM                 DMA2_Stream0         

/* Definition for ADCx's NVIC */

#define ADCx_DMA_IRQn                   DMA2_Stream0_IRQn

#define ADCx_DMA_IRQHandler             DMA2_Stream0_IRQHandler

/** @addtogroup STM32F4xx_HAL_Examples

  * @{

  */

/** @addtogroup ADC_RegularConversion_DMA

  * @{

  */

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

/* ADC handler declaration */

ADC_HandleTypeDef    AdcHandle;

/* Variable used to get converted value */

__IO uint16_t uhADCxConvertedValue=1;

/* Private function prototypes -----------------------------------------------*/

//static void SystemClock_Config(void);

static void Error_Handler(void);

extern float Efact ;

/* Private functions ---------------------------------------------------------*/

/**

  * @brief  Main program.

  * @param  None

  * @retval None

  */

void ADCmain(void)

{

  ADC_ChannelConfTypeDef sConfig;

 

  /* STM32F4xx HAL library initialization:

       - Configure the Flash prefetch, instruction and Data caches

       - Configure the Systick to generate an interrupt each 1 msec

       - Set NVIC Group Priority to 4

       - Global MSP (MCU Support Package) initialization

     */

//  HAL_Init();

//  /* Configure the system clock to have a system clock = 144 Mhz */

//  SystemClock_Config();

 

  /* Configure LED3 and LED4 */

//  BSP_LED_Init(LED3);

//  BSP_LED_Init(LED4);

 

  /*##-1- Configure the ADC peripheral #######################################*/

  AdcHandle.Instance          = ADCx;

 

  AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;

  AdcHandle.Init.Resolution = ADC_RESOLUTION12b;

  AdcHandle.Init.ScanConvMode = DISABLE;

  AdcHandle.Init.ContinuousConvMode = ENABLE;

  AdcHandle.Init.DiscontinuousConvMode = DISABLE;

  AdcHandle.Init.NbrOfDiscConversion = 0;

  AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

  AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;

  AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;

  AdcHandle.Init.NbrOfConversion = 1;

  AdcHandle.Init.DMAContinuousRequests = ENABLE;

  AdcHandle.Init.EOCSelection = DISABLE;

      

  if(HAL_ADC_Init(&AdcHandle) != HAL_OK)

  {

    /* Initiliazation Error */

    Error_Handler();

  }

 

  /*##-2- Configure ADC regular channel ######################################*/  

  sConfig.Channel = ADCx_CHANNEL;

  sConfig.Rank = 1;

  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;

  sConfig.Offset = 0;

~~~~~~~~~~~~~~~~~~`

Thanks a lot

Linda
Associate II
Posted on June 24, 2014 at 18:13

I add these lines in the code of stm32f4xx_it.c:

extern ADC_HandleTypeDef             AdcHandle;

extern ADC_HandleTypeDef            ADCx_DMA_IRQn;

extern ADC_HandleTypeDef            ADCx_DMA_IRQHandler;

But it is still the same problem.

Please help.

Thanks

Posted on June 24, 2014 at 20:07

I'm not even sure that makes sense to do.

Do you have a void ADCx_DMA_IRQHandler(void) routine? And does it show up in the .MAP file as DMA2_Stream0_IRQHandler?

If you don't have this function, and linkage to it, the interrupt is going to go to that ''B .'' loop and die.

Do you have any other interrupts which are not being handled?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Linda
Associate II
Posted on June 24, 2014 at 23:41

I h�?ve �?tt�?ched the .M�?�? file. C�?uld y�?u �?le�?se check it?

Th�?nks

________________

Attachments :

STM32F429I-Discovery.map : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I02A&d=%2Fa%2F0X0000000bSs%2F._q11dSauuM7u8CyKEAxdB5GglRvPz33V6p3_HX7bB4&asPdf=false
Posted on June 25, 2014 at 03:16

Ok, your stm32f4xx_it.c is not including the defines for the ADC configuration, consequently the ADCx_DMA_IRQHandler name is not be substituted with DMA2_Stream0_IRQHandler, and the body code for the handler is being discarded.

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