write a complete code for STM32F407

Status
Not open for further replies.

jab99407

Member
I have some basic understanding of microcontroller, C programming language and did some projects about this. There is no doubt, STM32Cube code generator is very useful but I don't want to use code generated by STM32Cube.

This is my basic template. if I want to write complete for stm32f407 board I will need to include header file. I have datasheet so how to write my own header file by looking information into datasheet.

C:
void main(void)
{
   initialize();
   while (1)
      {
    
      
      }
}
 
Just get one of the standard device headers for the STM32 that already exist; no point "reinventing the wheel".
eg.

Set the appropriate device type in the first few lines of that, where it says.

Then you can write the actual C program you want!

Edit - typo
 
Last edited:
Set the appropriate device type in the first dew lines of that, where it says.
I don't understand what is meaning of "Set the appropriate device type in the first dew lines of that, where it says." Can you explain clearly

C:
#include"stm32f4xx.h"

void main(void)
{
   initialize();
   while (1)
      {
    
      
      }
}
 
It should have said "First few lines".

See this section of the header file:

C:
#if !defined  (STM32F4)
#define STM32F4
#endif /* STM32F4 */

/* Uncomment the line below according to the target STM32 device used in your
   application
  */
#if !defined (STM32F405xx) && !defined (STM32F415xx) && !defined (STM32F407xx) && !defined (STM32F417xx) && \
    !defined (STM32F427xx) && !defined (STM32F437xx) && !defined (STM32F429xx) && !defined (STM32F439xx) && \
    !defined (STM32F401xC) && !defined (STM32F401xE) && !defined (STM32F411xE) && !defined (STM32F446xx)
  /* #define STM32F405xx */   /*!< STM32F405RG, STM32F405VG and STM32F405ZG Devices */
  /* #define STM32F415xx */   /*!< STM32F415RG, STM32F415VG and STM32F415ZG Devices */
  /* #define STM32F407xx */   /*!< STM32F407VG, STM32F407VE, STM32F407ZG, STM32F407ZE, STM32F407IG  and STM32F407IE Devices */
  /* #define STM32F417xx */   /*!< STM32F417VG, STM32F417VE, STM32F417ZG, STM32F417ZE, STM32F417IG and STM32F417IE Devices */
  /* #define STM32F427xx */   /*!< STM32F427VG, STM32F427VI, STM32F427ZG, STM32F427ZI, STM32F427IG and STM32F427II Devices */
  /* #define STM32F437xx */   /*!< STM32F437VG, STM32F437VI, STM32F437ZG, STM32F437ZI, STM32F437IG and STM32F437II Devices */
  /* #define STM32F429xx */   /*!< STM32F429VG, STM32F429VI, STM32F429ZG, STM32F429ZI, STM32F429BG, STM32F429BI, STM32F429NG,
                                   STM32F439NI, STM32F429IG  and STM32F429II Devices */
  /* #define STM32F439xx */   /*!< STM32F439VG, STM32F439VI, STM32F439ZG, STM32F439ZI, STM32F439BG, STM32F439BI, STM32F439NG,
                                   STM32F439NI, STM32F439IG and STM32F439II Devices */
  /* #define STM32F401xC */   /*!< STM32F401CB, STM32F401CC, STM32F401RB, STM32F401RC, STM32F401VB and STM32F401VC Devices */
  /* #define STM32F401xE */   /*!< STM32F401CD, STM32F401RD, STM32F401VD, STM32F401CE, STM32F401RE and STM32F401VE Devices */
  /* #define STM32F411xE */   /*!< STM32F411CD, STM32F411RD, STM32F411VD, STM32F411CE, STM32F411RE and STM32F411VE Devices */
  /* #define STM32F446xx */   /*!< STM32F446MC, STM32F446ME, STM32F446RC, STM32F446RE, STM32F446VC, STM32F446VE, STM32F446ZC,
                                   and STM32F446ZE Devices */
#endif

Just do as it says and uncomment the define relevant to the device you are using:
#define STM32F407xx /*!< STM32F407VG, STM32F407VE, STM32F407ZG, STM32F407ZE, STM32F407IG and STM32F407IE Devices */


Or you could add the appropriate #define on a line before the #include for that header file, at the start of your program:

Code:
#define STM32F407xx
#include "stm32f4xx.h"
 
Thanks for help I now want to test code practically. user manual of IDE https://www.st.com/resource/en/user_manual/dm00629856-stm32cubeide-user-guide-stmicroelectronics.pdf I can create project for specific board. Do you have any idea how to create project from scratch stm32f407G
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…