News for hackers. Stuff that matters.
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by MuffinFlavored on Friday April 03, 2020 @06:37PM (#22774609)
Is there a better way to sleep/delay other than what basically seems like 100% CPU usage in a subtraction loop?
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by roland35 on Friday April 03, 2020 @07:48PM (#22775014)
On ARM Cortex M4 devices like the STM32 there is a simple timer called SysTick used for exactly this type of purpose! You only need to set up a clock divider and you start it up- now you have a regular interrupt at whatever frequency you need!
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by inamberclad on Friday April 03, 2020 @06:47PM (#22774676)
Nearly every microcontroller has at least one free-running timer that can be used to either reset or wake the processor, if you care about power.
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by rdc12 on Friday April 03, 2020 @06:48PM (#22774682)
The other approach to delay's (keep in mind, that there is no other process to yield the CPU too) is to use a timer (a peripheral of the micro controller).

This would take a fair bit more code to configure the timer, and setup an interrupt to handle the timer.

Re:How to flash an LED: writing ARM assembly for an STM32 mi... by MuffinFlavored on Friday April 03, 2020 @09:01PM (#22775345)
How do multiple processes usually 'share' a timer?
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by rdc12 on Friday April 03, 2020 @10:00PM (#22775593)
Microcontrollers (assuming no RTOS in use), typically don't have multiple processes, they have the main thread of execution (which in the article is the entire program) and have interrupt routines that a run in response to an external event (in this case, the timer has expired).

Using the interrupt driven approach, can led to better performance both in CPU time (async communication with slower periphials etc) and battery life (sleep states).

Re:How to flash an LED: writing ARM assembly for an STM32 mi... by detaro on Friday April 03, 2020 @09:02PM (#22775353)
by either having the timer fire regularly and have run code to figure out what needs to be done now, or having code to set it to the time to the next needed interrupt
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by ex3ndr on Friday April 03, 2020 @07:17PM (#22774860)
Jokes aside one of the easiest ways (for developer) to do so is just run JS on it since it have sleepy event loop built in. Works wonderfully with Espruino. So sad that it is not as widespread as should be.
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by nolok on Friday April 03, 2020 @07:36PM (#22774953)
I think you missed the point, which in this case would be "how does that js engine does it". If it does it the same way then it doesn't answer him at all.
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by dmitrygr on Friday April 03, 2020 @06:44PM (#22774654)
if you have an OS, yes
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by lochsh on Friday April 03, 2020 @06:46PM (#22774670)
You don't need an OS to do more advanced or efficient sleeping. You could have one of the timer peripherals generate an interrupt on a regular basis, and then put the chip in a lower power sleep mode in between interrupts.
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by saagarjha on Friday April 03, 2020 @06:57PM (#22774735)
Isn't that what an OS would do, essentially?
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by lochsh on Friday April 03, 2020 @07:00PM (#22774760)
Yes, probably! But you can do it yourself without one.

Here is an example in C using libopencm3, that uses timers to trigger an interrupt used to flash LEDs https://github.com/libopencm3/libopencm3-examples/tree/maste...

Re:How to flash an LED: writing ARM assembly for an STM32 mi... by dmitrygr on Friday April 03, 2020 @08:13PM (#22775114)
that is basically a mini-os :)
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by foldr on Saturday April 04, 2020 @07:15AM (#22777596)
You can set up a wakeup interrupt using a timer by moving a few values into a few registers. It doesn't require anything like an OS. Even tiny 8-bit microcontrollers can do this.
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by als0 on Friday April 03, 2020 @07:34PM (#22774941)
Sure, but putting the chip to sleep is one instruction, and programming the timer interval is only about a dozen instructions. So you don't really need an OS in this context.
Re:How to flash an LED: writing ARM assembly for an STM32 mi... by yjftsjthsd-h on Friday April 03, 2020 @09:51PM (#22775555)
There is a blurry line on the edges of "library" and "OS"; most people would put this particular example on the "library" side.