ARRGGHHH!! register heck!
-
I wanted to turn on an LED on a STM32 devkit. To do so I needed to turn some GPIO off and on. It turns out, this isn't so straightforward. I did not want to tie myself to a particular framework, so I decided to target the CMSIS headers which are available everywhere (I think?), even surprisingly under Arduino. That means going to the hardware registers directly though. Between being sidetracked by paying work and doing the research and code for this I've been at this all day. I've got a class that almost lets me set the various properties of a GPIO pin and turn it off and on.
bool cmsis::gpio_pin_t::output() const {
const int shl = 1<ODR);
return !!(odr & shl);
}
void cmsis::gpio_pin_t::output_type(pin_output_type_t value) {
const unsigned shl = 1<OTYPER, shl, (shl * uint32_t(value)));
}
pin_output_type_t cmsis::gpio_pin_t::output_type() const {
const int shl = 1<OTYPER, shl) >> POSITION_VAL(shl));
}
void cmsis::gpio_pin_t::speed(pin_speed value) {
const unsigned shl = 1<OSPEEDR, (GPIO_OSPEEDER_OSPEEDR0 << (POSITION_VAL(shl) * 2U)),
(uint32_t(value) << (POSITION_VAL(shl) * 2U)));
}
pin_speed_t cmsis::gpio_pin_t::speed() const {
const int shl = 1<OSPEEDR,
(GPIO_OSPEEDER_OSPEEDR0 << (POSITION_VAL(shl) * 2U))) >> (POSITION_VAL(shl) * 2U));
}
gpio_port_t cmsis::gpio_ports[] = {
{(GPIO_TypeDef *)GPIOA_BASE},
{(GPIO_TypeDef *)GPIOB_BASE}
#if defined GPIOC_BASE
,{(GPIO_TypeDef *)GPIOC_BASE}
#endif
#if defined GPIOD_BASE
,{(GPIO_TypeDef *)GPIOD_BASE}In arduino it's just stuff like
pinMode(pin,OUTPUT);
digitalWrite(pin,HIGH);There's a whole mess of behind the scenes there. And I ran face first into it. I'm several hundred lines of C++ in and I've got it almost working. Just need to enable the clock for the pin group even though I'm not entirely sure what that is, just how to do it. :~ Here goes everything.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx
-
I wanted to turn on an LED on a STM32 devkit. To do so I needed to turn some GPIO off and on. It turns out, this isn't so straightforward. I did not want to tie myself to a particular framework, so I decided to target the CMSIS headers which are available everywhere (I think?), even surprisingly under Arduino. That means going to the hardware registers directly though. Between being sidetracked by paying work and doing the research and code for this I've been at this all day. I've got a class that almost lets me set the various properties of a GPIO pin and turn it off and on.
bool cmsis::gpio_pin_t::output() const {
const int shl = 1<ODR);
return !!(odr & shl);
}
void cmsis::gpio_pin_t::output_type(pin_output_type_t value) {
const unsigned shl = 1<OTYPER, shl, (shl * uint32_t(value)));
}
pin_output_type_t cmsis::gpio_pin_t::output_type() const {
const int shl = 1<OTYPER, shl) >> POSITION_VAL(shl));
}
void cmsis::gpio_pin_t::speed(pin_speed value) {
const unsigned shl = 1<OSPEEDR, (GPIO_OSPEEDER_OSPEEDR0 << (POSITION_VAL(shl) * 2U)),
(uint32_t(value) << (POSITION_VAL(shl) * 2U)));
}
pin_speed_t cmsis::gpio_pin_t::speed() const {
const int shl = 1<OSPEEDR,
(GPIO_OSPEEDER_OSPEEDR0 << (POSITION_VAL(shl) * 2U))) >> (POSITION_VAL(shl) * 2U));
}
gpio_port_t cmsis::gpio_ports[] = {
{(GPIO_TypeDef *)GPIOA_BASE},
{(GPIO_TypeDef *)GPIOB_BASE}
#if defined GPIOC_BASE
,{(GPIO_TypeDef *)GPIOC_BASE}
#endif
#if defined GPIOD_BASE
,{(GPIO_TypeDef *)GPIOD_BASE}In arduino it's just stuff like
pinMode(pin,OUTPUT);
digitalWrite(pin,HIGH);There's a whole mess of behind the scenes there. And I ran face first into it. I'm several hundred lines of C++ in and I've got it almost working. Just need to enable the clock for the pin group even though I'm not entirely sure what that is, just how to do it. :~ Here goes everything.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx
-
I wanted to turn on an LED on a STM32 devkit. To do so I needed to turn some GPIO off and on. It turns out, this isn't so straightforward. I did not want to tie myself to a particular framework, so I decided to target the CMSIS headers which are available everywhere (I think?), even surprisingly under Arduino. That means going to the hardware registers directly though. Between being sidetracked by paying work and doing the research and code for this I've been at this all day. I've got a class that almost lets me set the various properties of a GPIO pin and turn it off and on.
bool cmsis::gpio_pin_t::output() const {
const int shl = 1<ODR);
return !!(odr & shl);
}
void cmsis::gpio_pin_t::output_type(pin_output_type_t value) {
const unsigned shl = 1<OTYPER, shl, (shl * uint32_t(value)));
}
pin_output_type_t cmsis::gpio_pin_t::output_type() const {
const int shl = 1<OTYPER, shl) >> POSITION_VAL(shl));
}
void cmsis::gpio_pin_t::speed(pin_speed value) {
const unsigned shl = 1<OSPEEDR, (GPIO_OSPEEDER_OSPEEDR0 << (POSITION_VAL(shl) * 2U)),
(uint32_t(value) << (POSITION_VAL(shl) * 2U)));
}
pin_speed_t cmsis::gpio_pin_t::speed() const {
const int shl = 1<OSPEEDR,
(GPIO_OSPEEDER_OSPEEDR0 << (POSITION_VAL(shl) * 2U))) >> (POSITION_VAL(shl) * 2U));
}
gpio_port_t cmsis::gpio_ports[] = {
{(GPIO_TypeDef *)GPIOA_BASE},
{(GPIO_TypeDef *)GPIOB_BASE}
#if defined GPIOC_BASE
,{(GPIO_TypeDef *)GPIOC_BASE}
#endif
#if defined GPIOD_BASE
,{(GPIO_TypeDef *)GPIOD_BASE}In arduino it's just stuff like
pinMode(pin,OUTPUT);
digitalWrite(pin,HIGH);There's a whole mess of behind the scenes there. And I ran face first into it. I'm several hundred lines of C++ in and I've got it almost working. Just need to enable the clock for the pin group even though I'm not entirely sure what that is, just how to do it. :~ Here goes everything.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx
This reminds me of the old days of programming Borland C++, where I had to read the changes on the parallell port via the register. I do not miss it... :laugh:
-
I think Mr Boring ( Mike Hankey link ) covered how to do that
In a closed society where everybody's guilty, the only crime is getting caught. In a world of thieves, the only final sin is stupidity. - Hunter S Thompson - RIP
Yeah. But I got this. *cracks knuckles*
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx