Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 20, 2024, 08:58:15 08:58


Login with username, password and session length


Pages: 1 2 3 [All]
Print
Author Topic: Playing with STM32CubeMX  (Read 52984 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: 4147
-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.
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #25 on: February 13, 2015, 11:34:04 11:34 »

nop, in the datasheets, look at MMS of TIM6, if you look at the defs in HAL, you will find these, and are actually related to MMS.
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #26 on: February 13, 2015, 09:16:50 21:16 »

So it is about Master-Slave configuration for timers, i have no idea when to use it. My understanding about Update even on timers occurs if there is a change on timer registers (depends on configuration) , while Reset event occurs when the counter register goes to zero by overflow. I can be wrong...

A touch screen is better available before playing with STemWin, so below is a port of LCD Paint application from library project folder for STM324xG_Eval board to F4-Discovery. The original code is for ILI9325 LCD which is ported to SSD2119, while the save to usb flash drive function is stripped off.

I found that combining the CubeMX generated code with other existing code is a pain, even both use the same library Sad, too many layers so the program flow is jumping here and there back and forth.

Well at least i can make it functional,  attached the complete project.

And yeah... i make a nice touch calibration screen - our father Don Corleone Grin.

-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 #27 on: February 15, 2015, 09:41:34 21:41 »

Finally Cool, STemWin on STM32F4-Discovery + Expansion board (SSD2119 LCD + STMPE811 Touchscreen Controller) with STM32CubeMX generated initialization routine. Attached the full project.

Some notes:
- The STemWin library file not included, add STemWin526_CM4_Keil.lib from STemWin library folder.
- Heap and stack size need to be increased, i use double the value that the CubeMX generate.
- For other GUI screen, copy and replace file sample1/2/3/4.c as sample.c
- Those sample GUI files actually taken from HERE.
- Not all the files from the link above will work on this project, because of memory, display size, and OS restriction.
- This project is Non-RTOS based.

I finished my own learning stage with this tool, will go for the real work on my own board - still open for any related discussion.

Cheers...

-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 #28 on: February 25, 2015, 10:08:35 22:08 »

I worked with the mechanical rotary encoder for the last couple of days and using TIM channels in encoder mode with them is a waste of time, I have been using STM32F0DISCOVERY. I saw a video on youtube where a guy did get good results, but this doesn't mean they will be good on the long term. The best way is to use another code which is dedicated for mechanical rotary encoders and do the debouncing in software itself. This is because resistor capacitor low pass filter doesn't work for this TIM HW at all for that it expects the speed of rotation to be at a specific level which is impossible for the user to keep all the time. This feature is best suited for optical encoders to be honest. Looking at other debouncing solutions, it seems that TIM HW is not worth using in this case. More to it is that software way doesn't even need filtering the encoder AB pins :- )
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #29 on: February 27, 2015, 07:03:27 19:03 »

I agree that a hardware quadrature encoder interface will need a cleaner pulse than signals from a (cheap) mechanical rotary encoder, same case with microchip quadrature encoder interface.

But my encoder on some post above works as my expectation, good enough for hand rotated application - it does sometimes skip one rotation click or sometimes makes two counts per click, but overall i think it's ok.

I do not use RC as filter but only C (100n), and 2K2 resistor as external pull up, internal IO pullup is too high for this (about 40K ohm) also i set input filter to a quite high value.

-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 #30 on: March 03, 2015, 06:05:12 06:05 »

I kept trying with the rotary encoder and it came to my mind that using an optocoupler can solve the debouncing issue, of course the code needed tuning, but the encoder works perfectly now:

Code:
/* TIM1 init function */
void MX_TIM1_Init(void)
{

  TIM_Encoder_InitTypeDef sConfig;
  TIM_MasterConfigTypeDef sMasterConfig;

  htim1.Instance = TIM1;
  htim1.Init.Prescaler = 3;
  htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim1.Init.Period = 63;
  htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim1.Init.RepetitionCounter = 0;
  sConfig.EncoderMode = TIM_ENCODERMODE_TI12;
  sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
  sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
  sConfig.IC1Prescaler = TIM_ICPSC_DIV8;
  sConfig.IC1Filter = 15;
  sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
  sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
  sConfig.IC2Prescaler = TIM_ICPSC_DIV8;
  sConfig.IC2Filter = 15;
  HAL_TIM_Encoder_Init(&htim1, &sConfig);

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig);

}
« Last Edit: March 03, 2015, 04:38:01 16:38 by metal » Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #31 on: March 04, 2015, 05:01:04 17:01 »

