Skip to main content
BBrow.2
Associate III
December 17, 2022
Question

I am trying to simply turn PA0 HI on an STM32F030F4P6 using Cube IDE. No matter what I do, if I try to write to any GPIO registers (including using the auto generated Inits), I get a Hard Fault. Nothing solves it :(

  • December 17, 2022
  • 16 replies
  • 2938 views

I am trying to simply turn PA0 HI on an STM32F030F4P6 using Cube IDE.

No matter what I do, if I try to write to any GPIO registers (including using the auto generated Inits), I get a Hard Fault. Nothing solves it :( Tried debugging it, no matter what I do, I get a hard fault at any attempt to use any GPIO registers using any methods!!

This topic has been closed for replies.

16 replies

S.Ma
Principal
December 17, 2022

Have you selected the right mcu in the project settings? If you can go in debug mode with st link, you can view and change all hw registers manually.

waclawek.jan
Super User
December 17, 2022

Is this a "known good" hardware like Nucleo or Disco?

JW

gbm
Lead III
December 17, 2022

Looking for sympathy or for help? In the 2nd case it is necessary to post some code including the port setup and the attempted operations.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
BBrow.2
BBrow.2Author
Associate III
December 17, 2022

I have tried creating the project in MX Cube, but strangly, it does not open it in IDE cube like it does for other CPUs. Its code fails.

I have tried creating new project in IDE cube, it fails (Note:- IDE cube does not have STM32F030x4.h, it only has STM32F030x6.h).

I have tried manually doing everything.

One example:-

 HAL_Init();

// SystemClock_Config();

// MX_GPIO_Init();

 RCC->AHBENR |= (1<<17);

 RCC->AHBRSTR |= (1<<17);

 GPIOA->ODR = 0xFF;

Hard Fault at GPIOA->ODR = 0xFF;

same fault if I change it to GPIO->MODER etc

same fault if I include the SystemClock_Config(); and remove the RCC lines

different fault (Hard fault somewhere else) if I enable MX_GPIO_Init();

BBrow.2
BBrow.2Author
Associate III
December 18, 2022

0693W00000WLFIKQA5.jpg080002ae <HardFault_Handler>:

/**

 * @brief This function handles Hard fault interrupt.

 */

void HardFault_Handler(void)

{

 80002ae: b580    push {r7, lr}

 80002b0: af00    add r7, sp, #0

 /* USER CODE BEGIN HardFault_IRQn 0 */

 /* USER CODE END HardFault_IRQn 0 */

 while (1)

 80002b2: e7fe    b.n 80002b2 <HardFault_Handler+0x4>

BBrow.2
BBrow.2Author
Associate III
December 18, 2022

Stepping it from RESET shows it stops at the GPIO command (str - 800024a)

 GPIOA->ODR = 0xFF;

 8000244: 2390    movs r3, #144 ; 0x90

 8000246: 05db    lsls r3, r3, #23

 8000248: 22ff    movs r2, #255 ; 0xff

 800024a: 615a    str r2, [r3, #20]

//  GPIOA->

R3 appears to be correct (48000000 is GPIOA address, 20 more is ODR address)

BBrow.2
BBrow.2Author
Associate III
December 18, 2022

More specifically, GPIO is on AHB2 (Nothing else on AHB2), so it would seem that there is some kind of issue with AHB2 access.

BBrow.2
BBrow.2Author
Associate III
December 18, 2022

0693W00000WLFJmQAP.jpgCube IDE debug

BBrow.2
BBrow.2Author
Associate III
December 18, 2022

Even using:-

*((uint32_t *)addr) = 0xff;

if addr = 0x40020000 (AHB1) no problem

if addr = 0x48000000(AHB2) HARD FAULT

S.Ma
Principal
December 18, 2022

If this is not a Nucleo board, get a Genuine Nucleo to test your code, because that is probably the first thing to share with support.