STM32CubeIDE: Hello World

* Select a directory as workspace
enter Documents\STM32Cube\o323bgc
=> creates a folder Documents\STM32Cube\o323bgc if not already existing
contains a .metadata folder which stores the workspace info
=> STM32CubeIDE opens with „Welcome to STM32CubeIDE“ screen

* either press „Start new STM32 project“ or do File->New->STM32 Project
=> it may download some files

=> Target Selector dialog opens
enter e.g. STM32F103RC or go through the check boxes
click choice and hit Next

=> Project Name dialog opens
enter e.g. f103rc
this will create a new subfolder o323bgc\f103rc
I use that to allow for multiple targets for the o323bgc project
the other options I leave at default
– targeted language: C
– targeted binary type: executable
– targeted project type: STM32Cube
hitting Next will bring up more options, which I also leave at default
– firmware package name and version: default should be the latest (V1.8.4)

comment on versioning !!

– code generator options: copy only necessary library files
we will copy over the complete HAL files later anyway

=> hit Finish
this will bring up dialog asking to open perspective now, press yes

comment on workspace, project, perspectives

=> may download files, can take a while if complete HAL package has t be downloaded

=> opens STM32CubeMX inside the IDE, with the tabs
– „Pinout & Configuration“
– „Clock Configuration“
– „Project Manager“
– „Tools“
important settings to be made in the first three („Tools“ is irrelevant to us)

* „Pinout & Configuration“
click „System Core“ category
click SYS
select Debug = Serial Wire !!! THIS IS VERY IMPORTANT !!!!

click RCC
select High Speed Clock (HSE) = Crystal/Ceramic

this is all we do here, we do not make use of the STM32CubeMX’s ability to generate further code template parts (for even moderately complex projects I don’t find that useful at all)

* „Clock Configuration“
that’s very useful as it will generate the code for starting up the system clocks
check the fields „Input frequency“, that it has the frequency you want to use, e.g. 8 MHz
the simplest way is to just enter the desired frequency in the box „HCLK (MHz)“
e.g. 72 for the F103RC
this will make it search for a possible configuration
usually this works fine, only if it doesn’t yield what you want you have to go through things manually

* „Project Manager“
– „Project“
I leave the settings as default, except of „Minimum Heap Size“, which I set to 0x0
– „Code Generator“
I leave all settings as default
– „Advanced Settings“
!!! VERY IMPORTANT !!!
here you can choose between HAL and LL for each peripheral
we just have RCC and GPIO
I select LL for both/all

this is it, press the „Safe All“ icon in the top left area
this will open a dialog asking if you want to generate code, press yes
this will open a dialog asking to open the C/C++ perspective, press yes
=> this will do some things

* Setup files and folders
– not all LL files are in the Drivers/STM32F1xx_HAL_Driver folder
so we copy them over by hand from a location there we had put them before
even though we could click all peripherals in the STM32CubeMX view, but we do not use this as this will generate lots of code templates, which I find just annoying
do not copy the HAL files, copy only the LL files (unless you want a mixed LL/HAL or pure HAL project and know what you are doing)
also, some LL files may in fact need the HAL files, and will cause issues, for the F103RC I resolve this by deleting also these files
– stm32f1xx_ll_fsmc.c
– stm32f1xx_ll_sdmmc.c
– stm32f1xx_ll_usb.c

– right click on f103rc, to create a new folder „CommonSrc“
click „Advanced“
click „Link to alternate location (Linked Folder)“
browse to o323bgc/CommonSrc
attention not into f103rc subfolder, should be one higher, so it cam be later similarly accessed by all targets

– create a file in CommonSrc which has a function int main_main(), this will be the main project file
I call it o323bgc-vm.c

– right click CommonSrc, go to Properties, go to C/C++ Build, un-click „exclude resource form build“, hit „Apply and Close“
you have to do this for both „Debug“ and „Release“ configuration (or at least for Release as this is what I use only)

go to Core/Src/main.c
enter „int main_main();“ in the area marked by „USER CODE BEGIN PFP“ and „USER CODE END PFP“, which is just after the section with the SystemClock_Config() declaration
enter „return main_main();“ in the area marked by „USER CODE BEGIN 2“ and „USER CODE END2“, which is just right before the while(1) loop

now you are done, and you should be able to compile

—————————————-
* how to use STLinkV2 with STM32CubeIDE

The STM32CubeIDE is quite picky with which STLink dongles can be used. It seems it requires and accepts only dongles which are identified (somehow) as ST original, and it will refuse to use e.g. the common cheap STLinkV2 dongle sticks. Also STLinkV1 is not supported at all. As a result, STM32CubeIDE refuses to flash where STM32CubeProgrammer or ST-LINK Utility would just happily do the job.

There are a couple of ways to get around that, e.g., via the External Tools Configurations option. It goes as this:

Project -> Properties -> C/C++ Build -> Settings -> Tool Settings -> MCU Post build outputs: check „Convert to Intel Hex file“

Run -> External Tools -> External Tools Configuration: double click on „Program“ on the left side, this opens a field with many entries

Name: STLink Dongle
Main->Location: C:\Program Files (x86)\STMicroelectronics\STM32 ST-LINK Utility\ST-LINK Utility\ST-LINK_CLI.exe
Main->Arguments: -c SWD -P ${project_loc}\${config_name:${project_name}}\${project_name}.hex -Rst
Build->Build before launch: uncheck it
Common->display in favorites menu: check „External Tools“

Another way I found described here: https://community.st.com/s/question/0D53W00000DGpMn/i-cant-use-the-stlink-in-stm32cubeide-even-after-updating-the-stlink-firmware, see the response by Georgy Moshkin. It goes as this:

Project -> Properties -> C/C++ Build -> Settings -> Tool Settings -> MCU Post build outputs: check „Convert to Intel Hex file“

Run -> Release Configurations: double-click on first line „C/C++ Application“ to create new configuration. This opens fields on the right.

Main -> C/C++ Application: enter C:\Program Files (x86)\STMicroelectronics\STM32 ST-LINK Utility\ST-LINK Utility\ST-LINK_CLI.exe
Arguments -> Program arguments: enter -c SWD -P ${project_loc}\${config_name:${project_name}}\${project_name}.hex -Rst
Common: check „Display in favorites menu“ – „Run“

—————–

for old coocox
Main->Location: C:/Programme2/CooCox/CoIDE/bin\coflash.exe
Main->Arguments: program STM32F103C8 „${project_loc}\Release\${project_name}.elf“ –adapter-name=ST-Link –port=SWD –adapter-clk=1000000 –erase=affected –driver=“C:/Programme2/CooCox/CoIDE/flash/STM32F10x_MD_64.elf“

Hinterlasse einen Kommentar