Nice. I am curious, with opto does input filter still need to be set to a high value?

-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 #32 on: March 04, 2015, 08:11:42 20:11 »

Today, I could work with filters as low as 1, without any problems. Bear in mind too, that I also use the following code utilizing input capture interrupt rather than inaccurately/asynchronously reading TIM1 using TIM3 interrupt:

Code:
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{
enc = htim1.Instance->CNT >> 1;
}


I divide by two, as you can see, if I use TI12, I will have to shift right by 2 ; )   Go figure...

Look at how beautiful the results are in the attached video, simply amazing... team work is also making us more creative than before..!
« Last Edit: March 04, 2015, 08:14:15 20:14 by metal » Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #33 on: March 18, 2015, 05:49:52 17:49 »

Congrats Metal, seems a stable encoder readings.

These days I have no time to play with this, busy making tons of plastic chips with a large cnc router machine - will be back soon after that.

-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 #34 on: September 26, 2015, 08:54:31 20:54 »

Coming back to play this thing i found there are many updates on both CubeMX and the libraries, the new CubeMX also can generate code for Keil 5.x so i spent a day to upgrade my environment to become:

- STM32CubeMX Ver. 4.10.0
- CubeF4 Library Ver. 1.8.0
- Keil MDK ARM 5.16a
- Library pack Keil.STM32F4xx_DFP.2.5.0

Testing the ADC_7SEG_ENC project (reply #19), regenerating it with CubeMX and compile it with MDK 5.16a giving two errors, quick checking found that the new CubeMX generate user code section as below:

Code:
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
  /* Infinite loop */
  while (1)
  {

  }
  /* USER CODE END 3 */

There is one closing bracket missing on USER CODE WHILE section, problem solved.

Testing the F4_STemWin project (reply #27), not working and giving me a headache!

It is compiled ok but giving a blank lcd display, seems the new CubeMX generate FSMC things in a different way.

I hate upgrading softwares....  Angry

-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 #35 on: September 29, 2015, 04:04:49 16:04 »

The new CubeMX has a more detailed setting for FSMC, attached the project similar with the one on reply #27 which is working in my new development environment as on post above.

Remember to copy in the STemWin528_CM4_Keil.lib, also to increase the heap and stack size - it is on startup_stm32f407xx.s file.

I am going to learn the STemWin from the beginning, still have to decide what board to use: F4-Discovery + expansion board or F429-Discovery. Any suggestion?

-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 #36 on: October 03, 2015, 07:14:56 19:14 »

My work is with F407, but seems the Chrom-ART graphic accelerator of the F429 is very interesting, i just found a tempting youtube video: Doom on STM32F429 (STM32F429IDISCOVERY).

So, i will try STM32F429IDISCOVERY first.

-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 #37 on: October 04, 2015, 07:19:21 19:19 »

This play is based on LTDC sample on the library repository folder.

Before go to learn STemWin we need to know how the lcd display on the board work, it use LTDC and SPI peripheral.

Instruction:

- extract the file attached to a folder
- open the cubemx project .ioc file
- generate the code, open in mdk 5.x
- change the code on main.c as picture below
- build the project
- change the programming algorithm size as picture below
- download to flash and run

Pay attention on the CubeMX setting of both peripheral above also the clock configuration, the TIM6 added just for alive 1 second blinky led signal.

-ichan
« Last Edit: October 04, 2015, 07:24:28 19:24 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 #38 on: October 10, 2015, 05:43:43 17:43 »

Continuing the previous play here a learn about setting DMA2D (the Chrom-ART graphic accelerator) and FMC (SDRAM) peripheral on CubeMX.

The instruction is the same as the previous one, except no need to modify the main.c - the layer frame buffer is pointed to absolute SDRAM address which can be set via CubeMX.

This project set LTDC into 2 layers, upper half of the LCD display as layer0 and the lower half as layer1. Two image (penguins and girls) in flash is blended and transfered to the two LTDC layer frame buffer in SDRAM using DMA2D.

What i still do not understand is why the result on layer0 (upper half) is darker than the layer1 (lower half), even with the same image and parameters. If anyone try this and know the answer please let me know.

-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 #39 on: October 13, 2015, 07:30:38 19:30 »

This one based on the STemWin sample HelloWord project on the repository folder, but in CubeMX environment with more simple project structure and easier to follow program flow. Project file attached doesn't include the library file STemWin528_CM4_Keil.lib, copy it in from the STemWin library repository folder - it is to big to be attached in here.

Some notes:
- DMA2D and LTDC on CubeMX parameters doesn't need to be defined, just activate it and use default parameters.
- There is re-initialization procedure for both of above on file LCDConf.c
- CRC peripheral need to be enabled before calling GUI_Init(), this can be done from CubeMX

Next should be a play with GuiBuilder...

-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 #40 on: October 18, 2015, 04:14:13 16:14 »

With the project HelloFriends above we can play with many other GUI API functions, what needed is to open the emWin user manual somewhere on the repository folder. It is a comprehensive manual with samples for each GUI API. In my experience this manual need to keep open while playing with STemWin.

I decide to jump to the use of GUI Builder as picture below:
- start the application (GuiBuilder.exe)
- add a frame window, set the size as 240 x 320 pixels
- add a progress bar, any size
- save it, by default it will be saved as FramewinDLG.c
- add it to the project
- add MainTask() routine below

Code:
void MainTask(void) {
  WM_HWIN hDlg, hBar;
  int Val = 0;

  hDlg = CreateFramewin();
  hBar = WM_GetDialogItem(hDlg, ID_PROGBAR_0);
  PROGBAR_SetFont(hBar, &GUI_Font24B_ASCII);
  PROGBAR_SetMinMax(hBar, 0, 100);
  GUI_Delay(10);
  while (1) {
    if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0)) {
      if(Val < 100) Val += 10; else Val = 0;
      PROGBAR_SetValue(hBar, Val);
    }
    GUI_Delay(200);
  }
}

