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;
$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.
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...
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?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
$endgroup$
add a comment |
$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.
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...
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?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
$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
add a comment |
$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.
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...
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?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
$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.
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...
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?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
stm32 arm datasheet
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
add a comment |
$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
add a comment |
5 Answers
5
active
oldest
votes
$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.
$endgroup$
add a comment |
$begingroup$
I also moved from PIC to STM, some things changed and you need to read datasheets to understand.
The "datasheet" of the STM only contains some information one peripherals, electrical values... Take a look ate the "Reference Manual" for the registers.
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).
- Use Stm32IDE, you can configure the project without HAL. It will includes CMSIS, some useful headers with all registers already defined.
$endgroup$
add a comment |
$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)
$endgroup$
add a comment |
$begingroup$
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.
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).
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.
$endgroup$
add a comment |
$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.
$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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
$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.
$endgroup$
add a comment |
$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.
$endgroup$
add a comment |
$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.
$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.
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
add a comment |
add a comment |
$begingroup$
I also moved from PIC to STM, some things changed and you need to read datasheets to understand.
The "datasheet" of the STM only contains some information one peripherals, electrical values... Take a look ate the "Reference Manual" for the registers.
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).
- Use Stm32IDE, you can configure the project without HAL. It will includes CMSIS, some useful headers with all registers already defined.
$endgroup$
add a comment |
$begingroup$
I also moved from PIC to STM, some things changed and you need to read datasheets to understand.
The "datasheet" of the STM only contains some information one peripherals, electrical values... Take a look ate the "Reference Manual" for the registers.
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).
- Use Stm32IDE, you can configure the project without HAL. It will includes CMSIS, some useful headers with all registers already defined.
$endgroup$
add a comment |
$begingroup$
I also moved from PIC to STM, some things changed and you need to read datasheets to understand.
The "datasheet" of the STM only contains some information one peripherals, electrical values... Take a look ate the "Reference Manual" for the registers.
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).
- Use Stm32IDE, you can configure the project without HAL. It will includes CMSIS, some useful headers with all registers already defined.
$endgroup$
I also moved from PIC to STM, some things changed and you need to read datasheets to understand.
The "datasheet" of the STM only contains some information one peripherals, electrical values... Take a look ate the "Reference Manual" for the registers.
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).
- Use Stm32IDE, you can configure the project without HAL. It will includes CMSIS, some useful headers with all registers already defined.
edited 7 hours ago
answered 8 hours ago
PierreOlivierPierreOlivier
2452 silver badges9 bronze badges
2452 silver badges9 bronze badges
add a comment |
add a comment |
$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)
$endgroup$
add a comment |
$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)
$endgroup$
add a comment |
$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)
$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)
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
add a comment |
add a comment |
$begingroup$
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.
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).
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.
$endgroup$
add a comment |
$begingroup$
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.
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).
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.
$endgroup$
add a comment |
$begingroup$
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.
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).
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.
$endgroup$
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.
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).
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.
answered 8 hours ago
Michel KeijzersMichel Keijzers
8,28610 gold badges35 silver badges80 bronze badges
8,28610 gold badges35 silver badges80 bronze badges
add a comment |
add a comment |
$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.
$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
add a comment |
$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.
$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
add a comment |
$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.
$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.
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
add a comment |
$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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
$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