From 61bd8c76327920a8e9896b1555825b15c70965b3 Mon Sep 17 00:00:00 2001 From: Attila BODY Date: Sat, 15 Dec 2018 10:32:53 +0100 Subject: [PATCH] (mostly) assembly timings --- .cproject | 334 ++++++++++++++++++------------------ .mxproject | 4 +- NeoPixelF103MVP Release.cfg | 28 +++ NeoPixelF103MVP.ioc | 3 + Src/gpio.c | 2 +- Src/main.c | 90 ++++++++-- 6 files changed, 275 insertions(+), 186 deletions(-) create mode 100644 NeoPixelF103MVP Release.cfg diff --git a/.cproject b/.cproject index f0248b5..1ff2b9a 100644 --- a/.cproject +++ b/.cproject @@ -1,261 +1,261 @@ - + - + - - - - - - + + + + + + - - - - - + + + + - + - + - - - - - - + + + + + + - - - - - + + + + - + - + - + - + - + - + - + diff --git a/.mxproject b/.mxproject index ce3dcb2..b3484dd 100644 --- a/.mxproject +++ b/.mxproject @@ -1,8 +1,8 @@ [PreviousGenFiles] HeaderPath=/home/abody/work/private/NeoPixelF103MVP/Inc -HeaderFiles=gpio.h;stm32f1xx_it.h;stm32_assert.h;stm32f1xx_hal_conf.h;main.h; +HeaderFiles=gpio.h;stm32f1xx_it.h;stm32_assert.h;stm32f1xx_hal_conf.h;main.h;spi.h; SourcePath=/home/abody/work/private/NeoPixelF103MVP/Src -SourceFiles=gpio.c;stm32f1xx_it.c;main.c; +SourceFiles=gpio.c;stm32f1xx_it.c;main.c;spi.c;stm32f1xx_hal_msp.c; [PreviousLibFiles] LibFiles=Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_system.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_exti.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_bus.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_utils.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_dma.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_exti.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_utils.c;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Drivers/CMSIS/Include/arm_common_tables.h;Drivers/CMSIS/Include/arm_const_structs.h;Drivers/CMSIS/Include/arm_math.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/cmsis_armcc_V6.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_cmFunc.h;Drivers/CMSIS/Include/core_cmInstr.h;Drivers/CMSIS/Include/core_cmSimd.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_sc300.h; diff --git a/NeoPixelF103MVP Release.cfg b/NeoPixelF103MVP Release.cfg new file mode 100644 index 0000000..d815a00 --- /dev/null +++ b/NeoPixelF103MVP Release.cfg @@ -0,0 +1,28 @@ +# This is an NeoPixelF103MVP board with a single STM32F103C8Tx chip +# +# Generated by System Workbench for STM32 +# Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s) + +source [find interface/stlink.cfg] + +set WORKAREASIZE 0x5000 + +transport select "hla_swd" + +set CHIPNAME STM32F103C8Tx +set BOARDNAME NeoPixelF103MVP + +# Enable debug when in low power modes +set ENABLE_LOW_POWER 1 + +# Stop Watchdog counters when halt +set STOP_WATCHDOG 1 + +# STlink Debug clock frequency +set CLOCK_FREQ 4000 + +# use software system reset +reset_config none +set CONNECT_UNDER_RESET 0 + +source [find target/stm32f1x.cfg] diff --git a/NeoPixelF103MVP.ioc b/NeoPixelF103MVP.ioc index 2bad45f..f509b2b 100644 --- a/NeoPixelF103MVP.ioc +++ b/NeoPixelF103MVP.ioc @@ -37,7 +37,10 @@ PA13.Mode=Serial_Wire PA13.Signal=SYS_JTMS-SWDIO PA14.Mode=Serial_Wire PA14.Signal=SYS_JTCK-SWCLK +PB11.GPIOParameters=GPIO_Speed,PinState +PB11.GPIO_Speed=GPIO_SPEED_FREQ_HIGH PB11.Locked=true +PB11.PinState=GPIO_PIN_RESET PB11.Signal=GPIO_Output PC13-TAMPER-RTC.Locked=true PC13-TAMPER-RTC.Signal=GPIO_Output diff --git a/Src/gpio.c b/Src/gpio.c index 05d7887..8e2f442 100644 --- a/Src/gpio.c +++ b/Src/gpio.c @@ -84,7 +84,7 @@ void MX_GPIO_Init(void) /**/ GPIO_InitStruct.Pin = LL_GPIO_PIN_11; GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; - GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; LL_GPIO_Init(GPIOB, &GPIO_InitStruct); diff --git a/Src/main.c b/Src/main.c index c8f275c..cc75153 100644 --- a/Src/main.c +++ b/Src/main.c @@ -99,42 +99,100 @@ int main(void) /* Infinite loop */ /* USER CODE BEGIN WHILE */ + asm volatile( + " movs r3, #1000 \n\t" + "1: subs r3, #1 \n\t" + " bne 1b \n\t" + : : : "r3", "cc" + ); + + asm volatile("\tmovs r3, #1000\n1:\tsubs r3, #1\n\tbne 1b\n\t" : : : "r3", "cc"); + GPIOB->ODR = 0; volatile uint32_t v; - uint8_t ledbytes[] = {0x0f, 0xf0, 0}; + uint8_t ledbytes[] = {0, 0xff, 0, 0xff, 0x55, 0xaa}; __disable_irq(); +#define W_1f 5 +#define W_0f 0 +#define W_0s 3 + +#define W_1af +#define W_1as ++v; ++v +#define W_0af ++v; ++v +#define W_0as ++v; ++v +/* +#define SHIFTBIT(x) \ + if(b&(1<BSRR = (1 << 11); \ + for( v=W_1f; v != 0; --v); \ + W_1af; \ + GPIOB->BSRR = (1 << (16+11)); \ + W_1as; \ + } else { \ + GPIOB->BSRR = (1 << 11); \ + for( v=W_0f; v != 0; --v); \ + W_0af; \ + GPIOB->BSRR = (1 << (16+11)); \ + for( v=W_0s; v != 0; --v); \ + W_0as; \ + } +*/ +#define SHIFTBIT(x) \ + if(b&(1<BSRR = (1 << 11); \ + asm volatile("\tmov r3, #10\n1:\tsubs r3, #1\n\tbne 1b\n\t" : : : "r3", "cc"); \ + GPIOB->BSRR = (1 << (16+11)); \ + asm volatile("\tmov r3, #03\n1:\tsubs r3, #1\n\tbne 1b\n\t" : : : "r3", "cc"); \ + } else { \ + GPIOB->BSRR = (1 << 11); \ + asm volatile("\tmov r3, #03\n1:\tsubs r3, #1\n\tbne 1b\n\t" : : : "r3", "cc"); \ + GPIOB->BSRR = (1 << (16+11)); \ + asm volatile("\tmov r3, #10\n1:\tsubs r3, #1\n\tbne 1b\n\t" : : : "r3", "cc"); \ + } + +__disable_irq(); + while(1) { - uint32_t *bitPtr = BITBAND_RAM(ledbytes, 0); - uint32_t cnt = sizeof(ledbytes)*8 + 1; + uint8_t *bufPtr = ledbytes; + uint32_t cnt = sizeof(ledbytes) + 1; while(--cnt) { + uint32_t b = *bufPtr++; + SHIFTBIT(7); + SHIFTBIT(6); + SHIFTBIT(5); + SHIFTBIT(4); + SHIFTBIT(3); + SHIFTBIT(2); + SHIFTBIT(1); - if(*bitPtr++) { - GPIOB->BSRR = 1 << 11; //set - for( v=5; v != 0; --v); //long - GPIOB->BSRR = 1 << (16+11); //clear - ++v; ++v; //short + if(b&1) { + GPIOB->BSRR = 1 << 11; + for( v=W_1f; v != 0; --v); + W_1af; + GPIOB->BSRR = 1 << (16+11); + W_1as; } else { - GPIOB->BSRR = 1 << 11; //set - for( v=0; v != 0; --v); //short - ++v;++v; - GPIOB->BSRR = 1 << (16+11); //clear - for( v=3; v != 0; --v); //long - ++v; ++v; + GPIOB->BSRR = 1 << 11; + for( v=W_0f; v != 0; --v); + W_0af; + GPIOB->BSRR = 1 << (16+11); + for( v=W_0s; v != 0; --v); + ++v; v=0; } } /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ - for( v=400; v != 0; --v); //long + for( v=100; v != 0; --v); //long } /* USER CODE END 3 */ -} +} static void LL_Init(void) {