As easy as that... Smiley

This project simply display a progress bar where everytime the blue button pressed the value will increase by 10%, roll over to 0 when the value pass 100%.

Some notes:
- CubeMX doesn't generate code for incrementing OS_TimeMS required by GUI_Delay() function
- Add it manually on user section of SysTick_Handler on file stm32f4xx_it.c
- Remember that the current CubeMX generate wrong programming address range for proper flash download (read some post before)
- As before the project code attached doesn't include the StemWin library

Next should be adding the touch screen...

-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 #41 on: October 21, 2015, 07:46:50 19:46 »

There is new upgrade:
- CubeMX Ver.4.11.0
- F4 library Ver. 1.9.0

I install the upgrades, and all previous pre-generated projects will not compiled succesfully, what a sucks!

The work around is the generate freshly the MDK project and then add again all the files required to the project structure.

-ichan
Logged

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

Posts: 12

Thank You
-Given: 5
-Receive: 2


« Reply #42 on: November 18, 2015, 07:25:23 19:25 »

i cannot figure out how on earth to setup timer in encoder mode in STM32cubemx version  4.11 , stm32cubeFW_F4 V 1.9.0
i have read the datasheet , and it is there and the HAL libraries support it , but the code configurator doesnot seem to do so
there is no encoder mode in any mode

if any one can find it , please attach a screen shot

another aspect that i hate about stm32cubeMX , is that until now , everytime i use the mx to add an initailaization for a pin or function and hit generate code , all my previous work in the project is lost due to main becoming empty again , maybe i should write my functions in a separate .c .h , but i donot know if they will get flushed as well   Angry Sad Huh
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #43 on: November 18, 2015, 10:04:52 22:04 »

There is encoder use sample on reply #19, i just open it again on the new environment and capture the screen as below.

