I have written my code for STM32F103C8T6 board in Keil using the adequate startup files. I wrote directly to the memory addresses using information from the datasheet but the ST-Link upload seems to upload the hex file to the wrong addresses for example:
GPIOA = 0x4001 0800
This is according to the STM datasheet. But ST-Link shows the device data range from:
0x0800 0000 to 0x0800 03d4.
My code is a simple program to blink the LED at portA1. I connected the LED across a 10k resistor. Why is STM assigning the wrong addresses when I used pointers to specify the memory locations, or could there be any other mistakes. Code below.
void delay(int a);
int main(void)
{
unsigned int* GPIO_A;
GPIO_A = (unsigned int*)0x40010800 ; // Assigning GPIOA to the correct memory location
unsigned int* GPIO_A_CRL;
GPIO_A_CRL = GPIO_A + 0x00 ; // Assigning GPIO_A_CRL to the correct memory location
/*unsigned int* GPIO_A_IDR;
GPIO_A_IDR = GPIO_A + 0X08 ; // Assigning GPIO_A_IDR to the correct memory location */
unsigned int* GPIO_A_BSRR;
GPIO_A_BSRR = GPIO_A + 0X10 ; // Assigning GPIO_A_BSRR to the correct memory location
unsigned int* GPIO_A_BRR;
GPIO_A_BRR = GPIO_A + 0X14 ; // Assigning GPIO_A_BSRR to the correct memory location
unsigned int* RCC_APB2ENR;
RCC_APB2ENR = (unsigned int*)(0x40021000 + 0X18) ; // Assigning RCC_APB2ENR to the correct memory location
*RCC_APB2ENR = 0X04; // Set clock for GPIOA
*GPIO_A_CRL = 0X00008888 ; // Defining pin modes for GPIO_A_CRL
while(1) // infinite loop
{
*GPIO_A_BSRR = 0X00000002; // Set bit 1 to 1
delay(2); // delay
*GPIO_A_BRR = 0x00000002; // reset bit 1 to reset value(0)
delay(2); // delay
}
}
void delay(int a)
{
long b = a*1000000;
for(int i=0;i<b;i++)
{
int c = 1;
}
}