Saturday, February 22, 2020

4. GPIO (using LED and Push Button)

    I this example we are using Green LED on our stem32f4 Discovery Board. It will turn on, once the
    push Button is pressed.

    Steps:
    1. Enable clock for LED:
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
    2. Enable clock for push Button:
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
    3. Configure Pins (LED and push Button)
    4. We can then use the LED and Button

    Example:
^

3. Setting System Clock Frequency (Excel Utility)

    In this example, I am using Excel Utility

Steps:
    1. After creating any project with Atollic TrueStudio, the HSE value is automatically set to 25   
          MHz, which is not correct. First, we have to edit it to 8 MHz. For that go to stm32f4xx.h and
          find HSE_VALUE. Change there the value to 8000000.


     2. Open the Excel File

    Here we can see HSE value is 8 (i.e. 8 MHz), we always have to use this value. stm32f4 Discovery
   Board have external Oscillator whose frequency is 8 MHz. Our Discovery have highest frequency
   of 168 MHz. We can choose here our own frequency. In my Example I'm setting the value to 48 
   MHz.

    3. Enter HCLK frequency value

    4. Click on Run and choose PLL(HSE) as source clock and then click on OK.


    5. Click on Generate. A file (system_stm32f4xx.c) in the same folder with new clock frequency
        will be generated.


    6. Copy that file. Then go to your project on Atollic TrueStudio. Replace there the 
        file system_stm32f4xx.c with new one we have generated.


    Ready to Go :)

2. Using Random Number Generator (RNG)


  • Cortex-M4 features 32 bit RNG
    Steps:
  1. Activating clock for RNG:                                RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
  2. Activating the RNG itself:                                                                          RNG_Cmd(ENABLE);
  3. Before calling for random number from RNG, we have to check whether the Data is ready with RNG Flag:                                                                  RNG_GetFlagStatus(RNG_FLAG_DRDY)
  4. Getting generated numbers:                                                                RNG_GetRandomNumber()

    Example:
Random Number Generator | stm32f4xx

Wednesday, January 29, 2020

1. Creating New Project in Atollic TrueStudio



1. Go to File > New > C Project

Atollic TrueStudio


2. Give the Project a name
    > select Embedded C Project in Project type  Executable
    > click on Next



3. Search for Device: STM32F4 > MCUs




4. Select STM32F407VG
    > click on Next

Atollic TrueStudio


5. Leave this Part as it is.
    > click on Next
Atollic TrueStudio


6. Select ST-Link in Debug Probe
    > click on Finish

Atollic TrueStudio


7. there you GO :)

Atollic TrueStudio