Does the following picture tell that what went wrong?
With a debugger, you would look at Hardfault Status Register and others. If there is some actual reason not to use a debugger, you can just print those interesting registers to UART as well in your hardfault handler (make it an infinite loop which prints every second so that you don't miss the printout when it happens).
The address 0x40012C00 is the start of TIM1 register: it should not appear in the shown stack trace!
Of course, you'll find no code there.
The address below could be legit (as 0x00000000 is an alias for the flash at 0x08000000 in normal boot mode).
Moreover, the "Signal Handler called at 0xFFFFFFF1" is quite suspect: the value of 0xFFFFFFF1 is an EXCEPTION_RETURN (loaded in LR when entering exceptions) and means that the CPU was already in handler mode when fault hit, i.e., already in an interrupt servicing routine or in a fault handler.
In the second case the processor enters lockup (only reset and NMI accepted) and the stack unwinding in gdb gets very confused (at least it used to - not sure this is still the case, but it looks like).
You might need to follow ataradov's instructions to unwind the stack manually.
/* Change the htim state */
htim->State = HAL_TIM_STATE_READY;
8004968: 2301 movs r3, #1
__HAL_UNLOCK(htim);
800496a: 2000 movs r0, #0
htim->State = HAL_TIM_STATE_READY;
800496c: 702b strb r3, [r5, #0]
__HAL_UNLOCK(htim);
800496e: 7020 strb r0, [r4, #0]
return HAL_OK;
}
8004970: bdf0 pop {r4, r5, r6, r7, pc}
8004972: 46c0 nop ; (mov r8, r8)
8004974: 40012c00 .word 0x40012c00
8004978: ff0fffff .word 0xff0fffff
800497c: 40000400 .word 0x40000400
8004980: 40014000 .word 0x40014000
08004984 <HAL_TIMEx_CommutCallback>:
8004984: 4770 bx lr
08004986 <HAL_TIMEx_BreakCallback>:
8004986: 4770 bx lr
/* Check if the update flag is set after the Update Generation, if so clear the UIF flag */
if (HAL_IS_BIT_SET(TIMx->SR, TIM_FLAG_UPDATE))
800489a: 6903 ldr r3, [r0, #16]
800489c: 4213 tst r3, r2
800489e: d002 beq.n 80048a6 <TIM_Base_SetConfig+0x7e>
{
/* Clear the update flag */
CLEAR_BIT(TIMx->SR, TIM_FLAG_UPDATE);
80048a0: 6903 ldr r3, [r0, #16]
80048a2: 4393 bics r3, r2
80048a4: 6103 str r3, [r0, #16]
}
}
80048a6: bd10 pop {r4, pc}
80048a8: 40012c00 .word 0x40012c00
80048ac: 40000400 .word 0x40000400
80048b0: 40002000 .word 0x40002000
80048b4: 40014000 .word 0x40014000
80048b8: 40014400 .word 0x40014400
80048bc: 40014800 .word 0x40014800
80048c0: fffffcff .word 0xfffffcff
080048c4 <HAL_TIM_Base_Init>:
{
80048c4: b570 push {r4, r5, r6, lr}
80048c6: 0004 movs r4, r0
return HAL_ERROR;
80048c8: 2001 movs r0, #1
if (htim == NULL)
80048ca: 2c00 cmp r4, #0
80048cc: d023 beq.n 8004916 <HAL_TIM_Base_Init+0x52>
if (htim->State == HAL_TIM_STATE_RESET)
800466e: 4770 bx lr
__HAL_TIM_ENABLE(htim);
8004670: 681a ldr r2, [r3, #0]
8004672: 4302 orrs r2, r0
8004674: 601a str r2, [r3, #0]
return HAL_OK;
8004676: 2000 movs r0, #0
8004678: e7f9 b.n 800466e <HAL_TIM_Base_Start_IT+0x46>
800467a: 46c0 nop ; (mov r8, r8)
800467c: 40012c00 .word 0x40012c00
8004680: 40000400 .word 0x40000400
8004684: 40014000 .word 0x40014000
8004688: 00010007 .word 0x00010007
0800468c <HAL_TIM_Base_Stop_IT>:
{
/* Check the parameters */
assert_param(IS_TIM_INSTANCE(htim->Instance));
/* Disable the TIM Update interrupt */
__HAL_TIM_DISABLE_IT(htim, TIM_IT_UPDATE);
800468c: 2101 movs r1, #1
800468e: 6803 ldr r3, [r0, #0]
I suggested making the fet switch slowly with 10-22K Rgate + 100nF, that way it would take 5-10ms to switch.
You induced a problem by choosing fets conducting extremely well at low VGS (24 mOhm at 2.5V).
Do you need such low RDS to power a oled screen? I don't think so.
The problem? It will conduct so fast and so much, the charging current will be huge, causing all the issues you're having.
Did you measure the current at VDD rail? Was it 300mA? Well, the STLQ015 LDO is rated for 150mA!
Internally limited to 250-350mA, so you might be in the limit, any extra load causes voltage drop and it won't be able to respond properly to any small current surge.
As the OLED screens ususally carry their own LDO, just power it from 5V directly (As already talked).
Do you have oscilloscope?
If so, make a single run triggered by the gpio, second channel connected to VDD.
You'll see how VDD reacts to the load, if the voltage drop is still too large, increase the resistor.
Was that 10uf cap you used ceramic or electrolytic?
Ceramics have extremely low esr, so the current spike can be short and huge, beyond what most electrolytics can filter.
Try adding several 1uF ceramics here and there!