Adding our own code on the files generated by CubeMX need to be put between USER CODE START X and USER CODE END X, as on the last picture.

-ichan
Logged

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

Posts: 12

Thank You
-Given: 5
-Receive: 2


« Reply #44 on: November 19, 2015, 08:14:30 08:14 »

thank u very much , now things are making more sense Grin .. just a note for others use timer2 or timer5 since they are 32bit , since on 1000ppr encoders 16bit can overflow quickly
Logged
mare69
Junior Member
**
Offline Offline

Posts: 89

Thank You
-Given: 50
-Receive: 85



WWW
« Reply #45 on: November 25, 2015, 11:30:49 11:30 »

Here's working STM32F0 project of USB CDC using CubeMX and CubeF0 library (together with some library files from stm32f4discovery site):

http://e.pavlin.si/2015/11/20/usb-to-alphanumeric-lcd-interface/
Logged
rBot
Newbie
*
Offline Offline

Posts: 12

Thank You
-Given: 14
-Receive: 1


« Reply #46 on: November 27, 2015, 09:33:13 21:33 »

Hi everyone,

I finally have time to get back on this.  You guys have made a LOT of progress.  OK, so I've downloaded all the latest stuff:

- CubeMX Ver.4.11.0
- F4 library Ver. 1.9.0
- Keil MDK ARM 5.17
- Library pack Keil.STM32F4xx_DFP.2.5.0


I loaded in the .ioc from the first post and generated the code skeleton.  If I look in the src folder, I see stm32f4xx_hal_msp.c, but no main.c.   What might I have overlooked, forgot to check or uncheck, for that matter?

Thanks

Logged
rBot
Newbie
*
Offline Offline

Posts: 12

Thank You
-Given: 14
-Receive: 1


« Reply #47 on: December 02, 2015, 06:19:48 18:19 »

Stupid Anit-virus software.  For WHATEVER reason, it is/was deleting the Main.c file.  Angry  Worked fine on my other computer.  Time to move on with projects. . .
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #48 on: December 06, 2015, 03:25:47 15:25 »

Stupid Anit-virus software.  For WHATEVER reason, it is/was deleting the Main.c file.  Angry  Worked fine on my other computer.  Time to move on with projects. . .

Share some please...  Wink

-ichan
Logged

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

Posts: 12

Thank You
-Given: 5
-Receive: 2


« Reply #49 on: December 07, 2015, 05:28:49 05:28 »

if someone worked with USART using interrupts , can u tell me how to specify the source of interrupt ( tx or rx or error ) , because in cubemx you just set a global interrupt enable. ( i guess i have to use the macro : __USART_ENABLE_IT() , but i donot know when or where )

and how is the HAL_USART_RECIEVE_IT() used ? should it be called once ??

where is the interrupt service routine ( something similar to __void interrupt handler () in PIC ) or is this the same as call back function

sorry for the being extremely noob at this but moving from PIC micro controllers and xc16 compiler and being electrical engineer not a programmer), i am finding keil and stm32cube like reading ancient symbols on pharos pyramids  Shocked

is there tutorials on using the HAL libraries , because they are still new  Undecided Undecided Undecided Undecided Undecided
Logged
Espark
Newbie
*
Offline Offline

Posts: 12

Thank You
-Given: 5
-Receive: 2


« Reply #50 on: December 09, 2015, 10:58:04 10:58 »

It appears that : when an interrupt occur the system does to: IRQ_Handler
inside this function you can either write your own routine and clear interrupt flag using macro
or let HAL service the interrupt by HAL_UART_IRQHandler. and write your routine after that or in a call back function .

still donot know which is better practice , and wether using the HAL handler is consuming too much CPU cycles

Logged
TucoRamirez
Senior Member
****
Offline Offline

Posts: 307

Thank You
-Given: 257
-Receive: 115


Tuco ... dead or Alive


« Reply #51 on: December 09, 2015, 06:41:14 18:41 »

dunno, i'm a barebone guy and i use the IRQ_Handlers on IAR with the startup.s corresponding file...    i'll get into HAL this holidays ...  i think ...   
Logged

