[SOLVED] AVR SREG emulation

peppeve
Thu Jun 09, 2016 4:38 pm
Arduino:
uint8_t sreg = SREG;
cli();
// critical region
SREG = sreg;

mrburnette
Thu Jun 09, 2016 5:48 pm
STM32F103 has status registers.
Just not AVR style registers:
http://infocenter.arm.com/help/index.js … BIBGJ.html

More here: http://docs.leaflabs.com/static.leaflab … ister-maps

I strongly suggest you download & read the official reference before you go off into the land of the registers. Unless you can articulate a precise question and submit sample code for STM, I doubt if anyone here will take too much time to assist you. There is just not enough time to walk through the architecture.

Good read: Discovering the STM32 Microcontroller – Computer Science Google for it.

Ray


ahull
Fri Jun 10, 2016 9:44 am
Not just a good read, I would go further and say this should be on the required reading list for anybody who is interested in the STM32 Discovering the STM32 Microcontroller – Computer Science … there… I saved you the trouble of Googling it. :D Furthermore it has recently been updated.. Latest revision “June 5, 2016”

peppeve
Fri Jun 10, 2016 11:16 am
Thank’s……i find my to do for the week end. :D :D

ahull
Fri Jun 10, 2016 11:25 am
peppeve wrote:Thank’s……i find my to do for the week end. :D :D

zmemw16
Sat Jun 11, 2016 2:05 am
@ahull
you beat me to posting the gbrown update ! i’ve just put it up elsewhere

the second one, make sure you get the 850+ page version, it adds in the M4 and 400 odd pages. mine via Amazon

Greenwich_Books included the following items in package 1 of this shipment:

The Definitive Guide to ARM Cortex-M3 and Cortex-M4 Processors

i’m not sure the price on the invoice was the same as on the product page, maybe £5 or £7 less
definitely new and substantially packaged, impressed.

stephen


ahull
Sat Jun 11, 2016 2:28 am
I’m not sure my current corporate evil overlords will stump up the readies for a copy of “The Definitive Guide to ARM Cortex-M3 and Cortex-M4 Processors” and I’m not sure my pocket money can justify the hit either, so I may have to stick with the hookey downloaded version I linked to of the 2nd edition for the time being. :(

zmemw16
Sat Jun 11, 2016 5:45 am
now i almost wish i’d known of one or thought to look for one

my last group leader once tried to make me apologize for buying a book on something.
wrong move, i’ll never do that.
now if he’d said perhaps its wasn’t quite the right one, i might have agreed

stephen


peppeve
Sat Jun 11, 2016 2:41 pm
I add the code below at the wirish.h core file and the compatibility with the Arduino functions seem to be restored

class SREGemulation
{
public:
operator int () const __attribute__((always_inline)) {
uint32_t primask;
asm volatile("mrs %0, primask\n" : "=r" (primask)::);
if (primask) return 0;
return (1<<7);
}
inline SREGemulation & operator = (int val) __attribute__((always_inline)) {
if (val & (1<<7)) {
interrupts();
} else {
noInterrupts();
}
return *this;
}
};
extern SREGemulation SREG;

inline unsigned char digitalPinToInterrupt(unsigned char Interrupt_pin) { return Interrupt_pin; }

#define sei() interrupts();
#define cli() noInterrupts();


RogerClark
Sat Jun 11, 2016 9:04 pm
can you give me an example where this is used ?

peppeve
Sun Jun 12, 2016 3:57 am
RogerClark wrote:can you give me an example where this is used ?

Kot_dnz
Tue Jun 06, 2017 3:47 pm
Example how to I use it – wheel rotation speed calc.
Doesn’t matter the sensor principal.

void setup() {
pinMode(SpeedCountPin, INPUT_PULLUP); // interrupt count pin
attachInterrupt(digitalPinToInterrupt(SpeedCountPin), iCounter, RISING);

Timer3.setChannel1Mode(TIMER_OUTPUTCOMPARE);
Timer3.setPeriod(500000); // in microseconds
Timer3.setCompare1(1); // overflow might be small
Timer3.attachCompare1Interrupt(handler_led);
}

// motor speed counter interrupt
void iCounter(void){
mCount++;
}

void loop() {
[skip - not important] }

// 0.5Hz timer for blinking and count the speed
void handler_led(void) {
toggle ^= 1;
digitalWrite(LED_PIN, toggle);
// calculate the speed
mSpeed = mCount*60*2/3; // count * 60 sec * 2 per sec / 3 segments on a wheel
mCount = 0;
}


Leave a Reply

Your email address will not be published. Required fields are marked *