Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 19, 2024, 08:20:54 08:20


Login with username, password and session length


Pages: [1] 2 3  All
Print
Author Topic: Playing with STM32CubeMX  (Read 52333 times)
0 Members and 1 Guest are viewing this topic.
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« on: January 14, 2015, 07:36:16 19:36 »

I hope this thread can become a place where we share experiences using this tools.

So, here is my get starting project with Nucleo-F401RE board.

Software tools used:
- STM32CubeMX Ver. 4.5.0
- STM32CubeF4 library Ver. 1.3.0
- Keil MDK ARM Ver. 4.73

This is to blink the green led in two modes, first using delay (200ms) and the second using timer3 interrupt (2sec) - blue button toggles between modes.

The steps:
1. Open the .ioc file attached using CubeMX (remove .txt extension first)
2. Generate the code skeleton
3. Open generated project in Keil
4. Edit the main.c add codes below on the appropriate section

Code:
/* USER CODE BEGIN PV */
unsigned char mode;
/* USER CODE END PV */


/* USER CODE BEGIN 1 */
mode = 0;
/* USER CODE END 1 */


/* USER CODE BEGIN 3 */
HAL_TIM_Base_Start_IT(&htim3);
/* Infinite loop */
while (1)
{
if(!HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)) {
HAL_Delay(50);    // simple debounce
if(!HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)) {if(mode == 0) mode = 1; else mode = 0;};
}
if(mode == 0) HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_Delay(200);
}
/* USER CODE END 3 */


/* USER CODE BEGIN 4 */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
if(htim->Instance == htim3.Instance) {
if(mode == 1) HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}
}
/* USER CODE END 4 */

5. Build, flash download, and run (or press black reset button)

Hope this has any use...  I am playing with STM32F4-Discovery now.

-ichan
Logged

There is Gray, not only Black or White.
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #1 on: January 14, 2015, 11:56:27 23:56 »

I think there is a better approach, if you could do a video on the steps you followed while using the software to configure the chip, this is better.
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #2 on: January 16, 2015, 04:44:36 04:44 »

Currently I have no screen recorder software installed, which one is good?

I think the use of CubeMX software is pretty straightforward, just read and follow the user manual:

UM1718: STM32CubeMX for STM32 configuration and initialization C code generation

The much harder part is to follow and understand the Cube Library itself, for F4 the next documents to read are:

UM1730: Getting started with STM32CubeF4 firmware package for STM32F4xx series
UM1725: Description of STM32F4xx HAL drivers

and then other user manual from this page.

I am now playing with USB on F4Discovery, CDC device seems ok but got a headache with HID device.

-ichan
Logged

There is Gray, not only Black or White.
TucoRamirez
Senior Member
****
Offline Offline

Posts: 307

Thank You
-Given: 257
-Receive: 115


Tuco ... dead or Alive


« Reply #3 on: January 16, 2015, 09:58:54 09:58 »

Currently I have no screen recorder software installed, which one is good?

I could say to use camtasia. quite nice user interface.
Logged

Whoever double crosses me and leaves me alive... he understands nothing about Tuco.
rBot
Newbie
*
Offline Offline

Posts: 12

Thank You
-Given: 14
-Receive: 1


« Reply #4 on: January 17, 2015, 12:49:11 00:49 »

I have the F411RE-NUCLEO board.  Hope to get back playing with it this weekend. But, it is supposed to be nice outside here too.

Posted on: January 17, 2015, 01:22:11 01:22 - Automerged

Using CubeMX for the F411RET.  I want to put Timer2 in 'Encoder' mode.  Any clue how to do so?

