Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 10, 2016, 03:56:53 03:56


Login with username, password and session length


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

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« on: January 14, 2015, 08:36:16 20: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: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #1 on: January 15, 2015, 12:56:27 00: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

nothing to say..
Ichan
Hero Member
*****
Offline Offline

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #2 on: January 16, 2015, 05:44:36 05: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: 277

Thank You
-Given: 197
-Receive: 95


Tuco ... dead or Alive


« Reply #3 on: January 16, 2015, 10:58:54 10: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: 15

Thank You
-Given: 10
-Receive: 1


« Reply #4 on: January 17, 2015, 01:49:11 01: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
**
 Muted
Offline Offline

Posts: 35

Thank You
-Given: 13
-Receive: 17


« Reply #5 on: January 17, 2015, 04:07:05 16: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: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #6 on: January 17, 2015, 04:41:03 16: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: 15

Thank You
-Given: 10
-Receive: 1


« Reply #7 on: January 18, 2015, 02:35:04 02: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: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #8 on: January 18, 2015, 04:31:20 16: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: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #9 on: January 19, 2015, 08:20:52 20: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

nothing to say..
Ichan
Hero Member
*****
Offline Offline

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #10 on: January 20, 2015, 08:05:24 08: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: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #11 on: January 20, 2015, 08:44:25 08: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, 11:40:31 11:40 by metal » Logged

nothing to say..
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #12 on: January 20, 2015, 10:29:12 22: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

nothing to say..
Ichan
Hero Member
*****
Offline Offline

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #13 on: January 22, 2015, 01:22:34 01: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: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #14 on: January 30, 2015, 08:44:06 20: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
Active Member
***
Offline Offline

Posts: 151

Thank You
-Given: 1126
-Receive: 29


« Reply #15 on: February 01, 2015, 09:42:44 09: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: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


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

explain plz
Logged

nothing to say..
Ichan
Hero Member
*****
Offline Offline

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #17 on: February 01, 2015, 03:37:47 15: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: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #18 on: February 01, 2015, 07:37:04 19: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, 07:39:05 19:39 by Ichan » Logged

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

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #19 on: February 03, 2015, 12:20:55 00: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: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #20 on: February 05, 2015, 10:41:43 10: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

nothing to say..
Ichan
Hero Member
*****
Offline Offline

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #21 on: February 05, 2015, 03:28:28 15: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, 07:18:48 19:18 by Ichan » Logged

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

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #22 on: February 08, 2015, 02:58:24 14: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, 03:01:59 15:01 by Ichan » Logged

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

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #23 on: February 12, 2015, 12:38:16 12: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

nothing to say..
Ichan
Hero Member
*****
Offline Offline

Posts: 840

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #24 on: February 12, 2015, 03:31:54 15: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