Mercurial > stm32test
changeset 0:2e46e1862fa9 default tip
initial
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Wed, 28 Jan 2015 20:39:25 +0100 |
| parents | |
| children | |
| files | .hgignore Makefile common.h main.c openocd.cfg stm32f103.ld timers.c timers.h |
| diffstat | 8 files changed, 192 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Wed Jan 28 20:39:25 2015 +0100 @@ -0,0 +1,5 @@ +syntax: glob +*~ +.*.swp +*.DS_Store +*.o
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Wed Jan 28 20:39:25 2015 +0100 @@ -0,0 +1,2 @@ +all: + arm-none-eabi-gcc -v -Tstm32f103.ld -I STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport/ -I STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/ -I STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc/ main.c -o main.o STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport/*.c STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/*.c STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/src/*.c timers.c -mcpu=cortex-m3 -mthumb -nostartfiles -Wl,-Map=main.map -o main.bin
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common.h Wed Jan 28 20:39:25 2015 +0100 @@ -0,0 +1,23 @@ +/* + * common.h + * + * Created on: 2011-07-03 + * Author: michoo + */ + +#ifndef COMMON_H_ +#define COMMON_H_ + +#include "stm32f10x.h" +#include <stdlib.h> +#include <core_cm3.h> + +#ifdef __cplusplus + #define EXTERN_C extern "C" +#else + #define EXTERN_C +#endif //__cplusplus + +#define IRQ(name) EXTERN_C void name##_Handler(void) + +#endif /* COMMON_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.c Wed Jan 28 20:39:25 2015 +0100 @@ -0,0 +1,67 @@ +#include <stm32f10x.h> +#include "timers.h" +//#include <string.h> +//#include <cmath> +#include <stdlib.h> +#include <core_cm3.h> +#include <stm32f10x_rcc.h> +#include <stm32f10x_rtc.h> +#include <stm32f10x_bkp.h> +#include <stm32f10x_adc.h> +#include <stm32f10x_dac.h> +#include <stm32f10x_usart.h> +#include <stm32f10x_gpio.h> +#include <stm32f10x_spi.h> +//#include "rfm73.h" + + +void resetup_clock(){ + RCC_PLLCmd(DISABLE); + RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_6); + RCC_PLLCmd(ENABLE); + do{} while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)!=SET); + RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1, ENABLE); + SystemCoreClockUpdate(); +} +void setup_led_out(){ + GPIO_InitTypeDef gpioParams; + GPIO_StructInit(&gpioParams); + gpioParams.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_1|GPIO_Pin_10|GPIO_Pin_12; + gpioParams.GPIO_Mode=GPIO_Mode_Out_PP; + GPIO_Init(GPIOB, &gpioParams); + GPIO_SetBits(GPIOB, GPIO_Pin_1); + GPIO_ResetBits(GPIOB, GPIO_Pin_2); + GPIO_ResetBits(GPIOB, GPIO_Pin_2); + GPIO_SetBits(GPIOB, GPIO_Pin_10); + GPIO_SetBits(GPIOB, GPIO_Pin_12); + + +} + + +int main(int argc, char *argv[]) { + GPIO_InitTypeDef gpioParams; + + resetup_clock(); + setup_led_out(); + SetupTimeTicksCounter(); + while(1){ + GPIO_SetBits(GPIOB, GPIO_Pin_1); + GPIO_ResetBits(GPIOB, GPIO_Pin_10); + GPIO_StructInit(&gpioParams); + gpioParams.GPIO_Pin=GPIO_Pin_1; + gpioParams.GPIO_Mode=GPIO_Mode_Out_PP; + gpioParams.GPIO_Speed=GPIO_Speed_50MHz; + GPIO_Init(GPIOA, &gpioParams); + sleep(100); + GPIO_StructInit(&gpioParams); + gpioParams.GPIO_Pin=GPIO_Pin_1; + gpioParams.GPIO_Mode=GPIO_Mode_IN_FLOATING; + gpioParams.GPIO_Speed=GPIO_Speed_50MHz; + GPIO_Init(GPIOA, &gpioParams); + GPIO_ResetBits(GPIOB, GPIO_Pin_1); + GPIO_SetBits(GPIOB, GPIO_Pin_10); + sleep(100); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openocd.cfg Wed Jan 28 20:39:25 2015 +0100 @@ -0,0 +1,11 @@ +interface hla +hla_layout stlink +hla_device_desc "ST-LINK/V2" +hla_vid_pid 0x0483 0x3748 + +#source [find target/stm32f1x_stlink.cfg] + +adapter_khz 4000 +transport select hla_swd +source [find target/stm32f1x.cfg] +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stm32f103.ld Wed Jan 28 20:39:25 2015 +0100 @@ -0,0 +1,35 @@ +ENTRY(main) +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 128K + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 20K +} + +SECTIONS +{ + .text : + { + KEEP(*(.isr_vector)) + *(.text) + *(.text.*) + *(.rodata) + _sidata = .; +} >FLASH + +/* Initialized data will initially be loaded in FLASH at the end of the .text section. */ +.data : AT (_sidata) +{ + _sdata = .; + *(.data) /* Initialized data */ + _edata = .; +} >RAM + +.bss : { + _sbss = .; + *(.bss) /* Zero-filled run time allocate data memory */ + _ebss = .; +} >RAM + +_estack = ORIGIN(RAM) + LENGTH(RAM); + } +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/timers.c Wed Jan 28 20:39:25 2015 +0100 @@ -0,0 +1,18 @@ +/* + * timers.c + * + * Created on: 2011-07-03 + * Author: michoo + */ +#include "timers.h" + +volatile uint32_t msTicks; +IRQ(SysTick){ + msTicks++; /* increment timeTicks counter */ +} + +void SetupTimeTicksCounter(){ + if (SysTick_Config (SystemCoreClock / 1000)) { /* Setup SysTick for 1 msec interrupts */ + for(;;); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/timers.h Wed Jan 28 20:39:25 2015 +0100 @@ -0,0 +1,31 @@ +/* + * timers.h + * + * Created on: 2011-07-03 + * Author: michoo + */ + +#ifndef TIMERS_H_ +#define TIMERS_H_ + +#include "common.h" + +/* timeTicks counter */ +extern volatile uint32_t msTicks; + +/* wait for dlyTicks ms */ +inline static void sleep(uint32_t dlyTicks) { + uint32_t curTicks = msTicks; + + while ((msTicks - curTicks) < dlyTicks); +} + +/* setups 1000 ticks/s */ +EXTERN_C void SetupTimeTicksCounter(); + +/*volatile struct{ + uint16_t ms; + uint16_t s; +} sysTime_t;*/ + +#endif /* TIMERS_H_ */
