Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 16, 2019, 06:01:58 06:01


Login with username, password and session length


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

Posts: 2212

Thank You
-Given: 671
-Receive: 567


Top Topic Starter


« Reply #25 on: February 13, 2015, 05:34:04 05: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: 387



WWW
« Reply #26 on: February 13, 2015, 03:16:50 15: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: 387



WWW
« Reply #27 on: February 15, 2015, 03:41:34 15: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: 2212

Thank You
-Given: 671
-Receive: 567


Top Topic Starter


« Reply #28 on: February 25, 2015, 04:08:35 16: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: 387



WWW
« Reply #29 on: February 27, 2015, 01:03:27 13: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: 2212

Thank You
-Given: 671
-Receive: 567


Top Topic Starter


« Reply #30 on: March 03, 2015, 12:05:12 00: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, 10:38:01 10:38 by metal » Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #31 on: March 04, 2015, 11:01:04 11: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: 2212

Thank You
-Given: 671
-Receive: 567


Top Topic Starter


« Reply #32 on: March 04, 2015, 02:11:42 14: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, 02:14:15 14:14 by metal » Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #33 on: March 18, 2015, 11:49:52 11: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: 387



WWW
« Reply #34 on: September 26, 2015, 02:54:31 14: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: 387



WWW
« Reply #35 on: September 29, 2015, 10:04:49 10: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: 387



WWW
« Reply #36 on: October 03, 2015, 01:14:56 13: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: 387



WWW
« Reply #37 on: October 04, 2015, 01:19:21 13: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, 01:24:28 13:24 by Ichan » Logged

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

Posts: 833

Thank You
-Given: 312
-Receive: 387



WWW
« Reply #38 on: October 10, 2015, 11:43:43 11: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: 387



WWW
« Reply #39 on: October 13, 2015, 01:30:38 13: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: 387



WWW
« Reply #40 on: October 18, 2015, 10:14:13 10: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: 387



WWW
« Reply #41 on: October 21, 2015, 01:46:50 13: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
*
 Muted
Offline Offline

Posts: 8

Thank You
-Given: 5
-Receive: 0


« Reply #42 on: November 18, 2015, 01:25:23 13: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: 387



WWW
« Reply #43 on: November 18, 2015, 04:04:52 16: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
*
 Muted
Offline Offline

Posts: 8

Thank You
-Given: 5
-Receive: 0


« Reply #44 on: November 19, 2015, 02:14:30 02: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, 05:30:49 05: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: 15

Thank You
-Given: 14
-Receive: 1


« Reply #46 on: November 27, 2015, 03:33:13 15: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: 15

Thank You
-Given: 14
-Receive: 1


« Reply #47 on: December 02, 2015, 12:19:48 12: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: 387



WWW
« Reply #48 on: December 06, 2015, 09:25:47 09: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
*
 Muted
Offline Offline

Posts: 8

Thank You
-Given: 5
-Receive: 0


« Reply #49 on: December 06, 2015, 11:28:49 23: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
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