2022-01-02 04:01 AM
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 */
2022-01-02 08:41 AM
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 */
}
2022-01-02 10:49 AM
this is just simple bit shifting operation, i performed on registers
and i replaced this:
with this:
but, it still doesn't works...
2022-01-02 11:03 AM
No and NO
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 */
}
2022-01-03 12:25 AM
Thank you very much as later i figured out to use this:
instead of using only this...
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 */
}