working compilation and programming process for stm both with main.c or main.cpp

interrupts
key 3 years ago
parent 967d132301
commit 9de793750f

@ -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})

@ -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"

@ -5,22 +5,53 @@
#include "ascii.h"
#include "timer.h"
void timer_test(timerNo_t timer, pinNo_t pin)
{
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;
uint8_t a = '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);
delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library
timerActivateBus(timer_2);
timerSetPrescaler(timer_2,159999);
timerSetAutoReload(timer_2,999999);
timerClearCounter(timer_2);
timerEnableTimer(timer_2);
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
@ -44,35 +75,14 @@ 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;
}

@ -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<char *>("All is working fine \r\n"));
while(1)

Loading…
Cancel
Save