I can do it this way:
Code:
void EncoderInitialise(void) {
    // configure GPIO PA0 & PA1 as inputs for Encoder
    RCC->AHB1ENR |= 0x00000001;  // Enable clock for GPIOA
 
    GPIOA->MODER   |= GPIO_MODER_MODER0_1 | GPIO_MODER_MODER1_1 ;           //PA0 & PA1 as Alternate Function   /*!< GPIO port mode register,               Address offset: 0x00      */
    GPIOA->OTYPER  |= GPIO_OTYPER_OT_0 | GPIO_OTYPER_OT_1 ;                 //PA0 & PA1 as Inputs               /*!< GPIO port output type register,        Address offset: 0x04      */
    GPIOA->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR0 | GPIO_OSPEEDER_OSPEEDR1 ;     // Low speed                        /*!< GPIO port output speed register,       Address offset: 0x08      */
    GPIOA->PUPDR   |= GPIO_PUPDR_PUPDR0_1 | GPIO_PUPDR_PUPDR1_1 ;           // Pull Down                        /*!< GPIO port pull-up/pull-down register,  Address offset: 0x0C      */
    GPIOA->AFR[0]  |= 0x00000011 ;                                          //  AF01 for PA0 & PA1              /*!< GPIO alternate function registers,     Address offset: 0x20-0x24 */
    GPIOA->AFR[1]  |= 0x00000000 ;                                          //                                  /*!< GPIO alternate function registers,     Address offset: 0x20-0x24 */
   
 
    // configure TIM2 as Encoder input
    RCC->APB1ENR |= 0x00000001;  // Enable clock for TIM2
 
    TIM2->CR1   = 0x0001;     // CEN(Counter ENable)='1'     < TIM control register 1
    TIM2->SMCR  = 0x0003;     // SMS='011' (Encoder mode 3)  < TIM slave mode control register
    TIM2->CCMR1 = 0xF1F1;     // CC1S='01' CC2S='01'         < TIM capture/compare mode register 1
    TIM2->CCMR2 = 0x0000;     //                             < TIM capture/compare mode register 2
    TIM2->CCER  = 0x0011;     // CC1P CC2P                   < TIM capture/compare enable register
    TIM2->PSC   = 0x0000;     // Prescaler = (0+1)           < TIM prescaler
    TIM2->ARR   = 0xffffffff; // reload at 0xfffffff         < TIM auto-reload register
 
    TIM2->CNT = 0x0000;  //reset the counter before we use it
}
 

Thanks
Logged
pumper
Junior Member
**
Offline Offline

Posts: 35

Thank You
-Given: 13
-Receive: 18


« Reply #5 on: January 17, 2015, 03:07:05 15:07 »

Hi i am new to arm world and tried cube for creating a project my question is about header  files added to main.c
in most tutorials on the net for stm32f4 family the header file is :
Code:
// include necessary header files
#include<stm32f4xx.h>        // defines name for hardware addresses
#include<stm32f4xx_rcc.h>    // defines clock functions
#include<stm32f4xx_gpio.h>    // defines gpio functions

but cube only added this header file
Code:
#include "stm32f4xx_hal.h"
whats the difference?
is it something related to CMSIS?
and if HAL is the other name for cmsis?
sorry for nub question
Logged

C++ is designed to give the programmer choice, even if this makes it possible for the programmer to choose incorrectly
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #6 on: January 17, 2015, 03:41:03 15:41 »

I could say to use camtasia. quite nice user interface.

I seek for it, nah... too big for this kind of application, i am gonna try screen2swf (only 4MB).
I will make a video of blinky project for F4-Discovery with this, i think more people have F4-Discovery rather than Nucleo, as the last one is relatively new.

I have the F411RE-NUCLEO board.  I want to put Timer2 in 'Encoder' mode.  Any clue how to do so?

Quick a look onto this, current CubeMX seems already support encoder mode for timers, more to dig is the library manual UM1725 section 46. I may try this with my Nucleo-F401 if i can find an encoder around - anyway what is the difference between F401 and F411?

Hi i am new to arm world and tried cube for creating a project my question is about header  files added to main.c

I think STM32Cube library add one more layer from the standard peripheral library, stm32f4xx_hal.h includes stm32f4xx_hal_conf.h where CubeMX defines wich module to be enabled.

-ichan
Logged

There is Gray, not only Black or White.
rBot
Newbie
*
Offline Offline

Posts: 12

Thank You
-Given: 14
-Receive: 1


« Reply #7 on: January 18, 2015, 01:35:04 01:35 »

Ichan,

