Skip to main content
DPila.1
Associate II
April 3, 2023
Question

Code works only in Debug Mode

  • April 3, 2023
  • 6 replies
  • 5636 views

The code runs in debug mode, however when I disconnect debugger and run the code normally it does not work as working in debug mode?

I am using STM32H7xx single core microcontroller.

Awaiting to hearing from you.

This topic has been closed for replies.

6 replies

Rim LANDOLSI
ST Employee
April 3, 2023

Hello @DPila.1​ and welcome to community,

Could you, please, provide screenshot on how you run the code and if there are errors occurred.

It could be, also, helpful to provide which CubeIDE version used for this project.

Thanks,

Rim

DPila.1
DPila.1Author
Associate II
April 3, 2023

CubeIDE version 1.12.0

Below is my Booting section.

int main(void)
{
 /* USER CODE BEGIN 1 */
 int8_t mainStatus = 0x0F;
 uint8_t readValue = 0;
 /* USER CODE END 1 */
 
 /* MCU Configuration--------------------------------------------------------*/
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 
 /* USER CODE BEGIN Init */
 SCB_InvalidateDCache();
 __disable_irq();
 __disable_fault_irq();
 
 __DSB();
 /* USER CODE END Init */
 
 /* Configure the system clock */
 SystemClock_Config();
 
 /* USER CODE BEGIN SysInit */
 SCB_EnableDCache();
 __enable_irq();
 __enable_fault_irq();
 
 GPIO_Flash_Pins_Reset();
 /* USER CODE END SysInit */
 
 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_OCTOSPI1_Init();
 MX_UART4_Init();
 /* USER CODE BEGIN 2 */
 __DSB();
 
 /* Initialization Complete */
 while((HAL_UART_GetState(UART_GetHandle(4)) & HAL_UART_STATE_BUSY_TX) == HAL_UART_STATE_BUSY_TX)
 {}
 
 if(HAL_UART_Transmit(UART_GetHandle(4), (uint8_t *)"Main Started!\r\n\0", 16, UART4_TIMEOUT) != HAL_OK)
 {
	 return (HAL_ERROR);
 }
 
 mainStatus = OSPI_SetupFlash(OSPI_GetHandle(1), 0);
 (void)mainStatus;
 
 /* Flash Setup Complete */
 if(HAL_UART_Transmit(UART_GetHandle(4), (uint8_t *)"QSPI Flash Initialized!\r\n\0", 26, UART4_TIMEOUT) != HAL_OK)
 {
	 return (HAL_ERROR);
 }
 
// readValue = (*(uint8_t *)(0x92000008));
 (void)readValue;
 
 /* USER CODE END 2 */
 
 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */
 
 /* USER CODE BEGIN 3 */
 }
 /* USER CODE END 3 */
}

Code does not reach line 52 in this case. It reaches up to line 48. However in case of debug mode it reaches line 64 without any issue.

Tesla DeLorean
Guru
April 3, 2023

Check BOOT0 configuration on board.

SCB_InvalidatedDCache() is almost always the wrong choice..

Disabling interrupts tends to break SysTick based timeouts.

Make sure you enable all the clocks you expect to be running. Perhaps dump RCC in working/not-working cases. The debug tends to enable things it needs to facilitate it's work, without it you're expected to do all the initialization you need.

Not sure what's going on with QSPI/OSPI, the presentation here is very superficial.. Usually the initialization is multi-phase, decompose/bisect until you identify what specifically fails. Most IC lack an async reset, many have non-volatile settings, and expectations that commands will complete before the next one is issued.

Make a string printing function that computes the length on the fly, hard coding values seems such a poor choice.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
DPila.1
DPila.1Author
Associate II
April 4, 2023

QSPI Flash I am using can work up to speeds of 133MHz. I am giving clock to QSPI through PLL2Q which is 190MHz further the clock goes through QSPI prescalar of 4 before applied to Flash.

As soon as QSPI is initialized I turn ON power to Flash Chip through P-MOS, post that I wait for 10 milliseconds before issuing first command i.e. read status register command to check if flash is busy or not.