2024-01-26 05:59 AM
I'm developing a new project based on STM32G431RB using STM32CubeIDE 14.1.0 on macOS
I'm having touble where the program will hang at the first call of HAL_Delay() and digging deeper it's hanging because HAL_GetTick always returns 0
It looks like the SysTick timer is not running, or it's interrupt is not being called.
I do not have interrupts enabled on any other peripherals.
I have TIM1 configured as CH1_CH1N and that is working.
I have TIM2 configured in Encoder mode, and that is working too.
The only thing that is not working seems to be the System Timer.
What could I possibly have done to disable it?
My clock source is set to HSI
Here is my "main"
int main(void)
{
/* USER CODE BEGIN 1 */
uint8_t msg[64];
uint32_t lastCount;
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_TIM2_Init();
MX_USART2_UART_Init();
MX_SPI1_Init();
MX_TIM1_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_ALL);
HAL_Delay(100); /* <-- IT HANGS HERE !!! */
brake_set();
lastCount = TIM2->CNT;
sprintf((char*) msg, "Startup count: %ld\r\n", lastCount);
HAL_UART_Transmit(&huart2, msg, strlen((char*) msg), 500);
motor_spinup_test();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) {
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
It hangs where I've shown in the comment above at HAL_Delay(100)
Any ideas?
Solved! Go to Solution.
2024-01-26 10:33 AM
The nucleo uses option bytes to boot into flash. Are yours set to do the same?
2024-01-26 06:40 AM
HAL_InitTick is called at the end of HAL_Init. Step through, does it return HAL_OK? Is it using systick or some other timer?
Are interrupts enabled? They should be, but you can add __enable_irq(); to ensure.
2024-01-26 07:10 AM
Hello,
Try to isolate the systick function and remove all the stuff not related to it: ADC, SPI TIM etc .. Do you face the same issue?
2024-01-26 07:22 AM
Thanks for your reply.
To test this I created an empty project based on Nucleo-G431RB board and ran it on a Nucleo board and it works perfectly. But when run on my own board the exact same project hangs on any call to HAL_Delay()
So something in my design is not letting the system timer run. Hmmm.
I've attached my schematic.
2024-01-26 07:49 AM
Check your BOOT pin. It's floating.
Check the application note AN5093 Getting started with STM32G4 series hardware development boards / Figure 8
2024-01-26 08:04 AM
Thank you again,
Yes, I considered the boot0 pin - but it is also floating in the NUCLEO board
Plus, the code does start and run. Just the system timer is not running.
I'm beginning to suspect faulty or damaged chips. They were assembled by a reputable PCB firm in China.
I'm very careful with ESD using an ESD mat on the workbench, and proper ESD wrist straps etc.
I think I will transplant the STM32 from the nucleo board onto my board and see if the problem persists or goes away.
2024-01-26 09:44 AM
So I have 10 of these prototype boards, and so I pulled out a brand new one, programmed it with the project and it worked... kindof.
If I start the project with the dbugger attached using the RUN button then it works fine. All the timers and UART etc are doing there thing.
But if I disconnect the programmer and reboot - it hangs at the first call to HAL_Delay. So something is causing the system timer not to start. I cannot find out what it is. I've checked all the VSS and VDD pins, all are good, VDD is 3.3 V and nice and clean. Reset signal is present and correct. If I manually reset (by taking NRST pin to gnd,) I get the same symptoms. I tried adding __enable_irq() but it made no difference at all. The chip looks genuine.
2024-01-26 10:03 AM - edited 2024-01-26 10:04 AM
> But if I disconnect the programmer and reboot - it hangs at the first call to HAL_Delay.
How are you determining this exactly without a debugger attached?
Feels like a floating BOOT0 pin would explain the general behavior.
2024-01-26 10:09 AM
>>How are you determining this exactly without a debugger attached?
I'm observing the output of PWM on TIM 1 CH1 using an oscilloscope.
>>Feels like a floating BOOT0 pin would explain the general behavior.
Yes maybe, but the NUCLEO boards do have this pin floating. Also, if BOOT0 was to blame, it would be booting from SRAM which would not run Main and I wouldn't see my PWM on the oscilloscpe.
However, to be sure I will tie the BOOT0 pin to GND and see what happens.
2024-01-26 10:15 AM
In most STM32 BOOT0 is it's own pin, here it shares functionality with PB8
Check that their aren't Option Byte settings to perform an equivalent function, ie boot into user flash by default.
Make sure that SystemInit() sets SCB->VTOR to your Vector Table address