Whoever double crosses me and leaves me alive... he understands nothing about Tuco.
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #52 on: December 10, 2015, 03:53:12 15:53 »

if someone worked with USART using interrupts , can u tell me how to specify the source of interrupt ( tx or rx or error ) , because in cubemx you just set a global interrupt enable. ( i guess i have to use the macro : __USART_ENABLE_IT() , but i donot know when or where )

and how is the HAL_USART_RECIEVE_IT() used ? should it be called once ??

where is the interrupt service routine ( something similar to __void interrupt handler () in PIC ) or is this the same as call back function

STM32CubeMX is only an initialization code generator, after that what we need is to open the HAL library reference manual (UM1725 for F4).

For every interrupt function enabled, CubeMX will generate IRQ_Handler on stm32Xxx_it.c file. Right click the function called inside the handler and select "go to definition of..", it will open corresponding HAL driver file - here we will need to read the reference manual.

We need to write our own code for HAL_UART_RxCpltCallback and HAL_UART_TxCpltCallback to handle the data on interrupt RX/TX, those function define as empty weak function on HAL library which will be overwritten by user code. See the UART samples on the repository project sample.

One annoying thing with HAL USART library is we need to know the data length both for RX and TX, most of the the receive function has no info how is the length of the data will be received but use termination character as end of data signal. On this case USART with DMA is the way out, google has some info about this.

-ichan
Logged

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

Posts: 12

Thank You
-Given: 5
-Receive: 2


« Reply #53 on: December 14, 2015, 09:47:27 09:47 »

thank you chan for your reply . I will clarify how i am working now for others to benefit or comment,
 i just didnot find the HAL_XXX_IRQHandlers to suit my taste , so what i am doing now is commenting this line and writing my own routine or function inside USART1_IRQHandler , the most important thing to remember is to clear the corresponding bit using macro :__HAL_UART_CLEAR_FLAG(&huart1,UART_FLAG_RXNE) . Since i have disabled all the other interrupts of usart (like txe ,tc ,pe , ne ,ore ....) hal handler go check for each of these and clear them then it call another function called receive or transmit then it calls a call back function , because it is a very generic function. what  a waste of CPU power !!!!!
I also find the interrupt method inconvenient because if i have a 20 char message send every 100ms , contain header , address checksum ....
if i ask the HAL_Receive_IT to get 20chars for me , maybe the header is not the first among them , then i will get incomplete message , so i have to read again ...etc
instead on each character received i interrupt save this character in a 255 size array , and later i access this array to search for header , and other message parameters ( basically i created something like the arduino serial library ) Roll Eyes)))
« Last Edit: December 14, 2015, 09:50:27 09:50 by Espark » Logged
neodimio91
Newbie
*
Offline Offline

Posts: 7

Thank You
-Given: 10
-Receive: 1


« Reply #54 on: January 21, 2016, 03:30:38 15:30 »

Hey guys I'm new on the forum ! I hope I'm not OT here, years ago I developed some libraries and examples using my stm32 discovery with stm32f100RB on board ( if someone interested I ported some libraries or fixed to work on the discovery for example chips like MPU6050,MS5611,HMC5883L,nRF24L01P,ST7735).
 I'm approching with the new MDK of keil on the uVision5 ,I opened the old project from uVision 4 but trying to convert it (not the legacy import) .I experienced problems building the project ( it worked great with uVision 4).
I ran manage run time inviroment suggested from here  www.keil.com/forum/24398/ and add device and peripherals I'm using on the project ,but errors increase bulding the project :C e.g ..the first is "no source": Error:  #5: cannot open source input file "..\..\..\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\system_stm32f10x.c": No such file or directory
Anyone can help me a little ?
thanks
P.S no problem at all with the legacy import
« Last Edit: January 21, 2016, 04:24:44 16:24 by neodimio91 » Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #55 on: January 21, 2016, 07:55:37 19:55 »

you need to see where the missing files are, and check if you are using the correct library version. Also, you might need to install the the legacy support pack in case you have not installed it yet.
Logged
neodimio91
Newbie
*
Offline Offline

Posts: 7

Thank You
-Given: 10
-Receive: 1


