summaryrefslogtreecommitdiff
path: root/project/Core/Src
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-10-01 23:38:18 -0400
committersowgro <tpoke.ferrari@gmail.com>2025-10-01 23:38:18 -0400
commite2ba305068f3045944789bf65e29fb2f2f557879 (patch)
treec78a70b4e2641270f0804965b84dcddae38af4c0 /project/Core/Src
parente50a487f58941c49cace0783f80a3d4dc6de3c2a (diff)
download340-repo-Sowgro-e2ba305068f3045944789bf65e29fb2f2f557879.tar.gz
340-repo-Sowgro-e2ba305068f3045944789bf65e29fb2f2f557879.tar.bz2
340-repo-Sowgro-e2ba305068f3045944789bf65e29fb2f2f557879.zip
complete homework 4
Diffstat (limited to 'project/Core/Src')
-rw-r--r--project/Core/Src/Activties/activity6.c12
-rw-r--r--project/Core/Src/System/systick.c16
-rw-r--r--project/Core/Src/adc_dac_demo.c1
-rw-r--r--project/Core/Src/demo.c19
-rw-r--r--project/Core/Src/main.c13
5 files changed, 32 insertions, 29 deletions
diff --git a/project/Core/Src/Activties/activity6.c b/project/Core/Src/Activties/activity6.c
index 53f8bb0..da7bac8 100644
--- a/project/Core/Src/Activties/activity6.c
+++ b/project/Core/Src/Activties/activity6.c
@@ -5,19 +5,13 @@
* Author: sowgro
*/
-#include <stdint.h>
#include <stdio.h>
+#include "systick.h"
-typedef struct {
- uint32_t CSR;
- uint32_t RVR;
- uint32_t CVR;
- uint32_t CALIB;
-} sys_tick;
-
+// moved struct to systick.h
void activity6_run() {
- sys_tick *s = (sys_tick *) 0xE000E010;
+ systick_t *s = (systick_t *) 0xE000E010;
printf("%lu\r\n", s->CVR);
s->RVR = 8000000;
diff --git a/project/Core/Src/System/systick.c b/project/Core/Src/System/systick.c
index 263defd..58ee2b1 100644
--- a/project/Core/Src/System/systick.c
+++ b/project/Core/Src/System/systick.c
@@ -1,5 +1,9 @@
#include "systick.h"
+systick_t *get_systick() {
+ return (systick_t *) 0xE000E010;
+}
+
// This function is to Initialize SysTick registers
void init_systick()
{
@@ -10,6 +14,12 @@ void init_systick()
// Set the LOAD (RVR) to 8 million to give us a 100 milliseconds timer.
// Set the clock source bit in the CTRL (CSR) to the internal clock.
// Set the enable bit in the CTRL (CSR) to start the timer.
+ systick_t *s = get_systick();
+
+ s->CSR = 0;
+ s->RVR = 8000000;
+ s->CSR |= 1<<2;
+ s->CSR |= 1;
}
// This fuction is to create delay using SysTick timer counter
@@ -20,4 +30,10 @@ void delay_systick()
// Inside that for loop check the COUNTFLAG bit in the CTRL (CSR)
// register in a loop. When that bit is set exit this inner loop
// to do another pass in the outer loop of 10.
+ systick_t *s = get_systick();
+
+ for (int i = 0; i < 10; i++) {
+ while (~s->CSR & (1<<16))
+ ;
+ }
}
diff --git a/project/Core/Src/adc_dac_demo.c b/project/Core/Src/adc_dac_demo.c
index 5deff83..46b10f5 100644
--- a/project/Core/Src/adc_dac_demo.c
+++ b/project/Core/Src/adc_dac_demo.c
@@ -8,6 +8,7 @@
#include "adc.h"
#include "dac.h"
#include "adc_demo.h"
+#include "systick.h"
uint8_t one_second_elapsed = FALSE;
uint32_t counter = 0;
diff --git a/project/Core/Src/demo.c b/project/Core/Src/demo.c
index d34b7e3..fed34e3 100644
--- a/project/Core/Src/demo.c
+++ b/project/Core/Src/demo.c
@@ -15,15 +15,16 @@
#include "UART.h"
#include "demo.h"
#include "stm32l4xx.h"
+#include "systick.h"
// This function is to create a delay by consuming CPU cycle on counter
-static void delay_loop( int value )
-{
- // spin loop consuming CPU to spend time.
- for (int i = 0; i < value; i++)
- ;
-}
+//static void delay_loop( int value )
+//{
+// // spin loop consuming CPU to spend time.
+// for (int i = 0; i < value; i++)
+// ;
+//}
// This function is to print counter on UART port and toggle LED
static void demo_of_UART_print(int counter){
@@ -33,8 +34,10 @@ static void demo_of_UART_print(int counter){
n = sprintf((char *)buffer, "counter = %d\r\n", counter);
USART_Write(USART2, buffer, n);
- delay_loop( 8000000 ) ; // comment this out when you are ready to test delay_systick
- // delay_systick() ; // enable this when you are ready to test
+ // delay_loop( 8000000 ) ; // comment this out when you are ready to test delay_systick
+ init_systick();
+ delay_systick(); // enable this when you are ready to test
+ delay_systick();
// Toggle LED
LED_Toggle();
diff --git a/project/Core/Src/main.c b/project/Core/Src/main.c
index f447b8b..87939fd 100644
--- a/project/Core/Src/main.c
+++ b/project/Core/Src/main.c
@@ -8,10 +8,6 @@
#include "LED.h"
#include "UART.h"
#include "demo.h"
-#include "activity4.h"
-#include "activity5.h"
-#include "activity6.h"
-#include "activity7.h"
#include <stdio.h>
int main(void){
@@ -21,14 +17,7 @@ int main(void){
LED_Init();
UART2_Init();
-// printf("Hello world \r\n");
-
-// activity4_run();
-// activity5_run();
-// activity6_run();
- activity7_run();
-
// application run function
-// run_demo() ;
+ run_demo();
}