STM32 cannot reach individual registers and pins as PICBits are high on disabled pins(STM32)STM32F4 Cube HAL UART. Is it a bug or am I missing something?STM32 timing critical ADC outline codeHow to use timers in STM32 board and HAL library in order to measure speed of motor?Confusion on ARM-Tiva PORTS and RegistersSTM32F303 STM32CubeMX __HAL_TIM_SetCompare macro does not existGPIO Output Registers on the STM32Strange STM32L476RG GPIO behaviour when leaving STOP mode 2. Is it a silicon bug?

Can a network vulnerability be exploited locally?

Number of Fingers for a Math Oriented Race

In Endgame, wouldn't Stark have remembered Hulk busting out of the stairwell?

Why is there not a willingness from the world to step in between Pakistan and India?

Why is there no Disney logo in MCU movies?

Employing a contractor proving difficult

Pen test results for web application include a file from a forbidden directory that is not even used or referenced

Find feasible point in polynomial time in linear programming

How to deal with anxiety caused by dangerous riding conditions stemming from poor lane design and inconsiderate fellow road users?

What ways are there to "PEEK" memory sections in (different) BASIC(s)

STM32 cannot reach individual registers and pins as PIC

Did anybody find out it was Anakin who blew up the command center?

Stolen MacBook should I worry about my data?

Why can't you say don't instead of won't?

Normalized Malbolge to Malbolge translator

How do you say "half the time …, the other half …" in German?

Why does Sauron not permit his followers to use his name?

Why is the Grievance Studies affair considered to be research requiring IRB approval?

Why is 3/4 a simple meter while 6/8 is a compound meter?

Why does AM radio react to IR remote?

What is Soda Fountain Etiquette?

Cutting numbers into a specific decimals

Is the internet in Madagascar faster than in UK?

Is allowing Barbarian features to work with Dex-based attacks imbalancing?



STM32 cannot reach individual registers and pins as PIC


Bits are high on disabled pins(STM32)STM32F4 Cube HAL UART. Is it a bug or am I missing something?STM32 timing critical ADC outline codeHow to use timers in STM32 board and HAL library in order to measure speed of motor?Confusion on ARM-Tiva PORTS and RegistersSTM32F303 STM32CubeMX __HAL_TIM_SetCompare macro does not existGPIO Output Registers on the STM32Strange STM32L476RG GPIO behaviour when leaving STOP mode 2. Is it a silicon bug?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1












$begingroup$


I used to work with PIC and now I need to use STM32 chip. I was using HAL library but it gave me some problems so now I want to use it without HAL_Library. There are some questions I could not get any answer.



  1. In the datasheet of any PIC there are registers and each bit of those registers are showed and explained. But in the datasheet of STM32 chips I could not find any registers. How can I find all registers in STM32 chips and specific bits of these register. For example I need to set PE bit in I2Cx_CR1 register but I have no idea which bit is the PE bit...


  2. This one might be simple but I couldn't figure it out. Maybe it is not possible in STM32 I'm not sure. Let's say I want to set PA2. Do I need to GPIOA->ODR = 0b00000010;I am not sure how can I make it bitwise, something like this: GPIOA -> |= PA2 (?) What should I put instead of PA2 in this case?


  3. Is it possible to use CubeMX and then do the rest in classical way like I mentioned before using individual registers without using HAL? Or if I create the project by using Cube then I have to use HAL library?










share|improve this question











$endgroup$













  • $begingroup$
    Every MCU manufacturer provides 2 main documents. The datasheet which is for the hardware designer, and the user manual which is for the software designer.
    $endgroup$
    – Lundin
    8 hours ago

















1












$begingroup$


I used to work with PIC and now I need to use STM32 chip. I was using HAL library but it gave me some problems so now I want to use it without HAL_Library. There are some questions I could not get any answer.



  1. In the datasheet of any PIC there are registers and each bit of those registers are showed and explained. But in the datasheet of STM32 chips I could not find any registers. How can I find all registers in STM32 chips and specific bits of these register. For example I need to set PE bit in I2Cx_CR1 register but I have no idea which bit is the PE bit...


  2. This one might be simple but I couldn't figure it out. Maybe it is not possible in STM32 I'm not sure. Let's say I want to set PA2. Do I need to GPIOA->ODR = 0b00000010;I am not sure how can I make it bitwise, something like this: GPIOA -> |= PA2 (?) What should I put instead of PA2 in this case?


  3. Is it possible to use CubeMX and then do the rest in classical way like I mentioned before using individual registers without using HAL? Or if I create the project by using Cube then I have to use HAL library?










