Square Wave Generation on STM32F407
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-10-25 2:13 AM
Hi,
I am a beginner and I want to generate a 50Hz square wave on STM32F407 on Keil UVision4
Please mention libraries etc that are being used and if you can how to add them to Keil UVision so it doesn't give an error.
Solved! Go to Solution.
- Labels:
-
STM32F4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-15 1:13 AM
Hi @Zaidii1122 ,
As you are a beginner and if you don't want to use a timer but just GPIOs, you can simply toggle the pin you want at 20ms (1/50Hz) using: HAL_Delay(20). But this in not the way we recommend a such usage.
This is an example jhow to toggle the pin 5 on GPIOA:
/* -1- Enable GPIOA Clock (to be able to program the configuration registers) */
__HAL_RCC_GPIOA_CLK_ENABLE();
/* -2- Configure PA05 IO in output push-pull mode to
drive external LED */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* -3- Toggle PA05 IO in an infinite loop */
while (1)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
/* Insert delay 20 ms */
HAL_Delay(20);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-10-25 6:46 AM
Use the Example Selector in CubeMX to generate a PWM example project.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-07 4:35 AM
Hi , Thanks for this but i have to complete this on Keil Uvison 4 Software
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-07 6:13 AM - edited ‎2023-11-07 6:27 AM
Hello,
If you can't use CubeMX tool for code configuration/generation, you can also refer and inspire from the example provided in STM32CubeF4 under the path STM324xG_EVAL\Examples\TIM\TIM_PWMOutput
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-14 7:06 PM
I have to use the Board STM32F407VGT6 and the example offers to measure an external signal while I want to output a square wave on any of the output pins of the board without any external signal. Could you please guide how to do that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-14 7:39 PM
That's a CHIP, whats the make/model of BOARD? Are you talking about the STM32F4-DISCOVERY board?
Can you use the old SPL library with uV4 ?
https://www.st.com/en/embedded-software/stsw-stm32068.html
STM32F4-Discovery_FW_V1.1.0\Project\Peripheral_Examples\TIM_PWM_Output\main.c
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-14 7:43 PM
I will try this rn and get back to you Thank you sm
Plus do have any videos or resources that can help me in learning how to use stm32cube ide to accomplish the task or can you explain it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-14 7:51 PM
I'm from a generation that reads the manual.
https://legacy.cs.indiana.edu/~geobrown/book.pdf
https://github.com/nalepae/stm32_tutorial
https://github.com/RobGah/Discovering_STM32
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-11-15 1:13 AM
Hi @Zaidii1122 ,
As you are a beginner and if you don't want to use a timer but just GPIOs, you can simply toggle the pin you want at 20ms (1/50Hz) using: HAL_Delay(20). But this in not the way we recommend a such usage.
This is an example jhow to toggle the pin 5 on GPIOA:
/* -1- Enable GPIOA Clock (to be able to program the configuration registers) */
__HAL_RCC_GPIOA_CLK_ENABLE();
/* -2- Configure PA05 IO in output push-pull mode to
drive external LED */
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* -3- Toggle PA05 IO in an infinite loop */
while (1)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
/* Insert delay 20 ms */
HAL_Delay(20);
}
}
