Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. ARRGGHHH!! register heck!

ARRGGHHH!! register heck!

Scheduled Pinned Locked Moved The Lounge
hardwarec++comgraphicsiot
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #1

    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

    pkfoxP K 2 Replies Last reply
    0
    • H honey the codewitch

      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

      pkfoxP Offline
      pkfoxP Offline
      pkfox
      wrote on last edited by
      #2

      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

      H 1 Reply Last reply
      0
      • H honey the codewitch

        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

        K Offline
        K Offline
        Kenneth Haugland
        wrote on last edited by
        #3

        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:

        1 Reply Last reply
        0
        • pkfoxP pkfox

          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

          H Offline
          H Offline
          honey the codewitch
          wrote on last edited by
          #4

          Yeah. But I got this. *cracks knuckles*

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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups