2024-10-17 12:39 AM
i'm trying to run a simple blinking led program on my stm32f103c8t6 (after i run it several times before successfully), and it doesn't work, when i fix the delay in 1000 ms the led is always on, when i decrement it to 100, 200, 300 it's working properly, but whenever i go above 400 ms it's not working:
Solved! Go to Solution.
2024-10-17 03:00 AM - edited 2024-10-17 03:01 AM
Hello @Monssef and welcome to the community,
"X" Pill board flavors (Blue/Black .. other colors) are not the product of ST. They don't contain genuine STM32 chips for years but just fake ones.
I suggest you to purchase any of official ST boards such as NUCLEO-F103RB containing genuine STM32 MCUs.
2024-10-17 03:00 AM - edited 2024-10-17 03:01 AM
Hello @Monssef and welcome to the community,
"X" Pill board flavors (Blue/Black .. other colors) are not the product of ST. They don't contain genuine STM32 chips for years but just fake ones.
I suggest you to purchase any of official ST boards such as NUCLEO-F103RB containing genuine STM32 MCUs.
2024-10-17 05:26 AM
okeyy, but i think all the mcu chips are manufactured by ST because i got already one in a custom pcb and i will rerun the same program in it (even i will struggle to access the pins because i have only the interfaces needed in my project)
thank you !
2024-10-17 05:53 AM
Can you share the project code? I have webact bluepill stm32f103c8t6.
2024-10-17 05:58 AM
@Monssef wrote:i think all the mcu chips are manufactured by ST
No, they're not - by definition, fake & clone STM32 chips are not manufactured by ST !
For a couple of examples of the troubles fake parts can cause, see:
2024-10-17 06:16 AM
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE(); // Enable clock for GPIOA
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // Ensure it's set as output push-pull
GPIO_InitStruct.Pull = GPIO_NOPULL; // No pull-up or pull-down resistors
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; // Set speed to low (or medium/high if needed)
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); // Initialize GPIO
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET); // Ensure the pin starts LOW
/* USER CODE BEGIN 1 */
/* 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();
if (HAL_SYSTICK_Config(SystemCoreClock / 1000) != 0)
{
Error_Handler(); // Handle error
}
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
HAL_Delay(1000);
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
/* 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 */
2024-10-17 09:52 AM - edited 2024-10-17 09:53 AM
HAL_Delay() depends on HAL_GetTick()... So not sure how the hardware is causing the issue if it works up to 400ms, so I am curious
You code works well on my board.
can you try the code below?
uint32_t prevTime = 0;
if(HAL_GetTick() - prevTime >= 1000)
{
prevTime = HAL_GetTick();
HAL_GPIO_Toggle();
}
2024-10-17 10:39 AM
Hi Andrew Neil,
The program in question is HAL_Delay() which is just waiting in a loop to check if the HAL_GetTick() increments till the delay. So if it works for 400ms why does it not work for higher values? Is it a software bug or can it be caused by HW bug?
2024-10-17 01:21 PM
still getting exactly the same problem as before !