« Reply #56 on: January 22, 2016, 12:40:27 00:40 »

you need to see where the missing files are, and check if you are using the correct library version. Also, you might need to install the the legacy support pack in case you have not installed it yet.
Yeah with the legacy library everything works, my intent was only to undestand if someone has experienced a import to the new MDK ,I'll try a new project with the new one so maybe I'll find a solution about the system_stm32f10x.c that compiler isn't able to find !
Logged
h0nk
Senior Member
****
Offline Offline

Posts: 256

Thank You
-Given: 208
-Receive: 230



« Reply #57 on: January 22, 2016, 11:09:20 11:09 »


Hello neodimio91,

You have installed the ST "STM32F10x_StdPeriph_Lib_VX.Y.0" somewhere.
The file "system_stm32f10x.c" You will find at the directory:
"\$INSTALLDIR\stm32f10x_stdperiph_lib\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\"

This file is also included in the software pack: "Keil.STM32F1xx_DFP.2.0.0.pack"
You should try to install the pack and configure Your project to use it.


Best Regards
Logged
neodimio91
Newbie
*
Offline Offline

Posts: 7

Thank You
-Given: 10
-Receive: 1


« Reply #58 on: January 22, 2016, 09:23:46 21:23 »

Hello neodimio91,

You have installed the ST "STM32F10x_StdPeriph_Lib_VX.Y.0" somewhere.
The file "system_stm32f10x.c" You will find at the directory:
"\$INSTALLDIR\stm32f10x_stdperiph_lib\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\"

This file is also included in the software pack: "Keil.STM32F1xx_DFP.2.0.0.pack"
You should try to install the pack and configure Your project to use it.


Best Regards


Thanks! Tomorrow I 'll give a try and I'll post the result, I think that something goes wrong during installation cuz in legacy mode everything goes right ,debug mode too!
Logged
metyusan
Newbie
*
Offline Offline

Posts: 11

Thank You
-Given: 13
-Receive: 3


« Reply #59 on: February 03, 2016, 10:02:43 10:02 »

Hi,

I am working with the EMWIN on stm32f429-discovery board. Demo code examples work for portrait mode. I could not perform the landscape layout for both GUI windows and touchpad.

Does anybody who does this?

Thanks for reply..
Logged
neodimio91
Newbie
*
Offline Offline

Posts: 7

Thank You
-Given: 10
-Receive: 1


« Reply #60 on: March 02, 2016, 04:51:22 16:51 »

Hi,

I am working with the EMWIN on stm32f429-discovery board. Demo code examples work for portrait mode. I could not perform the landscape layout for both GUI windows and touchpad.

Does anybody who does this?

Thanks for reply..

Hi,
Do you try to compile and load to the dev board from a different IDE( or older ide version)? Maybe you have some wrong settings, maybe with a old version IDE the problem disappear ,so from it, you can debug and find where is the problem.
I had a similar problem, maybe you are compiling with a IDE not native for your demo project ,check it out!
But wait ,are you sure that your code has this feauture? maybe is not implemented yet
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #61 on: March 02, 2016, 04:57:54 16:57 »

STM32 ST-LINK Utility requires you reloading the file after each successful compile. it doesn't take the latest version of the file automatically.
Logged
avrlover
Active Member
***
Offline Offline

Posts: 115

Thank You
-Given: 50
-Receive: 217


« Reply #62 on: November 09, 2016, 03:49:48 03:49 »

very good presentation on stm32cube links are at bottom
https://blog.brichacek.net/stm32f4-discovery-kit-pro-stm32f429/


https://blog.brichacek.net/wp-content/uploads/2015/10/STM32Cube-Presentation.pdf
https://blog.brichacek.net/wp-content/uploads/2015/10/STM32F4-and-FreeRTOS.pdf
https://blog.brichacek.net/wp-content/uploads/2015/10/STM32F4-Labs.pdf
https://blog.brichacek.net/wp-content/uploads/2015/10/STM32F4-and-USB.pdf



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

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #63 on: March 10, 2017, 09:47:08 09:47 »

any one succeeded using cubeMX with uncleo-429Z for at least a ping :S
Logged
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