cancel
Showing results for 
Search instead for 
Did you mean: 

Call to Systick_config causes program to hang

ea6987
Associate II
Posted on June 19, 2016 at 22:14

Once I comment out the call to systick it all works as expected, any idea why?

I have an Stm32f103c8t6 64kb but Keil thinks its 128kb I changed it to 64 in the debugger settings but aside from that I'm not sure what else needs changing or if that is causing the problem. Some googling mention something about liker scripts, I am afraid I am not far enough into this endeavor to know what that is

#include ''stm32f10x.h''
//prototypes
void GPIO_initialize(void);
void USART_initlialize(void);
int putChar(int);
int main ()
{
SystemInit();
//SysTick_Config(1000);
GPIO_initialize();
USART_initlialize();
volatile int i ;
while(1)
{
for(i=0; i<=2000000;i++);
GPIOC->BSRR = 1<<
13
;
for(
i
=
0
; i<=2000000;i++);
GPIOC->BSRR = 1<<
29
;
putChar('o');
}
}
int putChar(int c)
{
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART1->DR = (c & 0xff);
return 1; 
}
int getChar(void)
{
while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET) ;
return USART1->DR&0xff;
}
void USART_initlialize()
{
//initialize GPIOA, ALternate FUnction Clock , UART1
//RCC->APB2ENR |= (1<<
14
) | (1<<0) | (1<<2);
//same as above, using STDPeripheral Library
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA ,ENABLE);
//initialize UART settings
USART_InitTypeDef myUART; 
USART_StructInit(&myUART);
myUART.USART_BaudRate
= 
9600
; 
myUART.USART_Mode
= 
USART_Mode_Rx
| USART_Mode_Tx ;
USART_Init(USART1, &myUART);
USART_Cmd(USART1 , ENABLE);
}
void GPIO_initialize()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA ,ENABLE);
RCC->APB2ENR |= 1<<4; 
GPIO_InitTypeDef myGPIO;
GPIO_StructInit(&myGPIO);
myGPIO.GPIO_Pin = GPIO_Pin_13;
myGPIO.GPIO_Mode = GPIO_Mode_Out_PP;
myGPIO.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOC, &myGPIO);
//initialize TX///////////////////////////////////
GPIO_InitTypeDef uartGPIO;
GPIO_StructInit(&uartGPIO);
uartGPIO.GPIO_Pin = GPIO_Pin_9 ;
uartGPIO.GPIO_Speed = GPIO_Speed_50MHz ;
uartGPIO.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &uartGPIO);
/////////////////////////////////////////////////
//initialize RX
GPIO_InitTypeDef rxGPIO;
GPIO_StructInit(&rxGPIO);
rxGPIO.GPIO_Pin = GPIO_Pin_10;
rxGPIO.GPIO_Mode =GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA , &rxGPIO);
///////////////////////////////////////////////////
}

6 REPLIES 6
matic
Associate III
Posted on June 19, 2016 at 22:59

Did you step the program under debug and see where does it hang? Maybe your initialize functions for GPIO and USART use SysTick as some kind of delay (I saw that in HAL functions) and if you reconfigure SyStick before, the program could stuck somewhere inside of these functions.

Step the program and see exactly where does it stuck.

Posted on June 20, 2016 at 01:17

The SPL doesn't use the ticker. You shouldn't need to call SystemInit() unless you have some broken CMSIS implementation (ie CooCox)

I don't like the C++ syntax style here, are you sure there isn't some issue with, or errant code in SysTick_Handler ?

Code is generally a bit of a jumble.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ea6987
Associate II
Posted on June 20, 2016 at 06:51

I started a new project, without any STDPeriph support, to just toggled an led .

If i do not call Systick all works as expected even the caveman 'for-loop' delay however when I call systick andproceed tostep through the code, I noticethe systick function sets the clock to 72Mhz, anywyas it exits out of systick just fine. So I thought well since its changing the clock let me add a longer delay so I iterate the for-loop with all kinds of numbers and no discernable blinking of the LED. , furthermore if I step through the code with higher numbers in my for-loop it just hangs there. if I enter a 1 or 2 or 3 for my for loop iterations (for(I=0;i<=3;i++) and I step through this code it works just fine I see the led blink obviously in debug mode ... Below is ALL my user generated code. nothing more nothing less, from me So why is it hanging in my for loop after calling systick? I would like to make use of it , but ive hit this wall now..


#include ''stm32f10x.h''


int main ()

{

volatile uint32_t i;

SystemInit();

SysTick_Config(1000);


//GPIOC CLOCK ENABLE

RCC->APB2ENR |= 1<<
4
;


//GPIOC OUT PP PIN13

GPIOC->CRH &= ~(1<<
23
);

GPIOC->CRH &= ~(1<<
22
);


//GPIOC 2MHz PIN13

GPIOC->CRH |= (1<<
21
);

GPIOC->CRH &= ~(1<<
20
);


while(1)

{

for(
i
=
0
;i<=200000;i++);

GPIOC->BSRR = (1<<
29
);

for(
i
=
0
;i<=200000;i++);

GPIOC->BSRR = (1<<13);

} 

}

Chris1
Senior III
Posted on June 21, 2016 at 18:05

Presumably you are enabling the Systick interrupt.

What's in your Systick interrupt handler function?

Perhaps once that interrupt occurs, the handler is executing [forever...].

Posted on June 21, 2016 at 18:54

And when you hit STOP in the debugger where exactly is it?

Perhaps there is a problem with your SysTick Handler? If the issue is there looking at the code provided isn't going to help.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ea6987
Associate II
Posted on June 22, 2016 at 04:14

Indeed the issue was the handler function or lack of, i could have sworn there was a dummy function somewhere that would be called if i did not provide a handler function myself. Anyways lesson learned, i litterally jumped the gun and compiled my code before writing the handler function and once i saw unexpected behavior i stopped writing code and started debugging not imagining my issue was that i needed to keep writing. Nevertheless thanks because the handler function was not crossing my mind because like i said i thought it was being handled by a dummy function