cancel
Showing results for 
Search instead for 
Did you mean: 

No output on GPIOs

Ursus
Associate

Hello

I have a STM32H7R3V8T6 and want to use a few peripherals and GPIOs. However, I don't manage to see an output with my analyzer. The peripherals themselves seem to work: An XSPI receive for example does receive some dummy bytes and takes exactly the required time for the transfer (measured with the cycle counter), but the pins do not show anything.

I reduced my code and came up with this simple demonstration of how I initialize a GPIO:

int main(void)
{
	SystemCoreClockUpdate();
	HAL_Init();
	SystemClock_Config();

	__HAL_RCC_GPIOB_CLK_ENABLE();
	GPIO_InitTypeDef GPIO_InitStruct = {0};
	GPIO_InitStruct.Pin = GPIO_PIN_12;
	GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct.Pull = GPIO_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
	HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

	while (1) {
		HAL_GPIO_TogglePin(GPIOB, 12);
		HAL_Delay(10);
	}
}

The debugger shows that I reach the loop. The registers of the peripheral seem to be correct, but the pin doesn't toggle. This also happens with other GPIOs and pins that are assigned to peripherals such as the XSPI.
What could I be missing?

Thank you very much.

PS: See the attachment for the clock setup, if that matters.

 

1 ACCEPTED SOLUTION

Accepted Solutions

@Ursus As @Chris21 said, the 2nd parameter to HAL_GPIO_TogglePin needs to be one of the GPIO_PIN_x definitions.

 

The GPIO_PIN_x definitions are bit-maps - not numbers:

/** @defgroup GPIO_pins GPIO pins
  * @{
  */
#define GPIO_PIN_0                 ((uint16_t)0x0001U)  /* Pin 0 selected    */
#define GPIO_PIN_1                 ((uint16_t)0x0002U)  /* Pin 1 selected    */
#define GPIO_PIN_2                 ((uint16_t)0x0004U)  /* Pin 2 selected    */
#define GPIO_PIN_3                 ((uint16_t)0x0008U)  /* Pin 3 selected    */
#define GPIO_PIN_4                 ((uint16_t)0x0010U)  /* Pin 4 selected    */
#define GPIO_PIN_5                 ((uint16_t)0x0020U)  /* Pin 5 selected    */
#define GPIO_PIN_6                 ((uint16_t)0x0040U)  /* Pin 6 selected    */
#define GPIO_PIN_7                 ((uint16_t)0x0080U)  /* Pin 7 selected    */
#define GPIO_PIN_8                 ((uint16_t)0x0100U)  /* Pin 8 selected    */
#define GPIO_PIN_9                 ((uint16_t)0x0200U)  /* Pin 9 selected    */
#define GPIO_PIN_10                ((uint16_t)0x0400U)  /* Pin 10 selected   */
#define GPIO_PIN_11                ((uint16_t)0x0800U)  /* Pin 11 selected   */
#define GPIO_PIN_12                ((uint16_t)0x1000U)  /* Pin 12 selected   */
#define GPIO_PIN_13                ((uint16_t)0x2000U)  /* Pin 13 selected   */
#define GPIO_PIN_14                ((uint16_t)0x4000U)  /* Pin 14 selected   */
#define GPIO_PIN_15                ((uint16_t)0x8000U)  /* Pin 15 selected   */
#define GPIO_PIN_All               ((uint16_t)0xFFFFU)  /* All pins selected */

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

View solution in original post

7 REPLIES 7
Chris21
Senior III
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_12);
TDK
Super User

XSPI pins should be VERY_HIGH. What is the hardware and where are you measuring? XSPI is typically fast data rate so ensure your capture device is sampling fast enough. Not really enough info here to diagnose apart from the bug in the posted code.

> The registers of the peripheral seem to be correct

There is no way ODR toggles correctly given the code you posted above.

If you feel a post has answered your question, please click "Accept as Solution".

@Ursus As @Chris21 said, the 2nd parameter to HAL_GPIO_TogglePin needs to be one of the GPIO_PIN_x definitions.

 

The GPIO_PIN_x definitions are bit-maps - not numbers:

/** @defgroup GPIO_pins GPIO pins
  * @{
  */
#define GPIO_PIN_0                 ((uint16_t)0x0001U)  /* Pin 0 selected    */
#define GPIO_PIN_1                 ((uint16_t)0x0002U)  /* Pin 1 selected    */
#define GPIO_PIN_2                 ((uint16_t)0x0004U)  /* Pin 2 selected    */
#define GPIO_PIN_3                 ((uint16_t)0x0008U)  /* Pin 3 selected    */
#define GPIO_PIN_4                 ((uint16_t)0x0010U)  /* Pin 4 selected    */
#define GPIO_PIN_5                 ((uint16_t)0x0020U)  /* Pin 5 selected    */
#define GPIO_PIN_6                 ((uint16_t)0x0040U)  /* Pin 6 selected    */
#define GPIO_PIN_7                 ((uint16_t)0x0080U)  /* Pin 7 selected    */
#define GPIO_PIN_8                 ((uint16_t)0x0100U)  /* Pin 8 selected    */
#define GPIO_PIN_9                 ((uint16_t)0x0200U)  /* Pin 9 selected    */
#define GPIO_PIN_10                ((uint16_t)0x0400U)  /* Pin 10 selected   */
#define GPIO_PIN_11                ((uint16_t)0x0800U)  /* Pin 11 selected   */
#define GPIO_PIN_12                ((uint16_t)0x1000U)  /* Pin 12 selected   */
#define GPIO_PIN_13                ((uint16_t)0x2000U)  /* Pin 13 selected   */
#define GPIO_PIN_14                ((uint16_t)0x4000U)  /* Pin 14 selected   */
#define GPIO_PIN_15                ((uint16_t)0x8000U)  /* Pin 15 selected   */
#define GPIO_PIN_All               ((uint16_t)0xFFFFU)  /* All pins selected */

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Pavel A.
Super User

Probably you've forgotten to enable the GPIO port itself:

__HAL_RCC_GPIOB_CLK_ENABLE();

Gyessine
ST Employee

Hello @Ursus 
-Are you using a custom-PCB design?
-Make sure that your sampling rate is good enough.

-What do you see in the ODR register?
BR
Gyessine

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Ursus
Associate

Thanks a lot for your help! The GPIO bitmask solved it, though for the pins on ports O and P (used for XSPI) I additionally had to add the line

HAL_PWREx_EnableXSPIM1();

in order to enable its separate power domain, otherwise there was no output.


@Ursus wrote:

 for the pins on ports O and P (used for XSPI) I additionally had to add the line

HAL_PWREx_EnableXSPIM1();

in order to enable its separate power domain


Indeed - see: Solved: Nucleo H7S3L8: No GPIO output on ports O and P.

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.