Looks like the main different (which isn't much) seems to be a little more speed (84MHz vs 100MHz) and a little more RAM (96K vs 128K).
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #8 on: January 18, 2015, 03:31:20 15:31 »

Attached Mediafire link to two video of creating blinky sample project with STM32F4-Discovery. The first one use delay while the second one use timer interrupt.

This is a great tool, not perfect yet but really make coding a lot more easier and faster. One i found is the current CubeMX doesn't generate HID device code skeleton correctly.

I am gonna try graphics on F429 Disco soon.

Looks like the main different (which isn't much) seems to be a little more speed (84MHz vs 100MHz) and a little more RAM (96K vs 128K).

How about you try the encoder thing and share the experience?

-ichan
Logged

There is Gray, not only Black or White.
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #9 on: January 19, 2015, 07:20:52 19:20 »

I need more explanation about those:

Peripheral initialization
a) Start by writing the peripheral HAL_PPP_MspInit function. For this function,
proceed as follows:
– Enable the peripheral clock.
– Configure the peripheral GPIOs.
– Configure DMA channel and enable DMA interrupt (if needed).
– Enable peripheral interrupt (if needed).
b) Edit the stm32f4xx_it.c to call the required interrupt handlers (peripheral and
DMA), if needed.
c) Write process complete callback functions if you plan to use peripheral interrupt or
DMA.
d) In your main.c file, initialize the peripheral handle structure, then call the function
HAL_PPP_Init() to initialize your peripheral.
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #10 on: January 20, 2015, 07:05:24 07:05 »

Metal, i am not sharp enough to explain... Wink  but all those points should be already handled (generated) by CubeMX.

How about playing with the real thing, read an ADC and display the value on seven segment display? What board do you prefer, Nucleo (easier prototyping using arduino proto shield) or F4-Discovery (most common owned)?

I will try it on the weekend.

-ichan.
Logged

There is Gray, not only Black or White.
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #11 on: January 20, 2015, 07:44:25 07:44 »

Actually I have F4 discovery, seems this is what I am going to do anyway.

But, while reading the file UM1730, sth came up to mind, suppose I did not want to use CubeMX, how can I find out which files to include, which functions to use, etc.. I found this video:

http://www.youtube.com/embed/99KU97JKXEQ/?vq=hd720
« Last Edit: January 20, 2015, 10:40:31 10:40 by metal » Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #12 on: January 20, 2015, 09:29:12 21:29 »

Ichan, I could not wait for the weekend to get sth from you. I did an example, both video and files are found in the attached file. I managed to create an example for ADC conversion using ADC interrupt, I also created a quick software filter to rule out instability issues, just for the fun of it, nothing special.

I will also try the DMA way later on and do its video if I have enough time for it.
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #13 on: January 22, 2015, 12:22:34 00:22 »

Metal, glad having a friend playing this tool  Grin.

I modify your ADC example a bit and send the measured value through USB CDC. ADC0 on F4-Discovery is connected to user (blue) button via some resistor, connected to 3.3V if the button pressed. As terminal picture attached, ADC0 value is near zero if the button not pressed, about 3.3V if pressed.

Attached the .ioc and modified .c files, have a look.

On my PC (W7/64), i need to increase heap size to 0x400 (on startup_stm32f407xx.s file), if not windows will fail to recognize the CDC device.

-ichan
Logged

There is Gray, not only Black or White.
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #14 on: January 30, 2015, 07:44:06 19:44 »

Have no time to play on the last weekend, hopefully i will have now.

