Click here to Skip to main content
15,887,746 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Wordle 759 - 5 4 me Pin
pkfox17-Jul-23 20:49
professionalpkfox17-Jul-23 20:49 
GeneralRe: Wordle 759 Pin
Sander Rossel17-Jul-23 20:52
professionalSander Rossel17-Jul-23 20:52 
GeneralRe: Wordle 759 Pin
Amarnath S17-Jul-23 21:01
professionalAmarnath S17-Jul-23 21:01 
GeneralRe: Wordle 759 Pin
StarNamer@work17-Jul-23 22:35
professionalStarNamer@work17-Jul-23 22:35 
GeneralRe: Wordle 759 (5/6) Pin
musefan17-Jul-23 23:02
musefan17-Jul-23 23:02 
GeneralRe: Wordle 759 Just in time! Pin
Cp-Coder18-Jul-23 0:16
Cp-Coder18-Jul-23 0:16 
GeneralRe: Wordle 759 3/6 Pin
jmaida18-Jul-23 9:37
jmaida18-Jul-23 9:37 
GeneralARRGGHHH!! register heck! Pin
honey the codewitch17-Jul-23 17:25
mvahoney the codewitch17-Jul-23 17:25 
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<<index;
    uint32_t odr = READ_REG(gpio_ports[(size_t)port].reg_base->ODR);
    return !!(odr & shl);
}
void cmsis::gpio_pin_t::output_type(pin_output_type_t value) {
    const unsigned shl = 1<<index;
    MODIFY_REG(gpio_ports[(size_t)port].reg_base->OTYPER, shl, (shl * uint32_t(value)));
}
pin_output_type_t cmsis::gpio_pin_t::output_type() const {
    const int shl = 1<<index;
    return (pin_output_type_t)(READ_BIT(gpio_ports[(size_t)port].reg_base->OTYPER, shl) >> POSITION_VAL(shl));
}
void cmsis::gpio_pin_t::speed(pin_speed value) {
    const unsigned shl = 1<<index;
    MODIFY_REG(gpio_ports[(size_t)port].reg_base->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<<index;
    return (pin_speed_t)(READ_BIT(gpio_ports[(size_t)port].reg_base->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. Unsure | :~

Here goes everything.
Check out my IoT graphics library here:
https://honeythecodewitch.com/gfx

GeneralRe: ARRGGHHH!! register heck! Pin
pkfox17-Jul-23 20:52
professionalpkfox17-Jul-23 20:52 
GeneralRe: ARRGGHHH!! register heck! Pin
honey the codewitch18-Jul-23 1:06
mvahoney the codewitch18-Jul-23 1:06 
GeneralRe: ARRGGHHH!! register heck! Pin
Kenneth Haugland17-Jul-23 21:22
mvaKenneth Haugland17-Jul-23 21:22 
GeneralMessage Closed Pin
17-Jul-23 18:12
zcswyx317-Jul-23 18:12 
GeneralRe: wow gold Pin
OriginalGriff17-Jul-23 18:14
mveOriginalGriff17-Jul-23 18:14 
GeneralRe: wow gold Pin
Kenneth Haugland17-Jul-23 21:44
mvaKenneth Haugland17-Jul-23 21:44 
GeneralRe: wow gold Pin
Dave Kreskowiak18-Jul-23 3:53
mveDave Kreskowiak18-Jul-23 3:53 
GeneralRe: wow gold Pin
jmaida17-Jul-23 18:54
jmaida17-Jul-23 18:54 
GeneralRe: wow gold Pin
dandy7218-Jul-23 4:19
dandy7218-Jul-23 4:19 
GeneralCode comments - how old is your code? Pin
charlieg17-Jul-23 10:51
charlieg17-Jul-23 10:51 
GeneralRe: Code comments - how old is your code? PinPopular
Mike Hankey17-Jul-23 11:25
mveMike Hankey17-Jul-23 11:25 
GeneralRe: Code comments - how old is your code? Pin
jmaida17-Jul-23 18:58
jmaida17-Jul-23 18:58 
GeneralRe: Code comments - how old is your code? Pin
maze318-Jul-23 4:21
professionalmaze318-Jul-23 4:21 
GeneralRe: Code comments - how old is your code? PinPopular
Dave Kreskowiak17-Jul-23 11:30
mveDave Kreskowiak17-Jul-23 11:30 
GeneralRe: Code comments - how old is your code? Pin
DerekT-P17-Jul-23 23:35
professionalDerekT-P17-Jul-23 23:35 
GeneralRe: Code comments - how old is your code? Pin
PIEBALDconsult17-Jul-23 11:47
mvePIEBALDconsult17-Jul-23 11:47 
GeneralRe: Code comments - how old is your code? Pin
Slacker00717-Jul-23 12:23
professionalSlacker00717-Jul-23 12:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.