cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4-Discovery - problem with debugging in RAM

st-com
Associate
Posted on December 08, 2013 at 15:56

Hello, I'm using CooCox IDE. I have problem with debugging in RAM and USART communication on STM32F4-Discovery. When I load my program to FLASH all works correctly , data transmit and LEDs on PD12-PD15 switch on but when I check ''Debug in RAM'' in Configuration Link Tab, LEDs on PD12-PD15 switch on but there is no data transmission. Thanks in advance.

Here is my code:

&sharpinclude ''stm32f4xx.h''

void init_RCC(void);

void init_GPIO(void);

void init_USART(void);

void USART_puts(USART_TypeDef* USARTx, volatile char *s);

void Delay(__IO uint32_t nCount);

int main(void)

{

    init_RCC();

    init_GPIO();

    init_USART();

    GPIO_SetBits(GPIOD, GPIO_Pin_12);

    GPIO_SetBits(GPIOD, GPIO_Pin_13);

    GPIO_SetBits(GPIOD, GPIO_Pin_14);

    GPIO_SetBits(GPIOD, GPIO_Pin_15);

    while(1)

    {

        USART_puts(USART6, ''COOCOX \r'');

        Delay(0xFFFFF);

    }

}

void init_RCC(void)

{

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD, ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);

}

void init_GPIO(void)

{

    GPIO_InitTypeDef GPIO_InitStruct;

    /* init  USART */

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP ;

    GPIO_Init(GPIOC, &GPIO_InitStruct);

    GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);

    //init LED

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13 | GPIO_Pin_12;

    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;

    GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

    GPIO_Init(GPIOD, &GPIO_InitStruct);

}

void init_USART(void)

{

    USART_InitTypeDef USART_InitStructure;

    USART_InitStructure.USART_BaudRate = 9600;

    USART_InitStructure.USART_WordLength = USART_WordLength_8b;

    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_Tx;

    USART_Init(USART6, &USART_InitStructure);

    USART_Cmd(USART6, ENABLE);

}

void USART_puts(USART_TypeDef* USARTx, volatile char *s)

{

    while(*s)

    {

        while(USART_GetFlagStatus(USARTx,USART_FLAG_TXE) == RESET);

        USART_SendData(USARTx, *s);

        *s++;

    }

}

void Delay(__IO uint32_t nCount) {

  while(nCount--) {

  }

}

#stm32 #stm32f4 #discovery #usart
2 REPLIES 2
Posted on December 08, 2013 at 18:31

So what can you learn about the failure by single stepping the code in the debugger?

You might want to inquire on CooCox's forum about specifics about their linker script settings, and the behaviour of the debugger and scripts related to RAM usage.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
st-com
Associate
Posted on December 08, 2013 at 19:35

Thanks for the reply. I looked deeper into code with single stepping and here are results:

the problem is in this part:

while(USART_GetFlagStatus(USARTx,USART_FLAG_TXE) == RESET);

USART_SendData(USARTx, *s);

In the first loop cycle there is no problem but after sending first letter (in my case 'C' from 'COOCOX') program stucks in the part of code where USART_FLAG_TXE is checking. Of course this 'C' letter isn't really transmitted.

  if ((USARTx->SR & USART_FLAG) != (uint16_t)RESET)

  {

    bitstatus = SET;

  }

  else

  {

    bitstatus = RESET;

  }