Created
December 2, 2018 22:51
-
-
Save jenschr/189fa3a802fa5d37705cff8d1b9a58ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
**=========================================================================== | |
** Notes during development of this tiny Blink program | |
** - Blinking a LED isn't easy unless you know exactly what libraries you | |
** need to include & what registers to set. The simplest way is to try | |
** setting as much as possible up using CubeMX. This will add all the | |
** needed HAL files for GPIO | |
** - You need to learn how to clear breakpoints since Atollic TrueStudio will | |
** place them in random parts of your code at times. This will case debug | |
** to stop working. If you get this error: | |
** | |
** internal-error: cp_search_static_and_baseclasses | |
** A problem internal to GDB has been detected, | |
** further debugging may prove unreliable. | |
** | |
** Select Window > Show View > Other and search for the Breakpoints view. | |
** remove any random breakpoints from here (or just Remove all) | |
** - To read an analog input, you can't just do an analogRead(pin) as on | |
** Arduino based platforms. You need to define an analog pin in Cube MX, | |
** open the ADC setup, turn on an analog input, connect this to the pin, | |
** re-export and then you'll get the required files for the ADC. You then | |
** need to find yourself a working example to learn ho you use that. ST | |
** do actually have some PDF's explaining bits of this, but I was unable | |
** to find one specific for the stm32f0 series, just stm32f1 series. | |
** | |
**=========================================================================== | |
*/ | |
#include "main.h" | |
void SystemClock_Config(void); | |
static void MX_GPIO_Init(void); | |
GPIO_InitTypeDef GPIO_InitStructure; | |
int main(void) | |
{ | |
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ | |
HAL_Init(); | |
/* Configure the system clock */ | |
SystemClock_Config(); | |
/* Initialize all configured peripherals */ | |
MX_GPIO_Init(); | |
__HAL_RCC_ADC1_CLK_ENABLE(); | |
uint32_t i = 0; | |
int rez = 0; | |
while (1) | |
{ | |
rez = HAL_(GPIOA,GPIO_PIN_6); | |
if( rez ) | |
{ | |
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET); | |
} | |
else | |
{ | |
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET); | |
} | |
if(i%200==0) | |
{ | |
//HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_1); | |
} | |
i++; | |
} | |
/* 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 CPU, AHB and APB busses clocks | |
*/ | |
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 busses clocks | |
*/ | |
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK | |
|RCC_CLOCKTYPE_PCLK1; | |
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; | |
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | |
RCC_ClkInitStruct.APB1CLKDivider = 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}; | |
/* GPIO Ports Clock Enable */ | |
__HAL_RCC_GPIOA_CLK_ENABLE(); | |
/*Configure GPIO pin Output Level */ | |
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET); | |
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET); | |
/*Configure GPIO pin : PA1 */ | |
GPIO_InitStruct.Pin = GPIO_PIN_1; | |
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
GPIO_InitStruct.Pull = GPIO_NOPULL; | |
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | |
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
/*Configure GPIO pins : PA2 PA6 */ | |
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_6; | |
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | |
GPIO_InitStruct.Pull = GPIO_NOPULL; | |
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
/*Configure GPIO pins : PA5 PA7 */ | |
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7; | |
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | |
GPIO_InitStruct.Pull = GPIO_NOPULL; | |
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; | |
GPIO_InitStruct.Alternate = GPIO_AF0_SPI1; | |
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
/*Configure GPIO pins : PA9 PA10 */ | |
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10; | |
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | |
GPIO_InitStruct.Pull = GPIO_NOPULL; | |
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; | |
GPIO_InitStruct.Alternate = GPIO_AF1_USART1; | |
HAL_GPIO_Init(GPIOA, &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 */ | |
/* 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(char *file, uint32_t line) | |
{ | |
/* USER CODE BEGIN 6 */ | |
/* User can add his own implementation to report the file name and line number, | |
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | |
/* USER CODE END 6 */ | |
} | |
#endif /* USE_FULL_ASSERT */ | |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment