Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- ******************************************************************************
- * @file main.c
- * @author Ac6
- * @version V1.0
- * @date 01-December-2013
- * @brief Default main function.
- ******************************************************************************
- */
- #include "stm32l0xx.h"
- #include "flash_if.h"
- #include "stm32l0xx_nucleo.h"
- /* UART handler declaration */
- UART_HandleTypeDef UartHandle;
- /* CRC handler declaration */
- CRC_HandleTypeDef CrcHandle;
- uint32_t vector_t[48];
- /* Private function prototypes -----------------------------------------------*/
- static void COM_Init(void);
- void SystemClock_Config(void);
- /**
- * @brief Interrupt vector table relocation
- * @param address: The original address in program memory
- * @retval None
- */
- void Relocate_NVIC(uint32_t address)
- {
- uint32_t i;
- /* It is important to make sure the vector table stays put when playing with memory mapping */
- for (i = 0;i < 48;i++)
- {
- vector_t[i] = *((uint32_t*)(address + (i << 2)));
- }
- SCB->VTOR = (uint32_t)vector_t;
- }
- void Serial_PutString(uint8_t *p_string)
- {
- uint16_t length = 0;
- while (p_string[length] != '\0')
- {
- length++;
- }
- HAL_UART_Transmit(&UartHandle, p_string, length, 100);
- }
- int main(void)
- {
- /* Relocate vector table to RAM for safer context switch later */
- Relocate_NVIC(NVIC_VT_FLASH_B1);
- __HAL_RCC_SYSCFG_CLK_ENABLE();
- /* STM32L0xx HAL library initialization:
- */
- HAL_Init();
- /* Configure the system clock to 32 MHz */
- SystemClock_Config();
- /* Initialization of the UART driver */
- COM_Init();
- while(1){
- Serial_PutString((uint8_t *)"Waiting for the file to be sent ... (press 'a' to abort)\n\r");
- }
- }
- void SystemClock_Config(void)
- {
- RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
- RCC_OscInitTypeDef RCC_OscInitStruct = {0};
- /* Enable Power Control clock */
- __HAL_RCC_PWR_CLK_ENABLE();
- /* The voltage scaling allows optimizing the power consumption when the device is
- clocked below the maximum system frequency, to update the voltage scaling value
- regarding system frequency refer to product datasheet. */
- __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
- /* Disable Power Control clock */
- __HAL_RCC_PWR_CLK_DISABLE();
- /* Enable HSE Oscillator */
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
- RCC_OscInitStruct.HSEState = RCC_HSE_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_8;
- RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2;
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
- {
- /* Initialization Error */
- while (1)
- {}
- }
- /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
- clocks dividers */
- RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- 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_1) != HAL_OK)
- {
- /* Initialization Error */
- while (1)
- {}
- }
- }
- void COM_Init(void)
- {
- /* UART configured as follow:
- - BaudRate = 115200 baud
- - Word Length = 8 Bits
- - One Stop Bit
- - No parity
- - Hardware flow control disabled (RTS and CTS signals)
- - Receive and transmit enabled
- */
- UartHandle.Instance = USART1;
- UartHandle.Init.BaudRate = 115200;
- UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
- UartHandle.Init.StopBits = UART_STOPBITS_1;
- UartHandle.Init.Parity = UART_PARITY_NONE;
- UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- UartHandle.Init.Mode = UART_MODE_TX_RX;
- __HAL_RCC_CRC_CLK_ENABLE();
- /* CRC configured */
- CrcHandle.Instance = CRC;
- /* The CRC-16-CCIT polynomial is used */
- CrcHandle.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_DISABLE;
- CrcHandle.Init.GeneratingPolynomial = 0x1021;
- CrcHandle.Init.CRCLength = CRC_POLYLENGTH_16B;
- /* The zero init value is used */
- CrcHandle.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_DISABLE;
- CrcHandle.Init.InitValue = 0;
- /* The input data are not inverted */
- CrcHandle.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;
- /* The output data are not inverted */
- CrcHandle.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;
- /* The input data are 32-bit long words */
- CrcHandle.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;
- if (HAL_CRC_Init(&CrcHandle) != HAL_OK)
- {
- /* Initialization Error */
- while (1)
- {}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement