This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Xtal is <undefined

Hi,

in MDK 3.40 Xtal is <undefined>.How can I solve this problem?

Parents Reply Children
  • Dear Hans,

    Please see the attached photo. My problem is I want to define my clock frequency in keil uvision but Keil doesn't let me, it shows <undefined>.  For example, I write simple blink code, if I can't choose xtal frequency, it doesn't work correctly. Is there an alternative for choosing xtal frequency in keil uvision? I put the code below.

    I want to blink my LED in 1 second.

    #include "stm32f10x.h" // Device header


    void delay(int rep);

    int main(void)
    {
    RCC->APB2ENR |= 0x10; /// Or 0b10000 --> Anabling Preiph GPIOC
    GPIOC->CRH &= 0xFF0FFFFF; /// Reset the PORT C PIN 13
    GPIOC->CRH |= 0x00300000; /// Set Port C PIN 13 as Output
    GPIOC->ODR |= 0x2000; /// Set Port C Pin 13
    while(1)
    {
    /// Blinking the Port C pin 13
    GPIOC->ODR |= 0x2000;
    delay(10);
    GPIOC->ODR &= ~0x2000;
    delay(10);

    }

    }


    /// Random time delay Function
    void delay(int rep)
    {
    for(;rep>0;rep--)
    {
    int i;
    for(i=0; i< 100000;i++)
    {}
    }
    }

  • Hi,

    The definition provided above is not crucial, as you can configure it directly in your code.

    This configuration is specifically for the STM32F103C8 microcontroller, utilizing an 8 MHz external clock and setting the system frequency to 36 MHz. Please note that this information is based on my previous code, which I have copied here for reference.

    void CLOCK(void){
        
        RCC_DeInit();     
        
        RCC_LSICmd(ENABLE);
        while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == SET);
        
        RCC_HSEConfig(RCC_HSE_ON);
        
        while(RCC_WaitForHSEStartUp() != SUCCESS){}
            
                
        FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);    
        FLASH_SetLatency(FLASH_Latency_2);    
        
            
        RCC_HCLKConfig(RCC_SYSCLK_Div1);    
        RCC_PCLK1Config(RCC_HCLK_Div2);                         
        RCC_PCLK2Config(RCC_HCLK_Div1);                        
            
        
            
        RCC_PLLCmd(DISABLE);
            
        RCC_PLLConfig(RCC_PLLSource_HSE_Div2,RCC_PLLMul_12);
                    
        RCC_PLLCmd(ENABLE);
        
        while(RCC_GetFlagStatus( RCC_FLAG_PLLRDY)!=SET);
            
                
        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
        
        while (RCC_GetSYSCLKSource() != 0x08){}
            
        FLASH_SetLatency(FLASH_Latency_1);    
        
    }

  • As mentioned already:

    Please remember that XTAL is a virtual register in the µVision simulator. It has no influence on your code and therefore your application

    You need to define the clock-tree setup in your application. I suggest using STCube to do that. Please see our examples how to do that.