Ick. If you *really* need to "hang around" until the result is available (instead of checking it, again, "some time later"), AT LEAST put a limit on how many iterations you'll spin. You *know* when it is specified to be complete; if it isn't, something DETECTABLE is broken (and your code should report it instead of just "lock up")
Yes, if it lock up, will put in timeout in the real code. But if the chip does not stop after the specified cycles, there is serious hardware problem of the chip anyway.
Just to be consistent and a bit faster. Default STM codes read 4 bytes and write 4 bytes to change a bit. I re-coded most registers to do bytes. I can do port I/O, usart and adc. Just haven't figure out mux channels yet.
Of course! But, the *user* just sees "it died"; he has no way of knowing (nor does he care) that it locked up spinning (vs. locked up due to a failure of Vcc at the chip).
The point is, you (can) know something that you can use to inform the user of a problem. Or, prevent some OTHER aspect of the code from chugging along on the assumption that "all is well".
["Can't Happen" should effectively PANIC so everything goes "safe"]
My changes are mostly stylistic and you my prefer your style. But do not make the struct packed. I am not sure if having volatile on each member is necessery, but it looks clearer and works.
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.