Skip to main content
Explorer II
June 20, 2023
Solved

Newbie Blue Pill Blink CubeIDE

  • June 20, 2023
  • 7 replies
  • 5691 views

Hi,

Pretty new to STM32 but reasonably comfortable with ESP32, Pico and 40 years of C++. So old enough to expect it to be me.

Cannot get blink to work with blue pill 32k using cube ide on ubuntu 23.04 with 

 

 

while (1)
 {
 /* USER CODE END WHILE */
 HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
 HAL_Delay(500);

 /* USER CODE BEGIN 3 */
 }

 

 

I do set the PC13 pin to output and set the sys debug thing but nothing else aside from the code.

Works fine for the neucleo board but not for this board. Also works fine with arduino so guessing the Programmer working fine. Although for neucleo I am not using the stlink v2.

Please remember I am new and could easily be doing something wrong.

Not at PC so maybe typos 

Thanks

    This topic has been closed for replies.
    Best answer by Peter BENSCH

    ST resources are dedicated to supporting genuine ST products. We are not committed to ensuring that clones/fakes work properly with the firmware we provide.

    7 replies

    Technical Moderator
    June 20, 2023

    Hello,

    please share your main.c file if you wish, I can check whether this is working on my bluepill board.

    bibble235Author
    Explorer II
    June 20, 2023
    /* USER CODE BEGIN Header */
    /**
     ******************************************************************************
     * @file : main.c
     * @brief : Main program body
     ******************************************************************************
     * @attention
     *
     * Copyright (c) 2023 STMicroelectronics.
     * All rights reserved.
     *
     * This software is licensed under terms that can be found in the LICENSE file
     * in the root directory of this software component.
     * If no LICENSE file comes with this software, it is provided AS-IS.
     *
     ******************************************************************************
     */
    /* 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);
    static void MX_GPIO_Init(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)
    {
     /* 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();
    
     /* USER CODE BEGIN SysInit */
    
     /* USER CODE END SysInit */
    
     /* Initialize all configured peripherals */
     MX_GPIO_Init();
     /* USER CODE BEGIN 2 */
    
     /* USER CODE END 2 */
    
     /* Infinite loop */
     /* USER CODE BEGIN WHILE */
     while (1)
     {
     /* USER CODE END WHILE */
    	HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
    	HAL_Delay(500);
    
     /* 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();
     }
    }
    
    /**
     * @brief GPIO Initialization Function
     * @PAram None
     * @retval None
     */
    static void MX_GPIO_Init(void)
    {
     GPIO_InitTypeDef GPIO_InitStruct = {0};
    /* USER CODE BEGIN MX_GPIO_Init_1 */
    /* USER CODE END MX_GPIO_Init_1 */
    
     /* GPIO Ports Clock Enable */
     __HAL_RCC_GPIOC_CLK_ENABLE();
     __HAL_RCC_GPIOA_CLK_ENABLE();
    
     /*Configure GPIO pin Output Level */
     HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
    
     /*Configure GPIO pin : PC13 */
     GPIO_InitStruct.Pin = GPIO_PIN_13;
     GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
     HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
    
    /* USER CODE BEGIN MX_GPIO_Init_2 */
    /* USER CODE END MX_GPIO_Init_2 */
    }
    
    /* 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 */

    bibble235_0-1687258490481.png

    And the diff from the working neucleo board F301 I think!

    Technical Moderator
    June 20, 2023

    I have just tested your code as is, it is working fine. Your board might be defective then.

    Graduate
    June 20, 2023

    Check the Boot0 pin. It should be grounded/set to 0.

    bibble235Author
    Explorer II
    June 20, 2023

    Not sure why the arduino version would work. I will debug it and check not crashing

    bibble235Author
    Explorer II
    June 21, 2023

    So anyone trying and have my problems.

    I followed the youtube https://www.youtube.com/watch?v=e_NSqz5P8Qk and this worked for me. Diffing between first attempt and this shows

    bibble235_0-1687343513946.png

    Where the working code is on the right. Not sure why but clearly the suggestion around the clock configuration is a pointer. 

    Thanks.

     

    Super User
    June 21, 2023

    @bibble235 You wrote that you are new to STM32. Are you just playing/learning or have a concrete project?

    If the former, you may want to look at newer STM32s and boards, as these are more capable and interesting than vintage  STM32F1 and the "pills". Also, less risk to get fake unsupported parts.

    bibble235Author
    Explorer II
    June 21, 2023

    Comparing with Pico, ESP32s and wanted to become more acquainted with the STM32 eco system. Started looking at rust on MCUs too. Clearly the cheapness of some of these products may have some use cases in monitoring. Overall trying to improve my understanding.

    Technical Moderator
    June 21, 2023

    As @Pavel A. already mentioned, the probability of getting a board with the original STM32 with the Blue Pill has been close to zero for years.
    In addition, unlike the NUCLEO, the Blue Pill has no debugger/programmer. With which hardware or in which way do you want to program the Blue Pill?

    bibble235Author
    Explorer II
    June 21, 2023

    Speaking as a plain customer, there is a lot of videos and pages with the blue pill. Clearly a great marketing name. Certainly more catchy than STM32F103C6T6. This was the first suggestion to me I remembered when looking for Rust.  Cannot remember the price but not expensive. Bought a higher model NUCLEO-F446RE for the Udemy course. My end goal is (maybe) to get a role which involves MCUs but as an aside enjoy electronics. I have forty years in IT half in PM and half as an engineer.

    If I was working for ST32, not fishing, I would make blink on a clearly popular product as easy as possible regardless of clones. Your first experience matters especially where you seem to be well documented and supported.

    I enjoy the challenge and it was on Ubuntu 23.04 I have experienced, but many will want to install the vs code extension

    Pressing on and will continue to feedback.

    and expect it to work. If you want your eco system to be top of the list follow the popular linux distros ubuntu, mint etc and make a bundle that just works.

    Technical Moderator
    April 14, 2025

    ST resources are dedicated to supporting genuine ST products. We are not committed to ensuring that clones/fakes work properly with the firmware we provide.