I using inline assembly to enable a bit in counter control register. I am looking out for the apt code in inline-assembly. I used the following code for an Infineon TriCore micro-controller.
__asm("ENABLE CCTRL.CE");
Please guide me in writing the correct code. In the above code, I will need to set 1 to the bit CE in Counter Control register (CCTRL). Please help.
A quick scan of the instruction set shows that the ENABLE command is used to enable interrupts. You probably want the ST.T instruction. There should be something in the SDK which maps the CCTRL register to a given memory address or variable name.
Related
I'm trying to learn and master embedded C, so I was just gonna test a code that I found on Github, which is built for STM32F4 discovery board. The board that I'm actually working on is STM32L152. when I tried to build/run the code (obviously it won't work) the errors I'm getting are mostly related to functions not being defined or "identifier 'function_name' is undefined", note that the code file includes a library (lib).
take a look at the code file:
https://github.com/TDAbboud/STM32F4_Examples/tree/master/04_PWM_Servo
Generally speaking, What modifications should be done to successfully run the code on STM32L1?
Thanks
These are two different chips. Just because they are from ST just because they are ARM based, they are not the same chip. for starters the stm32f4 is a cortex-m4 the stm32l might not be, 99.9% of your code wont care, just some assembly might. if the stm32l is a cortex-m0 then you have far fewer instructions so the assembly will matter if it is a cortex-m3 then it wont.
The real isssue is peripherals not that this is two st chips not that this is two arm chips, the peripherals can/will vary. ST has a number of chips that use the same uart or same gpio or other, but they have more than one uart they use for STM32 chips, and more than one GPIO. And they mix and match as they make new chips, so if you want to port from one to the other you need to go peripheral by peripheral reading the new and old docs to see what if anything changed.
Sounds like you are using a library so the tool may know from the chip you have chosen what peripherals you have and which library you need, so it might not be finding them because for that chip that peripheral and thus that function and those defines do not apply. Take it one perpheral at a time and port between chips.
stm32 (L) serise incloud EEPROM which are important when they go to sleep mode and want to recover variables after wakup . so make sure application is running in sleep modes need to save data somewhere. so if you use STM (F) series care needs to attache a external EEPROM
In ARM Cortex-M4F MCU (TM4C1294NCPDT specifically), to deal with interrupts (GPIO interrupts), one of the steps to get the interrupts working is to clear the I BIT.
I searched a lot but I couldn't find any useful information about that, could anybody please tell me where to find that bit exactly and how to edit it if I need some special procedures?
And that will be great if I have been told where to find that information exactly after the explanation please (to learn how to answer myself on any other questions).
The CMSIS provides a standard cross-vendor software interface to Cortex-M based devices. The CMSIS defines a number of functions for interacting with the NVIC and PRIMASK including the intrinsics __disable_irq()/__enable_irq()
The ARM Cortex-M interrupt system is quite complicated and very well thought. It consists of CPU registers and a tightly coupled interrupt controller (NVIC). Interrupts are prioritized and vectored. There is no single interrupt-enable flag as for smaller 8/16 bit MCUs.
For each interrupt, there are two ARM-core instances to gate the event to the CPU: The CPU PRIMASK register (single bit), which can be seen most similar to the classical interrupt-enable flag. Second is one enable bit in the NVIC. For these, there is an ARM standard in the CMSIS headers. These provide functions __enable_irq() and __disable_irq() for the PRIMASK bit. The peripheral interrupt itself has to be controlled by NVIC_EnableIRQ(IRQn_Type IRQn) where IRQn is the interrupt number as defined in the MCU-specific header file.
Finally, there are most times also interrupt enable bits in each peripheral module as know by the smaller MCUs.
Note that to have an interrupt pass through all gates have to be open (all bits set to "enable"). Use the CMSIS functions to manipuate the bits. They very likely will not take more instructions than a hand-crafted version.
Edit:
There is no actual need to fiddle yourself with assembler or the registers. Just use the CMSIS functions, you can very likely not do better yourself, but possibly worse. That's actually the intention of CMSIS.
(end edit)
Start reading in the reference manual for the MCU and the vendor's homepage. That should provide references and app-notes for the device. You also should read the technical reference manual, architecture reference manual from ARM. Actually, just have a close look at all related documents there for the CPU (M4 for you). These are for free, some require registering.
For the NVIC, you should not access it directly, but using the CMSIS header files as provided by TI for exactly this MCU (the headers require some device-specific settings). If not available,you can get them from ARM, but have to provide the device-specific settings yourself (they are few and are given in the MCU's reference manual).
As the ARM Cortex-M4 has multiple interrupts, you need their symbolic names to enable/disable. These have to be defined in the MCU header which defines all peripheral modules, too (there might be multiple such headers). The names end with _IRQn, just search for that.
To use the Cortex-M4 you should read the documents given, or you can try with a good book. However, as this is no tutorial site, nor is it allowed to recommend books, please search yourself.
OK, the easiest answer for my question is:
To use " CPSID I" or " CPSIE I" inline assembly code which will set or clear the PRIMASK (I) Bit respectively. (of course that will work just in privileged mode).
And both assembly instructions are equivalent to __disable_irq() and __enable_irq() functions in CMSIS respectively.
Am trying to add assembly instructions for timing in pisa architecture using simplescalar simulator. For my instructions i should access clock cycles and store it in the register. This changes has to be made in the machine.def file where all other assembly instructions like add, mul etc are defined.
Am not getting how to access clock cycles in simplescalar simulator? Kindly help
Thank u
I do not know if I got it right, but I think you need to keep the PC value. If this is what you want to do, you can see the used definitions in the beginning of the machine.def file. NPC for next PC, CPC for current PC and SET_NPC/SET_CPC accordingly. So if you want the PC value, you can have it using CPC. Also these definitions are all set in the simulators' files, for example in sim-outorder.c.
For the life of me I can't make a timer for PIC18 or precisely PIC18f87j11. All I want to do is to have a counter that increments every 1 second. I just want to monitor how long PIC18 been running in terms of seconds.
Most of the tutorials out there are for PIC16 and are in assembly. I am trying to do this using C programming. For someone who is beginner I understand better if I see examples, so without examples I can't progress.
please someone show me an example, thank you!
To begin understanding timers you will need to have a look at their documentation. I suggest searching the manufacturers website. There are 5 timer available. If you use Timer0 which is either a 8 bit or 16bit timer. You will need to set the correct configuration for T0CON. Also you will need to have correct interrupt settings (INTCONbits), so a an event can be generated by interrupt service routine once timer expired.
You will most likely need to calculate the prescale value you require for correct timing, in your case 1 second. It does depend on FOsc: Here is a tutorial
Here an example of C code using MPLab and another one based on MPLab and hi-tech compiler. It is not for same chip, however it is based on PIC18F family.
It's been a awhile since I have visited PIC18F, so if any correction required, please do so.
If you use HIGH-TECH compiler, you can simply use its special function for close, open, read and write timers modules in below directory:
...\HI-TECH Software\PICC-18\9.80\sources\plib\Timers
According to your microcontroller name, you can figure out which version of these function is written for your microcontroller. So for first step, open pconfig.h file and search your microcontroller name to see for every module which version is fit to your microcontroller registers.
Good Luck
Following on from my other question, Help optimising this C (AVR) code? :), I just realised that I don't really know the mechanics of how to implement an ISR in assembly within my C program. I googled, but I didn't find anything too useful.
Basically I want to set up everything else in my C project (including the registers to get the interrupt to fire), but I want the interrupt to execute some assembly code that I've written.
I'm using AVR studio 6 on Windows if that helps. I've been told I need to use .s files but apart from that I'm not really sure what to do. Is the basic structure just the following?
#include <avr\io.h>
TIMER1_COMPA_vect:
; assembly instructions here
If I want the assembly to run when the TIMER1_COMPA_vect interrupt is fired (this is the name of the ISR in C). Or am I totally off track? What is a basic template of what I need to do? Or if it's a dumb question, is there a link where I can find more information?
The Art of Assembly Language (by Randall Hyde) has two chapters about ISRs (17th and 18th, specifically sections 18.5 and 18.6 might help you). Shortly:
Go to the IVT (interrupt vector table) and modify it with your ISR segment and offset, saving the old values
You should do a TSR (terminate and stay resident) program, so that your ISR stays resident into memory even when the user closes the window
Remember to call the old ISR after you're done with the work (this is called interrupt chaining)
your ISR should be re-entrant (so that if the interrupt is fired again when your ISR is still running the pc won't explode ;) )
By the way, you can obtain a pdf copy of that great book here