Collecting components around me i can find two digit 7 segment display, a potentiometer, and a mechanical rotary encoder - but i can not find a proto board, what i can get is an arduino proto shield like in the picture below from my nephew (i don't use Arduino). So i will use Nucleo board instead of F4-Discovery because it has arduino compatible connectors for the proto board.

Ready to play, run the CubeMX, check for updates - and wow new updates available: CubeMX Ver. 4.6.0 and STM32F4 Library Ver. 1.4.0.

Now still downloading it...  Smiley

-ichan
Logged

There is Gray, not only Black or White.
bobcat1
Senior Member
****
Offline Offline

Posts: 295

Thank You
-Given: 4131
-Receive: 89


« Reply #15 on: February 01, 2015, 08:42:44 08:42 »

Hi All

I have played with the tool - generating some code to drive SPI
It looks like the code generated by the tool is not consistent with the library provided by ST
There for it was hard to mix code from library and code genereted by the tool
It is also look like the code generated by the tool is better then the code provided by the library - more deep code and better example
 
All the best

Bobi   
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #16 on: February 01, 2015, 08:54:00 08:54 »

explain plz
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #17 on: February 01, 2015, 02:37:47 14:37 »

Here is my ADC to 7 Segment display which work perfectly but i am not very satisfied yet because the display is a bit flicker, need more work to handle the ADC interrupt to not making some glitch on segment scanning.

Playing with this i found Nucleo is more useful than F4Disovery because it has no on board peripheral so we can use almost all ports. For this display 8 bit contiguous port PA0 - PA7 used to drive the segment including dot point, PC0 and PC1 to drive the digit. As i have no pnp transistor at home now i just drive the common anode of the display from those pins via 120 ohm resistor. The middle pin of the pot goes to PB0 (ADC1 channel 8 ), while the other two goes to gnd and 3.3V.

Some notes:
- To use PA2 and PA3 on arduino connector some resistor jumper at the bottom of pcb need to be modified.
- The segment drive use table lookup calculated using spreadsheet attached.
- GPIO HAL has no 8 bit parallel write routine, so register access used (GPIOA->ODR).
- Timer3 fired every 1 ms to do the segment scanning.
- ADC1 in continuous mode, interrupt driven (here is the flicker problem root of cause).
- Some filtering done on ADC interrupt.

On the photo attached the display shows 1.6 value when the pot on the center position.

Attached the files required, delete the extra .txt extension on some files.

-ichan
Logged

There is Gray, not only Black or White.
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #18 on: February 01, 2015, 06:37:04 18:37 »

Just found the solution for flickering problem:

- Configure the ADC for single conversion with interrupt.
- Call ADC start at the end of the timer interrupt callback.

Absolutely perfect now Grin

-ichan
« Last Edit: February 01, 2015, 06:39:05 18:39 by Ichan » Logged

There is Gray, not only Black or White.
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #19 on: February 02, 2015, 11:20:55 23:20 »

Adding rotary encoder functionality. The display in two modes, mode0 show ADC value while mode1 show Encoder value - if the ADC value higher than Encoder value then the green led lit. Pushing the encoder rotary push button will toggle between the two modes, in mode1 the encoder value displayed in blink.

Attached the files required and a very short reduced file size movie of it (remove the extra .txt extension).

I started to falling in love with this CubeMX  Grin.

-ichan
Logged

There is Gray, not only Black or White.
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #20 on: February 05, 2015, 09:41:43 09:41 »

I am wondering what type of rotary encoder you are using, btw is it possible to use this with a 2-bit gray code rotary encoder?
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #21 on: February 05, 2015, 02:28:28 14:28 »

The encoder used is cheap one taken from a spare 3d printer panel, zoomed picture below - it is mechanical Incremental encoder with push button. Grey code encoder is absolute encoder, can not be used in here. My encoder is bouncing badly, i have to put 100n cap from its A & B pin to ground, also the Timer1 filter input sets quite heavy.

Attached a simple USB HOST + MSC + FATFS implementation, this follow a sample on the library project folders, but here using CubeMX. Run it and then plugin a flash disk, a text file will be written and then verified back by reading it, if successful the orange led lit. The file written can be examined on PC.

Edit: Stack and Heap size need to be increased, i use 0x800 and 0x400

-ichan

« Last Edit: February 05, 2015, 06:18:48 18:18 by Ichan » Logged

There is Gray, not only Black or White.
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #22 on: February 08, 2015, 01:58:24 13:58 »

For learning graphics, easier to use F429 as some sample available - but my target board to work on later based on F407, so harder way need to be taken to port the SSD2119 LCD driver.

Took a full weekend time to make it work  Sad, i think this is the first available SSD2119 implementation with Cube HAL on the net  Grin.

The beauty of the CubeMX is it generates all the complicated FSMC-SRAM initialization thing, no need to open the mcu datasheet / user manual.  Attached the complete project.

Edit: The dev board used is STM32F4-Discovery + Expansion board.

Next will be STemWin.

-ichan.


« Last Edit: February 08, 2015, 02:01:59 14:01 by Ichan » Logged

There is Gray, not only Black or White.
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #23 on: February 12, 2015, 11:38:16 11:38 »

Ichan, what is the difference between using TIM_TRGO_RESET and TIM_TRGO_UPDATE, and when am I supposed to use each one?
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #24 on: February 12, 2015, 02:31:54 14:31 »

Never use that one yet Grin, but sure will try to find out.

What is the usage, triggering ADC?

-ichan
Logged

There is Gray, not only Black or White.
Pages: [1] 2 3  All
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC