#include #include #include "FreeRTOS.h" #include "task.h" #include "queue.h" #include "io/io_base.h" #include "fatfs_glue.h" #include "malloc_glue.h" #include "cli_task.h" #include "gsm_task.h" #include "syslog.h" #include "stm32f10x.h" static void hardwareSetup() { SCB->VTOR = 0x08000000; // Interrupt vector table in flash SCB->AIRCR = SCB_AIRCR_REALLY_WRITE | SCB_AIRCR_PRIGROUP3; // 4 bit priority RCC->CFGR = RCC_CFGR_PLLMULL_0 | RCC_CFGR_PLLSRC; // PLL 3x RCC->CR |= RCC_CR_PLLON | RCC_CR_HSEON; // HSE, PLL on while (!(RCC->CR & RCC_CR_PLLRDY) || !(RCC->CR & RCC_CR_HSIRDY)); // Wait for PLL RCC->CFGR |= RCC_CFGR_SW_PLL; // Switch clock RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPBEN; GPIOC->CRH = 0x11; // leds GPIOC->CRL = 0x00000011; // ultrasound GPIOA->CRL = 0x00004904; // USART2 pins /*GPIOC->CRLb.IO0 = GPIO_OUT_10; // ultrasound GPIOA->CRLb.IO0 = GPIO_HIGHZ_INPUT; // Button GPIOA->CRLb.IO2 = GPIO_AFOUT_10; // USART2 pins GPIOA->CRLb.IO3 = GPIO_HIGHZ_INPUT; // USART2 pins*/ GPIOA->CRH = 0x00000490; // USART1 pins RCC->APB2ENR |= RCC_APB2ENR_SPI1EN | RCC_APB2ENR_AFIOEN; AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE | AFIO_MAPR_SPI1_REMAP; GPIOB->CRL = 0x11989000; // SD pins SPI1->CR1 = SPI_CR1_SPE | (0 << 3) | SPI_CR1_MSTR | SPI_CR1_SSM | SPI_CR1_SSI; GPIOB->BSRR = (1 << 5); // Pull-up GPIOB->BSRR = (1 << 7) | (1 << 6); // Chip unselect RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; ADC1->CR2 |= ADC_CR2_ADON; ADC1->SQR1 = 0; // 1 channel ADC1->SQR3 = 12; // Channel number // ADC DMA RCC->AHBENR |= RCC_AHBENR_DMA1EN; DMA1_Channel1->CCR = (1 << 10) | (1 << 8) | DMA_CCR1_MINC; RCC->APB1ENR |= RCC_APB1ENR_TIM6EN; } int main( void ) { hardwareSetup(); io_init(); fatfs_init(); syslog_init(); xTaskCreate( CLI_task, (const signed char*)"CLI", ( unsigned short )200, NULL, tskIDLE_PRIORITY + 1, NULL ); xTaskCreate( syslog_task, (const signed char*)"LOG", ( unsigned short )200, NULL, tskIDLE_PRIORITY, NULL ); xTaskCreate( GSM_task, (const signed char*)"GSM", ( unsigned short )400, NULL, tskIDLE_PRIORITY + 1, NULL ); // Enable malloc locking malloc_init(); /* Start the scheduler. */ vTaskStartScheduler(); /* Will only get here if there was insufficient memory to create the idle task. The idle task is created within vTaskStartScheduler(). */ GPIOC->BSRR |= (1<<8); for( ;; ); }