cancel
Showing results for 
Search instead for 
Did you mean: 

I don't want to use HAL Library when programming STM32H745I-DISCO Programming Board...

Vijay Krishna
Associate II

can anyone please help, as i am having no result while trying to run a c program without using HAL Library , but i am getting correct result when i am using HAL Library, can anyone please tell me why??

here is the code:

with HAL Library:

#include "main.h"

#ifndef HSEM_ID_0

#define HSEM_ID_0 (0U) /* HW semaphore 0*/

#endif

static void MX_GPIO_Init(void);

int main(void)

{

 /*HW semaphore Clock enable*/

 __HAL_RCC_HSEM_CLK_ENABLE();

 /* Activate HSEM notification for Cortex-M4*/

 HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0));

 HAL_PWREx_ClearPendingEvent();

 HAL_PWREx_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFE, PWR_D2_DOMAIN);

 /* Clear HSEM flag */

 __HAL_HSEM_CLEAR_FLAG(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0));

 /* USER CODE END Boot_Mode_Sequence_1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 MX_GPIO_Init();

 while (1)

 {

 HAL_GPIO_TogglePin(GPIOJ, GPIO_PIN_2);

 HAL_Delay(500);

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

/**

 * @brief GPIO Initialization Function

 * @param None

 * @retval None

 */

static void MX_GPIO_Init(void)

{

 GPIO_InitTypeDef GPIO_InitStruct = {0};

 /* GPIO Ports Clock Enable */

 __HAL_RCC_GPIOJ_CLK_ENABLE();

 /*Configure GPIO pin Output Level */

 HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_2, GPIO_PIN_RESET);

 /*Configure GPIO pin : PJ2 */

 GPIO_InitStruct.Pin = GPIO_PIN_2;

 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

 HAL_GPIO_Init(GPIOJ, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**

 * @brief This function is executed in case of error occurrence.

 * @retval None

 */

void Error_Handler(void)

{

 /* USER CODE BEGIN Error_Handler_Debug */

 /* User can add his own implementation to report the HAL error return state */

 __disable_irq();

 while (1)

 {

 }

 /* USER CODE END Error_Handler_Debug */

}

#ifdef USE_FULL_ASSERT

/**

 * @brief Reports the name of the source file and the source line number

 *     where the assert_param error has occurred.

 * @param file: pointer to the source file name

 * @param line: assert_param error line source number

 * @retval None

 */

void assert_failed(uint8_t *file, uint32_t line)

{

 /* USER CODE BEGIN 6 */

 /* User can add his own implementation to report the file name and line number,

   ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

 /* USER CODE END 6 */

}

#endif /* USE_FULL_ASSERT */

without HAL Library:

#include "main.h"

#include "stm32h745xx.h"

#ifndef HSEM_ID_0

#define HSEM_ID_0 (0U) /* HW semaphore 0*/

#endif

int main(void)

{

 /*HW semaphore Clock enable*/

 __HAL_RCC_HSEM_CLK_ENABLE();

 /* Activate HSEM notification for Cortex-M4*/

 HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0));

 /*

 Domain D2 goes to STOP mode (Cortex-M4 in deep-sleep) waiting for Cortex-M7 to

 perform system initialization (system clock config, external memory configuration.. )

 */

 HAL_PWREx_ClearPendingEvent();

 HAL_PWREx_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFE, PWR_D2_DOMAIN);

 /* Clear HSEM flag */

 __HAL_HSEM_CLEAR_FLAG(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0));

/* USER CODE END Boot_Mode_Sequence_1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

RCC->AHB4ENR |= RCC_AHB4ENR_GPIOJEN;

 GPIOJ->MODER &= (1<<5);

 GPIOJ->MODER |= (1<<4);

 GPIOJ->OSPEEDR &= (1<<5);

 GPIOJ->OSPEEDR &= (1<<4);

 GPIOJ->PUPDR &= ((1<<5) | (1<<4));

 HAL_Init();

 while (1)

 {

  /* USER CODE END WHILE */

 GPIOJ->BSRR |= (1<<2);

 HAL_Delay(500);

 GPIOJ->BSRR |= (1<<18);

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**

 * @brief This function is executed in case of error occurrence.

 * @retval None

 */

void Error_Handler(void)

{

 /* USER CODE BEGIN Error_Handler_Debug */

 /* User can add his own implementation to report the HAL error return state */

 __disable_irq();

 while (1)

 {

 }

 /* USER CODE END Error_Handler_Debug */

}

#ifdef USE_FULL_ASSERT

/**

 * @brief Reports the name of the source file and the source line number

 *     where the assert_param error has occurred.

 * @param file: pointer to the source file name

 * @param line: assert_param error line source number

 * @retval None

 */

void assert_failed(uint8_t *file, uint32_t line)

{

 /* USER CODE BEGIN 6 */

 /* User can add his own implementation to report the file name and line number,

   ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

 /* USER CODE END 6 */

}

#endif /* USE_FULL_ASSERT */

4 REPLIES 4
MM..1
Chief II

From where you have this do nothing good with register

&= (1<<5)

and this toggle without pause

 while (1)
 {
  /* USER CODE END WHILE */
 GPIOJ->BSRR |= (1<<2);
 HAL_Delay(500);
 GPIOJ->BSRR |= (1<<18);
  /* USER CODE BEGIN 3 */
 }

  1. &= (1<<5)

this is just simple bit shifting operation, i performed on registers

and i replaced this:

  1. while (1)
  2. {
  3. /* USER CODE END WHILE */
  4. GPIOJ->BSRR |= (1<<2);
  5. HAL_Delay(500);
  6. GPIOJ->BSRR |= (1<<18);
  7. /* USER CODE BEGIN 3 */
  8. }

with this:

  1. while (1)
  2. {
  3. /* USER CODE END WHILE */
  4. GPIOJ->BSRR = (1<<2);
  5. for(int i=0;i<=5000000; i++);
  6. GPIOJ->BSRR = (1<<18);
  7. /* USER CODE BEGIN 3 */
  8. }

but, it still doesn't works...

No and NO

  1. &= (1<<5)

say set all 32 bit on register to zero except 5 th bit ...

and your while need two delays not other delay or better use ODR xor as normal toggle

while (1)
 {
  /* USER CODE END WHILE */
 GPIOJ->ODR ^= (1<<2);
 HAL_Delay(500);
  /* USER CODE BEGIN 3 */
 }

Vijay Krishna
Associate II

Thank you very much as later i figured out to use this:

  1. &= ~(1<<5)

instead of using only this...

  1. &= (1<<5)

I later fixed my code accordingly as:

RCC->AHB4ENR |= RCC_AHB4ENR_GPIOJEN;

 GPIOJ->MODER &= ~(GPIO_MODER_MODE2_1);

 GPIOJ->MODER |= GPIO_MODER_MODE2_0;

 GPIOJ->OSPEEDR &= ~(GPIO_OSPEEDR_OSPEED2);

 GPIOJ->PUPDR &= ~(GPIO_PUPDR_PUPD2);

 /* USER CODE END 2 */

 MX_GPIO_Init(); // not sure,! what it does, but it doesn't cause a problem too...

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

 GPIOJ->ODR ^= GPIO_ODR_OD2;

 HAL_Delay(500);

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}