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.
Related
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!
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).
I have a Linux driver for an external MCU application. The driver and the MCU communicate over a bus using our own protocol.
I would like to share the program code for the protocol features between the kernel module and the MCU but since it's not possible to build a lib for the kernel my only idea so far is to write the code "as kernel as possible" and then just copy the entire .c file between the platforms.
Are there any other ways? Surly I can't be the first to want to do this.
I'm talking about code reuse, not IPC mechanisms.
Thanks!
It requires some hardware abstraction so the code implementing the protocol needs to be generic as possible not requiring any hardware specific details.
The file implementing the protocol could have functions like init, exit, read, write and interrupt. The hardware implementation itself (gpio, memory, bus) can be accessed through function pointers which are registered at time when calling the init function. The directory structure can be set up like #smbear suggested
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.
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.