share|improve this question











$endgroup$













  • $begingroup$
    Every MCU manufacturer provides 2 main documents. The datasheet which is for the hardware designer, and the user manual which is for the software designer.
    $endgroup$
    – Lundin
    8 hours ago













1












1








1


1



$begingroup$


I used to work with PIC and now I need to use STM32 chip. I was using HAL library but it gave me some problems so now I want to use it without HAL_Library. There are some questions I could not get any answer.



  1. In the datasheet of any PIC there are registers and each bit of those registers are showed and explained. But in the datasheet of STM32 chips I could not find any registers. How can I find all registers in STM32 chips and specific bits of these register. For example I need to set PE bit in I2Cx_CR1 register but I have no idea which bit is the PE bit...


  2. This one might be simple but I couldn't figure it out. Maybe it is not possible in STM32 I'm not sure. Let's say I want to set PA2. Do I need to GPIOA->ODR = 0b00000010;I am not sure how can I make it bitwise, something like this: GPIOA -> |= PA2 (?) What should I put instead of PA2 in this case?


  3. Is it possible to use CubeMX and then do the rest in classical way like I mentioned before using individual registers without using HAL? Or if I create the project by using Cube then I have to use HAL library?










share|improve this question











$endgroup$




I used to work with PIC and now I need to use STM32 chip. I was using HAL library but it gave me some problems so now I want to use it without HAL_Library. There are some questions I could not get any answer.



  1. In the datasheet of any PIC there are registers and each bit of those registers are showed and explained. But in the datasheet of STM32 chips I could not find any registers. How can I find all registers in STM32 chips and specific bits of these register. For example I need to set PE bit in I2Cx_CR1 register but I have no idea which bit is the PE bit...


  2. This one might be simple but I couldn't figure it out. Maybe it is not possible in STM32 I'm not sure. Let's say I want to set PA2. Do I need to GPIOA->ODR = 0b00000010;I am not sure how can I make it bitwise, something like this: GPIOA -> |= PA2 (?) What should I put instead of PA2 in this case?


  3. Is it possible to use CubeMX and then do the rest in classical way like I mentioned before using individual registers without using HAL? Or if I create the project by using Cube then I have to use HAL library?







stm32 arm datasheet






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 hours ago









Michel Keijzers

8,28610 gold badges35 silver badges80 bronze badges




8,28610 gold badges35 silver badges80 bronze badges










asked 8 hours ago









Günkut AğabeyoğluGünkut Ağabeyoğlu

23013 bronze badges




23013 bronze badges














  • $begingroup$
    Every MCU manufacturer provides 2 main documents. The datasheet which is for the hardware designer, and the user manual which is for the software designer.
    $endgroup$
    – Lundin
    8 hours ago
















  • $begingroup$
    Every MCU manufacturer provides 2 main documents. The datasheet which is for the hardware designer, and the user manual which is for the software designer.
    $endgroup$
    – Lundin
    8 hours ago















$begingroup$
Every MCU manufacturer provides 2 main documents. The datasheet which is for the hardware designer, and the user manual which is for the software designer.
$endgroup$
– Lundin
8 hours ago




$begingroup$
Every MCU manufacturer provides 2 main documents. The datasheet which is for the hardware designer, and the user manual which is for the software designer.
$endgroup$
– Lundin
8 hours ago










5 Answers
5






active

oldest

votes


















6













$begingroup$

