Spark Logic

[SOLVED] AVR SREG emulation

STM32F103C8T6 Example · LQFP48 Pinout

Arduino:
   uint8_t sreg = SREG;
cli();
// critical region
SREG = sreg;

Replies11

Thu Jun 09, 2016 5:48 pm

STM32F103STM32F103Microcontrollers and processors…19.html . ag123 Sat Apr 28, 2018 5:54 pm come to think of it blue pill / maple mini ( stm32f103 ) is an *ideal* keyboard controller, the scanning can be done with assistance of sh…View in hardware catalog has status registers.
Just not AVRAVRMicrocontrollers and processors…Arduino\libraries\U8glib\U8glib.cpp, C:\Program Files (x86)\Arduino\hardware\arduino\ avr \cores\arduino\HardwareSerial.h, C:\Program Files (x86)\Arduino/Blink3.ino, D:\Users\me\A…View in hardware catalog 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 STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog Microcontroller – Computer Science Google for it.

Ray

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 STM32STM32Microcontrollers and processors…Map magic glue code, ethernet compiles, just WARNING: library LwIP claims to run on [ stm32 ] architecture(s) and may be incompatible with your current board which runs on [STM32]…View in hardware catalog 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”

Fri Jun 10, 2016 11:16 am

Thank’s……i find my to do for the week end. :D :D

Fri Jun 10, 2016 11:25 am

peppeve wrote:Thank’s……i find my to do for the week end. :D :D

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-M3Cortex-M3Microcontrollers and processors…get this error arm-none-eabi-g++: error: unrecognized command line option '-CC -mcpu= cortex-m3 ' RogerClark Sun May 15, 2016 6:25 am Fixed it @vassilis do a pull from my repo to…View in hardware catalog and Cortex-M4Cortex-M4Microcontrollers and processors… the Due form factor) e.g. … 4de7935aae Mini-version-STM32F407VET6-development-board- Cortex-M4 -STM32-minimum-system-board.jpg Mini-version-STM32F407VET6-development-board-Cortex…View in hardware catalog 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

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-M3Cortex-M3Microcontrollers and processors…get this error arm-none-eabi-g++: error: unrecognized command line option '-CC -mcpu= cortex-m3 ' RogerClark Sun May 15, 2016 6:25 am Fixed it @vassilis do a pull from my repo to…View in hardware catalog and Cortex-M4Cortex-M4Microcontrollers and processors… the Due form factor) e.g. … 4de7935aae Mini-version-STM32F407VET6-development-board- Cortex-M4 -STM32-minimum-system-board.jpg Mini-version-STM32F407VET6-development-board-Cortex…View in hardware catalog 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. :(

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

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();

Sat Jun 11, 2016 9:04 pm

can you give me an example where this is used ?

Sun Jun 12, 2016 3:57 am

RogerClark wrote:can you give me an example where this is used ?

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;
}

Post a reply

Optional · up to 10 MiB