What is name of the timer/counter overflow interrupt in stm32 - timer

I am using timer in input capture mode in STM32 micro with keil compiler, and I want to trigger an interrupt whenever counter register of the dedicated timer overflows.
Could anyone please tell me how i can do that? what is the name of this interrupt?
Note: I am using hal functions.

Please check out the (exact) controller type you are using on the STM homepage (you can start from here:
https://www.st.com/en/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus.html
On the product page for your controller, you'll find a useful list of PDFs under "Resources", especially
the Reference Manual (find the register descriptions in the TIM description of the timer you use)
a list of Application Notes, which are relevant for all STM32 families, especially
AN4776
General-purpose timer cookbook for STM32 microcontrollers
https://www.st.com/resource/en/application_note/dm00236305-generalpurpose-timer-cookbook-for-stm32-microcontrollers-stmicroelectronics.pdf
and
AN4013
STM32 cross-series timer overview
https://www.st.com/resource/en/application_note/dm00042534-stm32-crossseries-timer-overview-stmicroelectronics.pdf
Looking for the correct library functions, you can use STM32CubeMX to configure the timers in a GUI and have the correct driver codes generated for you.
Good luck!

Related

How to convert STM32 snippet (code examples) written for target device STM32F072B to STM32F030r8

Dears,
I am newbie in embedded systems.
I have downloaded code examples from st.com written for target device STM32F072B. As I am using Nucleo-64 with STM32F030r8 MCU, I need to convert the downloaded code examples to support my target device STM32F030r8.
I can build the code examples (written for STM32F072B) in Keil, but when I am changing the target device to STM32F030r8 I am getting an error:
..\system_stm32f0xx.c(301): error: #20: identifier "RCC_CFGR_PLLSRC_HSI48_PREDIV" is undefined
Please help me either by telling the way to convert the downloaded code examples to support my target device STM32F030r8.
Regards
Niyas
Welcome to the exciting world of embedded systems where peripherals even change within sub-families of devices.
The missing macro your compiler complains about is actually a pretty good hint on whats wrong. Looking at the STM32F072B reference manual ST lists the following available clock sources:
Various clock sources can be used to drive the system clock
(SYSCLK):
HSI 8 MHz RC oscillator clock
HSE oscillator clock
PLL clock
HSI48 48 MHz RC oscillator clock (available on STM32F04x, STM32F07x and STM32F09x devices only)
Comparing that to the STM32F030 reference manual we can see that the HSI48 clock is clearly missing on this device.
Various clock sources can be used to drive the system clock
(SYSCLK):
HSI 8 MHz RC oscillator clock
HSE oscillator clock
PLL clock
I guess that some part of the code snippet you downloaded tries to use that missing HSI48 clock somehow. Switching the device inside the IDE most likely caused your project to use another device header where the macro "RCC_CFGR_PLLSRC_HSI48_PREDIV" simply isn't defined. You might be able to use another clock source instead, but your question doesn't contain enough information to answer that for certain.
Generally when working with embedded devices you have to be very careful when switching from one microcontroller to another. Even the tiniest differences (even a single register or a single bit) can break your build or even worse your hardware.
Thank-you Dears,
I found the answer. Guillaume Petitjean 's reply made me to read more documents and finally I made it.
Question:
The STM32SnippetsF0 (C-code examples) downloaded from https://www.st.com/en/embedded-software/stm32snippetsf0.html#overview is designed to run on the STM32F072B Discovery board. So changing target device(my case STM32F030r8) need many changes like adding supported header files etc.
*I got the mentioned error previously because I compiled simply after changing target device in setting but without adding proper header file. :(
*I was asking this. Don't know whether I asked properly. Anyway the solution i found is sharing with you all.
Answer:
This document tells how the snippet code can be used on other target device
https://www.st.com/resource/en/data_brief/stm32snippetsf0.pdf
After reading the document and adding necessary driver header files I am able to compile and build the code

Different between Systick and Timer in ARM M4

I completed a basic microprocessor with 8051. In this course I learned using a timer to trigger an event. After a semester, I learned programming Embedded System with ARM Cortex M4 (Tiva C launchpad) and started to use Systick to trigger event ( almost used in FreeeRTOS) and sometimes it is used as a timer.
I wonder what different between timer and systick? Because sometime I
think systick behavior is the same as timer. I have searched the
differ, and know: systick is in arm core and timer is of chip vendor.
And which situation we should use systick intead of using timer?
Please let me know. Thank you.
You basically have it. The systick timer is part of the ARM core. And the other timer(s) are from the chip vendor. You, the programmer are free to use them however you wish.
They most likely have different features, the systick timer is pretty much only for polling or interrupts of simple durations. Where the chip vendor timers can do those things usually and much more, sometimes they can generate clocks for other timers sometimes they can generate clocks or signals that go out a pin, sometimes they can time inputs. Sometimes a vendor will have multiple timers in a chip and those timers have features different from each other. It varies widely.
Note some ARM cores do not have a systick timer or lets say the chip vendor has the option to compile the core without it. In those situations your only choice is the chip vendor supplied timers.
There is no magic here you are the programmer you are free to use the peripherals as you wish.
Now if you use an RTOS like FreeRTOS or others, then your freedom is limited to what the RTOS does not consume for itself (it will likely consume the systick timer if present, but leave others).
The reasoning behind this is any OS developer can write code for any Cortex-M which has SysTick, and not need to worry about the vendor specific details. There is a guarantee that SysTick always works the same way across a wide range of devices so there is less low-level porting to be done.
Same for your course, if you are writing bare metal, you don't need to worry about the device vendor until you use their peripherals (timer, uart, watchdog).

CMSIS and peripherals drivers

what types of codes are written in CMSIS files and peripheral drivers file. How can I distinguish them? any example would be more helpful. Thank you.
"CMSIS" is the Cortex Microcontroller Software Interface Standard. It's an ARM standard, so the code should be more or less portable between Cortex implementations.
Peripheral libraries generally are more vendor-specific, since there's no standard for how two different vendors will implement e.g. a timer or a UART block.
At least, that's my basic understanding from working (mostly) with ARMs in the STM32 family. However, I notice on that CMSIS page that the scope for CMSIS is actually larger:
CMSIS-Driver: defines generic peripheral driver interfaces for middleware making it reusable across supported devices. The API is RTOS independent and connects microcontroller peripherals with middleware that implements for example communication stacks, file systems, or graphic user interfaces.
That sounds like it'd do things that I associate with vendor-specific code, but perhaps not all vendors actually use CMSIS-Driver yet.
UPDATE: On the STM32:s I've worked with, GPIO is managed using only ST's peripheral library.
It's pretty easy, really:
Use RCC_AHB1PeriphClockCmd() to enable the GPIO peripheral's clock. There are many clocks so make sure you do it right. I think all the GPIO is on AHB1.
Initialize a variable of type GPIO_InitTypeDef by calling GPIO_StructInit() on it to get the defaults.
Set the settings you really want in your GPIO_InitTypeDef, overriding the defaults as needed.
Call GPIO_Init() on the proper port, also passing it the GPIO_InitTypeDef with your actual settings. This will poke registers in the peripheral.
Use calls like GPIO_SetBits(), GPIO_ReadInputDataBit() et cetera to actually use the GPIO pin.
CMSIS code are written for the ARM controller for different vendor like NXP (LPC series etc.) STM (STM32f4, stm32F1 ) basically the controller which has ARM architecture. this is portable software. this coding language is C/C++ most of the time but in some file assembly language is used. generally the assembly language are used in startup files.
In the peripheral driver the code are written in c/c++ language. peripheral driver are used to communications purposes.
I'm currently working on the LPC18xx controller, using the CMSIS driver, the CMSIS driver has code for all the peripherals, you can use the driver directly to implement your application
for example : if you want to read the data from the sensor connected via I2C.
you can directly used the I2C Cmsis driver to implement application. only thing you need to know this the hardware address to the sensor.
similarly you can use SPI driver, CMSIS also provide RTOS driver.

how to Register for listener in Accelerometer using C

I am working on an STM32f2xx processor eval board, with LIS3lv02dh accelerometer chipset.
I have been able able to program the accelerometer to wakeup the processor on interrupt based on the Threshold level change in accelerometer, but how do I register for events during wakeup.
How do I register an accelerometer sensor handler so that when an interrupt occurs, the application code is notified.
You need to read and understand the STM32f2xx User Reference Manual. You have no OS (I guess) and generic Google searches will not help you; the problem is very specific to the parts you are using.
The STM32F2xxx Standard Peripheral Library (downloadable from ST's site) contains numerous examples for all peripherals including I believe using wake-up sources.
If the accelerometer is included on the evaluation board, I would imagine that it includes example code or a support library that may help.

How to use the interrupt handler in FreeRTOS?

Hi I'm trying to use the OpenPicus devKit for a project I am working on and to my understanding the IDE, upon new project creation, creates code that basically utilizes FreeRTOS and OpenPicus libraries.
What I am trying to figure out is how to use interrupts with the FreeRTOS kernel, or through OpenPicus (i dont think this is possible). I have read that the ISRs in FreeRTOS can be specified with the __attribute__ ( ( signal ) ) directive but how are they linked to specific interrupts?(uart or even a pin just going high?)
Interrupt handling is architecture, and often compiler specific rather than specific to FreeRTOS. FreeRTOS itself only defines what RTOS calls are valid in an ISR.
The OpenPicus hardware uses a PIC24. The FreeRTOS demo code for PIC24 includes a timer interrupt and serial interrupt examples in [...]\Demo\PIC24_MPLAB\timertest.c and [...]\Demo\PIC24_MPLAB\serial\serial.c respectively. The examples use Microchip's PIC24 compiler syntax. If you are using an alternative compiler, you will need to consult its documentation.

Resources