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

I don't know how to configure the clock and the GPIO with CMSIS for cortex-M3

Hi all, I'm new and I'm doing a project to manage some ports in digital and ADC way but let me start for the basics.

I have the cortex-M3 stm32f103c6 microcontroller and I'm trying to create a project using CMSIS, CMSIS has a function to initialize the system called SystemInit() but when I look at it then the only thing that it aparently does is upload the system clock so someway it calls somewhere a function to initialize the clock of the microcontroller, I think this is done in startup_ARMCM3.c/h but I don't know, then I looked around and I've found that SystemInit() updates the SystemCore Clock variable to the value of XTAL/2 and when finally found XTAL definition it then has assigned 50000000UL, SystemClockUpdate simply assign to SystemCoreClock again SYSTEM_CLOCK.

What I don't know is:

1) Which funtion initializes the clock of the system.

2) Can I use that function to change the clock source in the system because I have around two days searching and I found nothing about it.

3) Is there CMSIS functions to manage GPIO for cortex-M3? I found nothing about it.

Having asked these question then I ask, Its better to use CMSIS or do I need to create my own libraries, I asked that because at the CMSIS documentation I found nothing until now to manage GPIO and when There are selections of libraries in CMSIS configuration for the cortex-M3 then nothing appeared for GPIO.

Thanks in advance for the help.

  • Most people are using the ST SPL or HAL libraries which use CMSIS includes/forms.

    ST generally programs the RCC peripheral, bringing up external clocks and the PLL so the chip runs at 72 MHz, rather than 8 MHz

    CMSIS wants you to do this board/chip bring up work in SystemInit(), so it can call that before the runtime code in startup.s unpacks your statics, and eventually transfers control to your main() function.

    STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template\system_stm32f10x.c

    /**
      * @brief  Setup the microcontroller system
      *         Initialize the Embedded Flash Interface, the PLL and update the
      *         SystemCoreClock variable.
      * @note   This function should be used only after reset.
      * @param  None
      * @retval None
      */
    void SystemInit (void)
    {
      /* Reset the RCC clock configuration to the default reset state(for debug purpose) */
      /* Set HSION bit */
      RCC->CR |= (uint32_t)0x00000001;
    
      /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
    #ifndef STM32F10X_CL
      RCC->CFGR &= (uint32_t)0xF8FF0000;
    #else
      RCC->CFGR &= (uint32_t)0xF0FF0000;
    #endif /* STM32F10X_CL */
    
      /* Reset HSEON, CSSON and PLLON bits */
      RCC->CR &= (uint32_t)0xFEF6FFFF;
    
      /* Reset HSEBYP bit */
      RCC->CR &= (uint32_t)0xFFFBFFFF;
    
      /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
      RCC->CFGR &= (uint32_t)0xFF80FFFF;
    
    #ifdef STM32F10X_CL
      /* Reset PLL2ON and PLL3ON bits */
      RCC->CR &= (uint32_t)0xEBFFFFFF;
    
      /* Disable all interrupts and clear pending bits  */
      RCC->CIR = 0x00FF0000;
    
      /* Reset CFGR2 register */
      RCC->CFGR2 = 0x00000000;
    #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
      /* Disable all interrupts and clear pending bits  */
      RCC->CIR = 0x009F0000;
    
      /* Reset CFGR2 register */
      RCC->CFGR2 = 0x00000000;
    #else
      /* Disable all interrupts and clear pending bits  */
      RCC->CIR = 0x009F0000;
    #endif /* STM32F10X_CL */
    
    #if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL)
      #ifdef DATA_IN_ExtSRAM
        SystemInit_ExtMemCtl();
      #endif /* DATA_IN_ExtSRAM */
    #endif
    
      /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */
      /* Configure the Flash Latency cycles and enable prefetch buffer */
      SetSysClock();
    
    #ifdef VECT_TAB_SRAM
      SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
    #else
      SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
    #endif
    }
    

    Start by looking at things that work, then decide if you prefer libraries, or doing register level bit banging