2016-06-19 01:14 PM
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);
///////////////////////////////////////////////////
}
2016-06-19 01:59 PM
2016-06-19 04:17 PM
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.2016-06-19 09:51 PM
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);
}
}
2016-06-21 09:05 AM
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...].2016-06-21 09:54 AM
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.2016-06-21 07:14 PM
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