Live data from Hacker News

How to flash an LED: writing ARM assembly for an STM32 microcontroller

mcla.ug

21–30 of 68 posts

Re: How to flash an LED: writing ARM assembly for an STM32 microcontroller

#21
post #18

Earlier quoted context omitted.

if you have an OS, yes

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.

Isn't that what an OS would do, essentially?

Re: How to flash an LED: writing ARM assembly for an STM32 microcontroller

#22
post #18

Earlier quoted context omitted.

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.

Isn't that what an OS would do, essentially?

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 microcontroller

#23

Is there a better way to sleep/delay other than what basically seems like 100% CPU usage in a subtraction loop?

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 microcontroller

#24
post #18

Earlier quoted context omitted.

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.

Isn't that what an OS would do, essentially?

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 microcontroller

#25
post #23

Is there a better way to sleep/delay other than what basically seems like 100% CPU usage in a subtraction loop?

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.

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 microcontroller

#26
post #8
post #4

Earlier quoted context omitted.

I don't have experience with this, but from talking to people who do, there are indeed open source implementations. They say the documentation is a bit confusing, but it does describe everything. This Rust library is an abstract USB library that can implement CDC serial https://docs.rs/usb-device/0.2.5/usb_device/ , and this library connects it to the STM32 USB peripheral https://github.com/stm32-rs/stm32-usbd Exampl…

those open source libs use undocumented regs documented and thus are based on STM lib. License in question thus

That's what "clean room reverse engineering" is for. If you document what the code does, then code written based only on those docs wouldn't need to be under the same license.

Re: How to flash an LED: writing ARM assembly for an STM32 microcontroller

#27
post #8
post #4

Earlier quoted context omitted.

I don't have experience with this, but from talking to people who do, there are indeed open source implementations. They say the documentation is a bit confusing, but it does describe everything. This Rust library is an abstract USB library that can implement CDC serial https://docs.rs/usb-device/0.2.5/usb_device/ , and this library connects it to the STM32 USB peripheral https://github.com/stm32-rs/stm32-usbd Exampl…

those open source libs use undocumented regs documented and thus are based on STM lib. License in question thus

Is clean-room reverse engineering even viable? That is, would anyone agree that an independent discovery of what bit does what is even possible, and this is not lifted from known drivers?

Re: How to flash an LED: writing ARM assembly for an STM32 microcontroller

#28

Is there a better way to sleep/delay other than what basically seems like 100% CPU usage in a subtraction loop?

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 microcontroller

#29
post #22

Earlier quoted context omitted.

Isn't that what an OS would do, essentially?

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...

that is basically a mini-os :)

Re: How to flash an LED: writing ARM assembly for an STM32 microcontroller

#30
post #3
post #2

Anybody got USB communication (CDC class) working on this platform without the proprietary libs?

no, i spent months on this, and the answer is no They use IP from synopsis, but synopsis refuses to allow their docs to be published so every manufacturer has to read them and regurgitate them into their own docs in their own words . In any case official STM docs are incomplete. See their driver source - it accesses undocumented registers and sets undocumented bits in documented regs. Without them the usb core will n…

Maybe I don't understand the question. Aren't the STM32 CDC libraries redistributable?
Post reply on HN