From 9de793750f91d6cdccc07f675661743e3ccd04a4 Mon Sep 17 00:00:00 2001 From: key Date: Sun, 12 Jun 2022 11:31:50 +0200 Subject: [PATCH] working compilation and programming process for stm both with main.c or main.cpp --- ked/CMakeLists.txt | 2 +- ked/run.sh | 2 +- main.c | 90 +++++++++++++++++++++++++--------------------- main.cpp | 2 +- 4 files changed, 53 insertions(+), 43 deletions(-) diff --git a/ked/CMakeLists.txt b/ked/CMakeLists.txt index 55309ba..3d198e8 100644 --- a/ked/CMakeLists.txt +++ b/ked/CMakeLists.txt @@ -42,7 +42,7 @@ message("${Blue} |--> Libs used\t\t: ${EXTRA_LIBS} ${ColourReset}") #################################################################################################### #EXECUTABLE #################################################################################################### -add_executable(${EXECUTABLE} ../main.cpp) +add_executable(${EXECUTABLE} ../main.c) target_compile_options(${EXECUTABLE} PRIVATE ${MAIN_FLAGS}) target_compile_definitions(${EXECUTABLE} PRIVATE ${MAIN_DEFS}) target_include_directories(${EXECUTABLE} PUBLIC ${MAIN_INCLUDES}) diff --git a/ked/run.sh b/ked/run.sh index cfe32d3..b40944a 100755 --- a/ked/run.sh +++ b/ked/run.sh @@ -44,7 +44,7 @@ else echo -e "\e[32m" fi - if [ "$CSL_TO_USE" == "nucleo_f042k6" ];then + if [ "$CSL_TO_USE" == "stm32f042" ];then echo -e "\e[36m" echo "+--------------------------------------+" echo -e "\tFlashing $CSL_TO_USE" diff --git a/main.c b/main.c index 9646e2c..4afbfe9 100644 --- a/main.c +++ b/main.c @@ -5,22 +5,53 @@ #include "ascii.h" #include "timer.h" -int main(int argc, char *argv[]) +void timer_test(timerNo_t timer, pinNo_t pin) { - uint8_t i = 0; - uint8_t a = '0'; - - delayInitMs(8000000, 1000); - timerActivateBus(timer_2); - timerSetPrescaler(timer_2,159999); - timerSetAutoReload(timer_2,999999); - timerClearCounter(timer_2); - timerEnableTimer(timer_2); + timerInitCounter(timer, 4000, 999, downCounting); + timerSart(timer); + + for(int i = 0; i < 10 ; i++) + { + while(!timerGetUpdateInterrupt(timer)); + timerClearUpdateInterrupt(timer); + pinToggle(pin); + } + pinWrite(pin,0); +} + +void timer_capture_compare_test(timerNo_t timer) +{ + uint16_t i = 0; + timerInitCounter(timer, 100, 99, downCounting); + // We use pin PA3 (Arduino header A2) + //timerInitOutputCompare(timer, toggle, 4, pinA3, 2,0, 300); + timerInitOutputCompare(timer, pwm_normal, 2, pinB3, 2,0, 900); + timerSart(timer); + + while(1){ + delayMs(200); + timerSetCounterCompareValue(timer, 2, i); + i += 10; + if(i>99) i = 0; + } +} + + +int main(int argc, char *argv[]) +{ + uint8_t i = 0; + // making array with all available timers + timerNo_t timers[MAX_TIMER_CHANNEL_COUNT] = {timer_1, timer_2, timer_3, timer_14, timer_16, timer_17}; + + delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library + + pinConfig(pinB3, output, pushPull, def_res, def_speed); pinConfig(pinA0, input, def_stage, pullDown, def_speed); - + + setupInit(); // This is the sescond call of System init the assebly start code is calling it before the main. usartInit( usart2, pinA2, pinA15, @@ -31,7 +62,7 @@ int main(int argc, char *argv[]) //clears screen and send the wellcome messgae print_Usart(usart2, ASCII_clear); - print_Usart(usart2, "Wellcome to our KED project\n\r"); + print_Usart(usart2, "HEllooo to our KED project\n\r"); //blinks 10 times to indicate the sicsessfull init if the device @@ -43,36 +74,15 @@ int main(int argc, char *argv[]) } pinWrite(pinB3,0); - + + timer_capture_compare_test(timer_2); + print_Usart(usart2, "All is working fine \r\n"); + while(1) { - while(!(TIM2->SR & 1)); - TIM2->SR &=~ 1; - pinToggle(pinB3); - /* - //USART will rteturn what wou type and trun led on if you press "1" - a = usartGetChar(usart2); - usartSendChar(usart2, a); - if(a == '1') - { - pinWrite(pinB3,1); - } - else - { - pinWrite(pinB3,0); - } - - //test if the gpio port works as an input - if(pinRead(pinA0)) - { - pinWrite(pinB3,1); - } - else - { - pinWrite(pinB3,0); - } - delayMs(10); - */ } + return 1; } + + diff --git a/main.cpp b/main.cpp index 4ecb0df..1a9f936 100644 --- a/main.cpp +++ b/main.cpp @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) pinWrite(pinB3,0); - timer_capture_compare_test(timer_2); + //timer_capture_compare_test(timer_2); print_Usart(usart2, const_cast("All is working fine \r\n")); while(1)