You are looking at the datasheet. It is not there. It is in the reference manual. For STM32, datasheet is mostly for package specific things like pinouts and electrical specifications (that's the only time I ever look at it anyways). User reference manual is for device common things like registers and peripherals which is almost everything else.






share|improve this answer











$endgroup$






















    2













    $begingroup$

    I also moved from PIC to STM, some things changed and you need to read datasheets to understand.



    1. The "datasheet" of the STM only contains some information one peripherals, electrical values... Take a look ate the "Reference Manual" for the registers.



    2. To set a GPIO, it is not that simple:



      • You need to enable the GPIO bank in RCC registers

      • Set the GPIO direction (MODER register)

      • Set the output value (ODR register, each bit is a pin, PA2 will be GPIOA->ODR |= (1 << 2);


    Some registers help the set/reset of the GPIO (BSRR register).



    1. Use Stm32IDE, you can configure the project without HAL. It will includes CMSIS, some useful headers with all registers already defined.





    share|improve this answer











    $endgroup$






















      2













      $begingroup$


      In the datasheet of any PIC there are registers and each bit of those registers are showed and explained. But in the datasheet of STM32 chips I could not find any registers. How can I find all registers in STM32 chips and specific bits of these register.




      The Datasheet contains the external description of the MCU, i.e. pin mappings, electrical characteristics, package dimensions.



      The register descriptions are in the reference manual, that's where the function of each bit in each peripheral register is explained.



      Then there is a programming manual where the ARM core is described, including the core peripheral registers like the interrupt controller or the SysTick timer.




      For example I need to set PE bit in I2Cx_CR1 register but I have no idea which bit is the PE bit...




      Each usable register bit has a definition in the CMSIS header for your controller. They have predictable names, e.g. to set the PE bit of the CR1 register on the first I2C controller, you can write



      I2C1->CR1 |= I2C_CR1_PE;



      Let's say I want to set PA2. Do I need to GPIOA->ODR = 0b00000010; I am not sure how can I make it bitwise, something like this: GPIOA -> |= PA2 (?) What should I put instead of PA2 in this case?




      GPIO data register bits have their definitions in the CMSIS header too, using the same convention as above, so it's possible to write



      GPIOA->ODR |= GPIO_ODR_OD2; // set PA2 to 1


      You can of course assume that the layout of the bits are the same across the IDR, ODR and BSRR registers, and use the simplified GPIO_PIN_2 definition from the HAL headers.



      You can use the GPIOx->BSRR register to set and reset some pins without bitwise instructions, e.g. to set PA2, reset PA4, and let the rest of the pins alone, do



      GPIOA->BSRR = GPIO_PIN_2 | (GPIO_PIN_4 << 16);


      it comes handy when some pins of a GPIO port are controlled by interrupt handlers, and others by the main code.




      Is it possible to use CubeMX and then do the rest in classical way like I mentioned before using individual registers without using HAL? Or if I create the project by using Cube then I have to use HAL library?




      Sure, I mix these approaches all the time. Just mind that whenever you re-generate the code from CubeMX, everything outside the USER CODE BEGIN / USER CODE END blocks will be overwritten. Once you got the HAL part right, the code is all yours.



      The HAL driver for each peripheral is self-contained, you can even use HAL functions for one peripheral, LL for another, StdPeriph for the third, and direct register access for the fourth, or initialize one peripheral with HAL and access it through registers afterwards. (I had an actual project where some peripherals were initialized by HAL, legacy code taken from older code used StdPeriph, and new code accessed the registers directly)






      share|improve this answer











      $endgroup$






















        1













        $begingroup$


        1. You should not load (only) the datasheet, but also the reference manual, which can be found for e.g. STM32F103C8T6 on the page with resources, see page https://www.st.com/en/microcontrollers-microprocessors/stm32f103c8.html#resource.



          In the Reference Manual, RM008, you find it on page 774. If you have another STM, find the right Reference manual.



        2. You can indeed use | (or), I'm not sure what is defined for PE (you can try if you have the I2C instance open in your editor, to find the definition, and you will probably find the values possible for the register).


        3. You can only use instead of HAL (or combined, not sure), the so called LL (Low Level) drivers, which give you a more lower level interface to the drivers/peripherals. I don't have experience with it myself.






        share|improve this answer









        $endgroup$






















          0













          $begingroup$

          What you are looking is the CMSIS (Cortex-M Software Interface Standard) libraries for your processor. These should be available from ST, and they make it possible to access and modify registers exactly as you describe. Meaningful constants should be defined for bit-banging all of the registers.






          share|improve this answer









          $endgroup$














          • $begingroup$
            To be precise, ST provide functions on top of CMSIS. CMSIS was designed so that the common parts of a Cortex-M system could be reused across multiple silicon vendors. Vendors then bolt their differentiating hardware in using the CMSIS API. The aim is one can access the C-M's registers in the same way using ST, TI, etc microcontrollers, as well as other things that would be useful independent of the vendor.
            $endgroup$
            – awjlogan
            7 hours ago













          Your Answer






          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("schematics", function ()
          StackExchange.schematics.init();
          );
          , "cicuitlab");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "135"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f455051%2fstm32-cannot-reach-individual-registers-and-pins-as-pic%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          6













          $begingroup$

          You are looking at the datasheet. It is not there. It is in the reference manual. For STM32, datasheet is mostly for package specific things like pinouts and electrical specifications (that's the only time I ever look at it anyways). User reference manual is for device common things like registers and peripherals which is almost everything else.






          share|improve this answer











          $endgroup$



















            6













            $begingroup$

            You are looking at the datasheet. It is not there. It is in the reference manual. For STM32, datasheet is mostly for package specific things like pinouts and electrical specifications (that's the only time I ever look at it anyways). User reference manual is for device common things like registers and peripherals which is almost everything else.






            share|improve this answer











            $endgroup$

















              6














              6










              6







              $begingroup$

              You are looking at the datasheet. It is not there. It is in the reference manual. For STM32, datasheet is mostly for package specific things like pinouts and electrical specifications (that's the only time I ever look at it anyways). User reference manual is for device common things like registers and peripherals which is almost everything else.






              share|improve this answer











              $endgroup$



              You are looking at the datasheet. It is not there. It is in the reference manual. For STM32, datasheet is mostly for package specific things like pinouts and electrical specifications (that's the only time I ever look at it anyways). User reference manual is for device common things like registers and peripherals which is almost everything else.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 7 hours ago

























              answered 8 hours ago









              DKNguyenDKNguyen

              6,2681 gold badge7 silver badges26 bronze badges




              6,2681 gold badge7 silver badges26 bronze badges


























                  2













                  $begingroup$

                  I also moved from PIC to STM, some things changed and you need to read datasheets to understand.



                  1. The "datasheet" of the STM only contains some information one peripherals, electrical values... Take a look ate the "Reference Manual" for the registers.



                  2. To set a GPIO, it is not that simple:



                    • You need to enable the GPIO bank in RCC registers

                    • Set the GPIO direction (MODER register)

                    • Set the output value (ODR register, each bit is a pin, PA2 will be GPIOA->ODR |= (1 << 2);


                  Some registers help the set/reset of the GPIO (BSRR register).



                  1. Use Stm32IDE, you can configure the project without HAL. It will includes CMSIS, some useful headers with all registers already defined.





                  share|improve this answer











                  $endgroup$



















                    2













                    $begingroup$

                    I also moved from PIC to STM, some things changed and you need to read datasheets to understand.



                    1. The "datasheet" of the STM only contains some information one peripherals, electrical values... Take a look ate the "Reference Manual" for the registers.



                    2. To set a GPIO, it is not that simple:



                      • You need to enable the GPIO bank in RCC registers

                      • Set the GPIO direction (MODER register)

                      • Set the output value (ODR register, each bit is a pin, PA2 will be GPIOA->ODR |= (1 << 2);


                    Some registers help the set/reset of the GPIO (BSRR register).



                    1. Use Stm32IDE, you can configure the project without HAL. It will includes CMSIS, some useful headers with all registers already defined.





                    share|improve this answer











                    $endgroup$

















                      2














                      2










                      2







                      $begingroup$

                      I also moved from PIC to STM, some things changed and you need to read datasheets to understand.



                      1. The "datasheet" of the STM only contains some information one peripherals, electrical values... Take a look ate the "Reference Manual" for the registers.



                      2. To set a GPIO, it is not that simple:



                        • You need to enable the GPIO bank in RCC registers

                        • Set the GPIO direction (MODER register)

                        • Set the output value (ODR register, each bit is a pin, PA2 will be GPIOA->ODR |= (1 << 2);


                      Some registers help the set/reset of the GPIO (BSRR register).



                      1. Use Stm32IDE, you can configure the project without HAL. It will includes CMSIS, some useful headers with all registers already defined.





                      share|improve this answer











                      $endgroup$



                      I also moved from PIC to STM, some things changed and you need to read datasheets to understand.



                      1. The "datasheet" of the STM only contains some information one peripherals, electrical values... Take a look ate the "Reference Manual" for the registers.



                      2. To set a GPIO, it is not that simple:



                        • You need to enable the GPIO bank in RCC registers

                        • Set the GPIO direction (MODER register)

                        • Set the output value (ODR register, each bit is a pin, PA2 will be GPIOA->ODR |= (1 << 2);


                      Some registers help the set/reset of the GPIO (BSRR register).



                      1. Use Stm32IDE, you can configure the project without HAL. It will includes CMSIS, some useful headers with all registers already defined.






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 7 hours ago

























                      answered 8 hours ago









                      PierreOlivierPierreOlivier

                      2452 silver badges9 bronze badges




                      2452 silver badges9 bronze badges
























                          2













                          $begingroup$


                          In the datasheet of any PIC there are registers and each bit of those registers are showed and explained. But in the datasheet of STM32 chips I could not find any registers. How can I find all registers in STM32 chips and specific bits of these register.




                          The Datasheet contains the external description of the MCU, i.e. pin mappings, electrical characteristics, package dimensions.



                          The register descriptions are in the reference manual, that's where the function of each bit in each peripheral register is explained.



                          Then there is a programming manual where the ARM core is described, including the core peripheral registers like the interrupt controller or the SysTick timer.




                          For example I need to set PE bit in I2Cx_CR1 register but I have no idea which bit is the PE bit...




                          Each usable register bit has a definition in the CMSIS header for your controller. They have predictable names, e.g. to set the PE bit of the CR1 register on the first I2C controller, you can write



                          I2C1->CR1 |= I2C_CR1_PE;



                          Let's say I want to set PA2. Do I need to GPIOA->ODR = 0b00000010; I am not sure how can I make it bitwise, something like this: GPIOA -> |= PA2 (?) What should I put instead of PA2 in this case?




                          GPIO data register bits have their definitions in the CMSIS header too, using the same convention as above, so it's possible to write



                          GPIOA->ODR |= GPIO_ODR_OD2; // set PA2 to 1


                          You can of course assume that the layout of the bits are the same across the IDR, ODR and BSRR registers, and use the simplified GPIO_PIN_2 definition from the HAL headers.



                          You can use the GPIOx->BSRR register to set and reset some pins without bitwise instructions, e.g. to set PA2, reset PA4, and let the rest of the pins alone, do



                          GPIOA->BSRR = GPIO_PIN_2 | (GPIO_PIN_4 << 16);


                          it comes handy when some pins of a GPIO port are controlled by interrupt handlers, and others by the main code.




                          Is it possible to use CubeMX and then do the rest in classical way like I mentioned before using individual registers without using HAL? Or if I create the project by using Cube then I have to use HAL library?




                          Sure, I mix these approaches all the time. Just mind that whenever you re-generate the code from CubeMX, everything outside the USER CODE BEGIN / USER CODE END blocks will be overwritten. Once you got the HAL part right, the code is all yours.



                          The HAL driver for each peripheral is self-contained, you can even use HAL functions for one peripheral, LL for another, StdPeriph for the third, and direct register access for the fourth, or initialize one peripheral with HAL and access it through registers afterwards. (I had an actual project where some peripherals were initialized by HAL, legacy code taken from older code used StdPeriph, and new code accessed the registers directly)






                          share|improve this answer











                          $endgroup$



















                            2













                            $begingroup$


                            In the datasheet of any PIC there are registers and each bit of those registers are showed and explained. But in the datasheet of STM32 chips I could not find any registers. How can I find all registers in STM32 chips and specific bits of these register.




                            The Datasheet contains the external description of the MCU, i.e. pin mappings, electrical characteristics, package dimensions.



                            The register descriptions are in the reference manual, that's where the function of each bit in each peripheral register is explained.



                            Then there is a programming manual where the ARM core is described, including the core peripheral registers like the interrupt controller or the SysTick timer.




                            For example I need to set PE bit in I2Cx_CR1 register but I have no idea which bit is the PE bit...




                            Each usable register bit has a definition in the CMSIS header for your controller. They have predictable names, e.g. to set the PE bit of the CR1 register on the first I2C controller, you can write



                            I2C1->CR1 |= I2C_CR1_PE;



                            Let's say I want to set PA2. Do I need to GPIOA->ODR = 0b00000010; I am not sure how can I make it bitwise, something like this: GPIOA -> |= PA2 (?) What should I put instead of PA2 in this case?




                            GPIO data register bits have their definitions in the CMSIS header too, using the same convention as above, so it's possible to write



                            GPIOA->ODR |= GPIO_ODR_OD2; // set PA2 to 1


                            You can of course assume that the layout of the bits are the same across the IDR, ODR and BSRR registers, and use the simplified GPIO_PIN_2 definition from the HAL headers.



                            You can use the GPIOx->BSRR register to set and reset some pins without bitwise instructions, e.g. to set PA2, reset PA4, and let the rest of the pins alone, do



                            GPIOA->BSRR = GPIO_PIN_2 | (GPIO_PIN_4 << 16);


                            it comes handy when some pins of a GPIO port are controlled by interrupt handlers, and others by the main code.




                            Is it possible to use CubeMX and then do the rest in classical way like I mentioned before using individual registers without using HAL? Or if I create the project by using Cube then I have to use HAL library?




                            Sure, I mix these approaches all the time. Just mind that whenever you re-generate the code from CubeMX, everything outside the USER CODE BEGIN / USER CODE END blocks will be overwritten. Once you got the HAL part right, the code is all yours.



                            The HAL driver for each peripheral is self-contained, you can even use HAL functions for one peripheral, LL for another, StdPeriph for the third, and direct register access for the fourth, or initialize one peripheral with HAL and access it through registers afterwards. (I had an actual project where some peripherals were initialized by HAL, legacy code taken from older code used StdPeriph, and new code accessed the registers directly)






                            share|improve this answer











                            $endgroup$

















                              2














                              2










                              2







                              $begingroup$


                              In the datasheet of any PIC there are registers and each bit of those registers are showed and explained. But in the datasheet of STM32 chips I could not find any registers. How can I find all registers in STM32 chips and specific bits of these register.




                              The Datasheet contains the external description of the MCU, i.e. pin mappings, electrical characteristics, package dimensions.



                              The register descriptions are in the reference manual, that's where the function of each bit in each peripheral register is explained.



                              Then there is a programming manual where the ARM core is described, including the core peripheral registers like the interrupt controller or the SysTick timer.




                              For example I need to set PE bit in I2Cx_CR1 register but I have no idea which bit is the PE bit...




                              Each usable register bit has a definition in the CMSIS header for your controller. They have predictable names, e.g. to set the PE bit of the CR1 register on the first I2C controller, you can write



                              I2C1->CR1 |= I2C_CR1_PE;



                              Let's say I want to set PA2. Do I need to GPIOA->ODR = 0b00000010; I am not sure how can I make it bitwise, something like this: GPIOA -> |= PA2 (?) What should I put instead of PA2 in this case?




                              GPIO data register bits have their definitions in the CMSIS header too, using the same convention as above, so it's possible to write



                              GPIOA->ODR |= GPIO_ODR_OD2; // set PA2 to 1


                              You can of course assume that the layout of the bits are the same across the IDR, ODR and BSRR registers, and use the simplified GPIO_PIN_2 definition from the HAL headers.



                              You can use the GPIOx->BSRR register to set and reset some pins without bitwise instructions, e.g. to set PA2, reset PA4, and let the rest of the pins alone, do



                              GPIOA->BSRR = GPIO_PIN_2 | (GPIO_PIN_4 << 16);


                              it comes handy when some pins of a GPIO port are controlled by interrupt handlers, and others by the main code.




                              Is it possible to use CubeMX and then do the rest in classical way like I mentioned before using individual registers without using HAL? Or if I create the project by using Cube then I have to use HAL library?




                              Sure, I mix these approaches all the time. Just mind that whenever you re-generate the code from CubeMX, everything outside the USER CODE BEGIN / USER CODE END blocks will be overwritten. Once you got the HAL part right, the code is all yours.



                              The HAL driver for each peripheral is self-contained, you can even use HAL functions for one peripheral, LL for another, StdPeriph for the third, and direct register access for the fourth, or initialize one peripheral with HAL and access it through registers afterwards. (I had an actual project where some peripherals were initialized by HAL, legacy code taken from older code used StdPeriph, and new code accessed the registers directly)






                              share|improve this answer











                              $endgroup$




                              In the datasheet of any PIC there are registers and each bit of those registers are showed and explained. But in the datasheet of STM32 chips I could not find any registers. How can I find all registers in STM32 chips and specific bits of these register.




                              The Datasheet contains the external description of the MCU, i.e. pin mappings, electrical characteristics, package dimensions.



                              The register descriptions are in the reference manual, that's where the function of each bit in each peripheral register is explained.



                              Then there is a programming manual where the ARM core is described, including the core peripheral registers like the interrupt controller or the SysTick timer.




                              For example I need to set PE bit in I2Cx_CR1 register but I have no idea which bit is the PE bit...




                              Each usable register bit has a definition in the CMSIS header for your controller. They have predictable names, e.g. to set the PE bit of the CR1 register on the first I2C controller, you can write



                              I2C1->CR1 |= I2C_CR1_PE;



                              Let's say I want to set PA2. Do I need to GPIOA->ODR = 0b00000010; I am not sure how can I make it bitwise, something like this: GPIOA -> |= PA2 (?) What should I put instead of PA2 in this case?




                              GPIO data register bits have their definitions in the CMSIS header too, using the same convention as above, so it's possible to write



                              GPIOA->ODR |= GPIO_ODR_OD2; // set PA2 to 1


                              You can of course assume that the layout of the bits are the same across the IDR, ODR and BSRR registers, and use the simplified GPIO_PIN_2 definition from the HAL headers.



                              You can use the GPIOx->BSRR register to set and reset some pins without bitwise instructions, e.g. to set PA2, reset PA4, and let the rest of the pins alone, do



                              GPIOA->BSRR = GPIO_PIN_2 | (GPIO_PIN_4 << 16);


                              it comes handy when some pins of a GPIO port are controlled by interrupt handlers, and others by the main code.




                              Is it possible to use CubeMX and then do the rest in classical way like I mentioned before using individual registers without using HAL? Or if I create the project by using Cube then I have to use HAL library?




                              Sure, I mix these approaches all the time. Just mind that whenever you re-generate the code from CubeMX, everything outside the USER CODE BEGIN / USER CODE END blocks will be overwritten. Once you got the HAL part right, the code is all yours.



                              The HAL driver for each peripheral is self-contained, you can even use HAL functions for one peripheral, LL for another, StdPeriph for the third, and direct register access for the fourth, or initialize one peripheral with HAL and access it through registers afterwards. (I had an actual project where some peripherals were initialized by HAL, legacy code taken from older code used StdPeriph, and new code accessed the registers directly)







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited 7 hours ago

























                              answered 7 hours ago









                              berendiberendi

                              4,4471 gold badge8 silver badges24 bronze badges




                              4,4471 gold badge8 silver badges24 bronze badges
























                                  1













                                  $begingroup$


                                  1. You should not load (only) the datasheet, but also the reference manual, which can be found for e.g. STM32F103C8T6 on the page with resources, see page https://www.st.com/en/microcontrollers-microprocessors/stm32f103c8.html#resource.



                                    In the Reference Manual, RM008, you find it on page 774. If you have another STM, find the right Reference manual.



                                  2. You can indeed use | (or), I'm not sure what is defined for PE (you can try if you have the I2C instance open in your editor, to find the definition, and you will probably find the values possible for the register).


                                  3. You can only use instead of HAL (or combined, not sure), the so called LL (Low Level) drivers, which give you a more lower level interface to the drivers/peripherals. I don't have experience with it myself.






                                  share|improve this answer









                                  $endgroup$



















                                    1













                                    $begingroup$


                                    1. You should not load (only) the datasheet, but also the reference manual, which can be found for e.g. STM32F103C8T6 on the page with resources, see page https://www.st.com/en/microcontrollers-microprocessors/stm32f103c8.html#resource.



                                      In the Reference Manual, RM008, you find it on page 774. If you have another STM, find the right Reference manual.



                                    2. You can indeed use | (or), I'm not sure what is defined for PE (you can try if you have the I2C instance open in your editor, to find the definition, and you will probably find the values possible for the register).


                                    3. You can only use instead of HAL (or combined, not sure), the so called LL (Low Level) drivers, which give you a more lower level interface to the drivers/peripherals. I don't have experience with it myself.






                                    share|improve this answer









                                    $endgroup$

















                                      1














                                      1










                                      1







                                      $begingroup$


                                      1. You should not load (only) the datasheet, but also the reference manual, which can be found for e.g. STM32F103C8T6 on the page with resources, see page https://www.st.com/en/microcontrollers-microprocessors/stm32f103c8.html#resource.



                                        In the Reference Manual, RM008, you find it on page 774. If you have another STM, find the right Reference manual.



                                      2. You can indeed use | (or), I'm not sure what is defined for PE (you can try if you have the I2C instance open in your editor, to find the definition, and you will probably find the values possible for the register).


                                      3. You can only use instead of HAL (or combined, not sure), the so called LL (Low Level) drivers, which give you a more lower level interface to the drivers/peripherals. I don't have experience with it myself.






                                      share|improve this answer









                                      $endgroup$




                                      1. You should not load (only) the datasheet, but also the reference manual, which can be found for e.g. STM32F103C8T6 on the page with resources, see page https://www.st.com/en/microcontrollers-microprocessors/stm32f103c8.html#resource.



                                        In the Reference Manual, RM008, you find it on page 774. If you have another STM, find the right Reference manual.



                                      2. You can indeed use | (or), I'm not sure what is defined for PE (you can try if you have the I2C instance open in your editor, to find the definition, and you will probably find the values possible for the register).


                                      3. You can only use instead of HAL (or combined, not sure), the so called LL (Low Level) drivers, which give you a more lower level interface to the drivers/peripherals. I don't have experience with it myself.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered 8 hours ago









                                      Michel KeijzersMichel Keijzers

                                      8,28610 gold badges35 silver badges80 bronze badges




                                      8,28610 gold badges35 silver badges80 bronze badges
























                                          0













                                          $begingroup$

                                          What you are looking is the CMSIS (Cortex-M Software Interface Standard) libraries for your processor. These should be available from ST, and they make it possible to access and modify registers exactly as you describe. Meaningful constants should be defined for bit-banging all of the registers.






                                          share|improve this answer









                                          $endgroup$














                                          • $begingroup$
                                            To be precise, ST provide functions on top of CMSIS. CMSIS was designed so that the common parts of a Cortex-M system could be reused across multiple silicon vendors. Vendors then bolt their differentiating hardware in using the CMSIS API. The aim is one can access the C-M's registers in the same way using ST, TI, etc microcontrollers, as well as other things that would be useful independent of the vendor.
                                            $endgroup$
                                            – awjlogan
                                            7 hours ago















                                          0













                                          $begingroup$

                                          What you are looking is the CMSIS (Cortex-M Software Interface Standard) libraries for your processor. These should be available from ST, and they make it possible to access and modify registers exactly as you describe. Meaningful constants should be defined for bit-banging all of the registers.






                                          share|improve this answer









                                          $endgroup$














                                          • $begingroup$
                                            To be precise, ST provide functions on top of CMSIS. CMSIS was designed so that the common parts of a Cortex-M system could be reused across multiple silicon vendors. Vendors then bolt their differentiating hardware in using the CMSIS API. The aim is one can access the C-M's registers in the same way using ST, TI, etc microcontrollers, as well as other things that would be useful independent of the vendor.
                                            $endgroup$
                                            – awjlogan
                                            7 hours ago













                                          0














                                          0










                                          0







                                          $begingroup$

                                          What you are looking is the CMSIS (Cortex-M Software Interface Standard) libraries for your processor. These should be available from ST, and they make it possible to access and modify registers exactly as you describe. Meaningful constants should be defined for bit-banging all of the registers.






                                          share|improve this answer









                                          $endgroup$



                                          What you are looking is the CMSIS (Cortex-M Software Interface Standard) libraries for your processor. These should be available from ST, and they make it possible to access and modify registers exactly as you describe. Meaningful constants should be defined for bit-banging all of the registers.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered 8 hours ago









                                          Elliot AldersonElliot Alderson

                                          11.8k2 gold badges12 silver badges25 bronze badges




                                          11.8k2 gold badges12 silver badges25 bronze badges














                                          • $begingroup$
                                            To be precise, ST provide functions on top of CMSIS. CMSIS was designed so that the common parts of a Cortex-M system could be reused across multiple silicon vendors. Vendors then bolt their differentiating hardware in using the CMSIS API. The aim is one can access the C-M's registers in the same way using ST, TI, etc microcontrollers, as well as other things that would be useful independent of the vendor.
                                            $endgroup$
                                            – awjlogan
                                            7 hours ago
















                                          • $begingroup$
                                            To be precise, ST provide functions on top of CMSIS. CMSIS was designed so that the common parts of a Cortex-M system could be reused across multiple silicon vendors. Vendors then bolt their differentiating hardware in using the CMSIS API. The aim is one can access the C-M's registers in the same way using ST, TI, etc microcontrollers, as well as other things that would be useful independent of the vendor.
                                            $endgroup$
                                            – awjlogan
                                            7 hours ago















                                          $begingroup$
                                          To be precise, ST provide functions on top of CMSIS. CMSIS was designed so that the common parts of a Cortex-M system could be reused across multiple silicon vendors. Vendors then bolt their differentiating hardware in using the CMSIS API. The aim is one can access the C-M's registers in the same way using ST, TI, etc microcontrollers, as well as other things that would be useful independent of the vendor.
                                          $endgroup$
                                          – awjlogan
                                          7 hours ago




                                          $begingroup$
                                          To be precise, ST provide functions on top of CMSIS. CMSIS was designed so that the common parts of a Cortex-M system could be reused across multiple silicon vendors. Vendors then bolt their differentiating hardware in using the CMSIS API. The aim is one can access the C-M's registers in the same way using ST, TI, etc microcontrollers, as well as other things that would be useful independent of the vendor.
                                          $endgroup$
                                          – awjlogan
                                          7 hours ago

















                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to Electrical Engineering Stack Exchange!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          Use MathJax to format equations. MathJax reference.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f455051%2fstm32-cannot-reach-individual-registers-and-pins-as-pic%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                          Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                          François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480