From bccacd0a217d582930470a63d1eab3548e40225e Mon Sep 17 00:00:00 2001 From: AntonJ Date: Tue, 4 Mar 2025 18:32:18 +0200 Subject: [PATCH 1/5] Fixed comments --- lab3/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lab3/main.c b/lab3/main.c index 14a1d18..30573f8 100644 --- a/lab3/main.c +++ b/lab3/main.c @@ -10,7 +10,7 @@ #include "inc/msp432p401r.h" void DebugDump(uint8_t bump, uint8_t line) { - // write this as part of Lab 10 + // write this as part of Lab 3 } // **************SysTick_Init********************* @@ -30,7 +30,7 @@ void SysTickInit(uint32_t period, uint32_t priority) { } void SysTick_Handler(void) { // every 1ms - // write this as part of Lab 10 + // write this as part of Lab 3 } int main(void) { From c41f3b0d5f097354fd82390d5a7c4e9c32ffc0c7 Mon Sep 17 00:00:00 2001 From: AntonJ Date: Thu, 6 Mar 2025 15:59:11 +0200 Subject: [PATCH 2/5] Fixed Makefile dirname: missing operand and implementation warnings --- lab1/Makefile | 13 +++++++++++-- lab2/Makefile | 13 +++++++++++-- lab3/Makefile | 13 +++++++++++-- syscalls.c | 17 +++++++++++++++++ 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 syscalls.c diff --git a/lab1/Makefile b/lab1/Makefile index 12a7431..9385d8e 100644 --- a/lab1/Makefile +++ b/lab1/Makefile @@ -3,9 +3,14 @@ CC = arm-none-eabi-gcc # The location of the C compiler # ARMGCC_ROOT is used by some makefiles that need to know where the compiler # is installed. -ARMGCC_ROOT := ${shell dirname ${shell readlink ${shell which ${CC}}}}/.. +ARMGCC_BIN := ${shell which ${CC}} +ifeq (${shell test -h ${ARMGCC_BIN} && echo "true" || echo "false"}, true) + ARMGCC_ROOT := ${shell dirname ${shell readlink ${ARMGCC_BIN}}}/.. +else + ARMGCC_ROOT := ${shell dirname ${ARMGCC_BIN}}/.. +endif -OBJECTS = main.o system.o startup.o +OBJECTS = main.o system.o startup.o syscalls.o NAME = lab @@ -40,6 +45,7 @@ LFLAGS = -Wl,-T,../config.lds \ --specs=nano.specs all: $(NAME).out + @echo "SUCCESS: Compilation completed successfully." main.o: main.c @$(CC) $(CFLAGS) -g $< -c -o $@ @@ -50,6 +56,9 @@ system.o: ../system.c startup.o: ../startup.c @$(CC) $(CFLAGS) $< -c -o $@ +syscalls.o: ../syscalls.c + @$(CC) $(CFLAGS) $< -c -o $@ + $(NAME).out: $(OBJECTS) @$(CC) $(OBJECTS) $(LFLAGS) -o $(NAME).out diff --git a/lab2/Makefile b/lab2/Makefile index 06c5834..1a68222 100644 --- a/lab2/Makefile +++ b/lab2/Makefile @@ -3,9 +3,14 @@ CC = arm-none-eabi-gcc # The location of the C compiler # ARMGCC_ROOT is used by some makefiles that need to know where the compiler # is installed. -ARMGCC_ROOT := ${shell dirname ${shell readlink ${shell which ${CC}}}}/.. +ARMGCC_BIN := ${shell which ${CC}} +ifeq (${shell test -h ${ARMGCC_BIN} && echo "true" || echo "false"}, true) + ARMGCC_ROOT := ${shell dirname ${shell readlink ${ARMGCC_BIN}}}/.. +else + ARMGCC_ROOT := ${shell dirname ${ARMGCC_BIN}}/.. +endif -OBJECTS = main.o bump.o delay.o clock.o system.o startup.o +OBJECTS = main.o bump.o delay.o clock.o system.o startup.o syscalls.o NAME = lab @@ -40,6 +45,7 @@ LFLAGS = -Wl,-T,../config.lds \ --specs=nano.specs all: $(NAME).out + @echo "SUCCESS: Compilation completed successfully." main.o: main.c @$(CC) $(CFLAGS) -g $< -c -o $@ @@ -59,6 +65,9 @@ system.o: ../system.c startup.o: ../startup.c @$(CC) $(CFLAGS) $< -c -o $@ +syscalls.o: ../syscalls.c + @$(CC) $(CFLAGS) $< -c -o $@ + $(NAME).out: $(OBJECTS) @$(CC) $(OBJECTS) $(LFLAGS) -o $(NAME).out diff --git a/lab3/Makefile b/lab3/Makefile index 8cd1e5a..7920501 100644 --- a/lab3/Makefile +++ b/lab3/Makefile @@ -3,9 +3,14 @@ CC = arm-none-eabi-gcc # The location of the C compiler # ARMGCC_ROOT is used by some makefiles that need to know where the compiler # is installed. -ARMGCC_ROOT := ${shell dirname ${shell readlink ${shell which ${CC}}}}/.. +ARMGCC_BIN := ${shell which ${CC}} +ifeq (${shell test -h ${ARMGCC_BIN} && echo "true" || echo "false"}, true) + ARMGCC_ROOT := ${shell dirname ${shell readlink ${ARMGCC_BIN}}}/.. +else + ARMGCC_ROOT := ${shell dirname ${ARMGCC_BIN}}/.. +endif -OBJECTS = main.o bump.o delay.o clock.o reflectance.o cpu.o system.o startup.o +OBJECTS = main.o bump.o delay.o clock.o reflectance.o cpu.o system.o startup.o syscalls.o NAME = lab @@ -40,6 +45,7 @@ LFLAGS = -Wl,-T,../config.lds \ --specs=nano.specs all: $(NAME).out + @echo "SUCCESS: Compilation completed successfully." main.o: main.c @$(CC) $(CFLAGS) -g $< -c -o $@ @@ -65,6 +71,9 @@ system.o: ../system.c startup.o: ../startup.c @$(CC) $(CFLAGS) $< -c -o $@ +syscalls.o: ../syscalls.c + @$(CC) $(CFLAGS) $< -c -o $@ + $(NAME).out: $(OBJECTS) @$(CC) $(OBJECTS) $(LFLAGS) -o $(NAME).out diff --git a/syscalls.c b/syscalls.c new file mode 100644 index 0000000..34c0d46 --- /dev/null +++ b/syscalls.c @@ -0,0 +1,17 @@ +// Minimal implementations to supress the warnings + +int _close(int file) { + return -1; +} + +int _lseek(int file, int ptr, int dir) { + return 0; +} + +int _read(int file, char *ptr, int len) { + return 0; +} + +int _write(int file, char *ptr, int len) { + return len; +} From 9aaca16baff25bc32fa87c175d7953f2027212e5 Mon Sep 17 00:00:00 2001 From: AntonJ Date: Thu, 24 Apr 2025 14:07:19 +0300 Subject: [PATCH 3/5] Better makefile object build recipe --- lab1/Makefile | 5 ++++- lab2/Makefile | 11 ++++------- lab3/Makefile | 16 +++++----------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lab1/Makefile b/lab1/Makefile index 9385d8e..4b14d1a 100644 --- a/lab1/Makefile +++ b/lab1/Makefile @@ -10,6 +10,9 @@ else ARMGCC_ROOT := ${shell dirname ${ARMGCC_BIN}}/.. endif +# Search for source files that are not in this directory +VPATH = ../common/ + OBJECTS = main.o system.o startup.o syscalls.o NAME = lab @@ -47,7 +50,7 @@ LFLAGS = -Wl,-T,../config.lds \ all: $(NAME).out @echo "SUCCESS: Compilation completed successfully." -main.o: main.c +%.o: %.c @$(CC) $(CFLAGS) -g $< -c -o $@ system.o: ../system.c diff --git a/lab2/Makefile b/lab2/Makefile index 1a68222..26f9be7 100644 --- a/lab2/Makefile +++ b/lab2/Makefile @@ -10,6 +10,9 @@ else ARMGCC_ROOT := ${shell dirname ${ARMGCC_BIN}}/.. endif +# Search for source files that are not in this directory +VPATH = ../common/ + OBJECTS = main.o bump.o delay.o clock.o system.o startup.o syscalls.o NAME = lab @@ -47,13 +50,7 @@ LFLAGS = -Wl,-T,../config.lds \ all: $(NAME).out @echo "SUCCESS: Compilation completed successfully." -main.o: main.c - @$(CC) $(CFLAGS) -g $< -c -o $@ - -bump.o: ../common/bump.c - @$(CC) $(CFLAGS) -g $< -c -o $@ - -delay.o: ../common/delay.c +%.o: %.c @$(CC) $(CFLAGS) -g $< -c -o $@ clock.o: ../common/clock.c diff --git a/lab3/Makefile b/lab3/Makefile index 7920501..7bc71d4 100644 --- a/lab3/Makefile +++ b/lab3/Makefile @@ -10,7 +10,10 @@ else ARMGCC_ROOT := ${shell dirname ${ARMGCC_BIN}}/.. endif -OBJECTS = main.o bump.o delay.o clock.o reflectance.o cpu.o system.o startup.o syscalls.o +# Search for source files that are not in this directory +VPATH = ../common/ + +OBJECTS = main.o bump.o delay.o reflectance.o clock.o cpu.o system.o startup.o syscalls.o NAME = lab @@ -47,21 +50,12 @@ LFLAGS = -Wl,-T,../config.lds \ all: $(NAME).out @echo "SUCCESS: Compilation completed successfully." -main.o: main.c - @$(CC) $(CFLAGS) -g $< -c -o $@ - -bump.o: ../common/bump.c - @$(CC) $(CFLAGS) -g $< -c -o $@ - -delay.o: ../common/delay.c +%.o: %.c @$(CC) $(CFLAGS) -g $< -c -o $@ clock.o: ../common/clock.c @$(CC) $(CFLAGS) $< -c -o $@ -reflectance.o: ../common/reflectance.c - @$(CC) $(CFLAGS) -g $< -c -o $@ - cpu.o: ../common/cpu.c @$(CC) $(CFLAGS) $< -c -o $@ From 8f8b21f19ce34e3192bce9c29507d2e17002940f Mon Sep 17 00:00:00 2001 From: AntonJ Date: Thu, 24 Apr 2025 14:10:52 +0300 Subject: [PATCH 4/5] Added Lab4 and necessary files in common/ --- common/motor_simple.c | 57 ++++++++++++++++++++++++++ common/motor_simple.h | 13 ++++++ common/systick.c | 18 +++++++++ common/systick.h | 10 +++++ lab4/Makefile | 74 ++++++++++++++++++++++++++++++++++ lab4/main.c | 93 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 265 insertions(+) create mode 100644 common/motor_simple.c create mode 100644 common/motor_simple.h create mode 100644 common/systick.c create mode 100644 common/systick.h create mode 100644 lab4/Makefile create mode 100644 lab4/main.c diff --git a/common/motor_simple.c b/common/motor_simple.c new file mode 100644 index 0000000..c513e35 --- /dev/null +++ b/common/motor_simple.c @@ -0,0 +1,57 @@ +#include +#include "motor_simple.h" + +#include "bump.h" +#include "systick.h" + +#include "inc/msp432p401r.h" + +// Left motor (PH) direction connected to P5.4 (J3.29) +// Left motor (EN) PWM connected to P2.7/TA0CCP4 (J4.40) +// Left motor (nSLEEP) enable connected to P3.7 (J4.31) + +// Right motor (PH) direction connected to P5.5 (J3.30) +// Right motor (EN) PWM connected to P2.6/TA0CCP3 (J4.39) +// Right motor (nSLEEP) enable connected to P3.6 (J2.11) + + +// Initializes the 6 GPIO output lines and puts driver to sleep +void MotorInit(void) { + // write this code +} + +// Stops both motors, puts driver to sleep +void MotorStop(void) { + P2->OUT &= ~0xC0; // off + P3->OUT &= ~0xC0; // low current sleep mode +} + +// Drives both motors forward at duty (100 to 9900) +// Runs for time duration, and then stops +// Stop the motors and return if any bumper switch is active +void MotorForward(uint16_t duty, uint32_t times_10ms) { + // write this code +} + +// Drives both motors backward at duty (100 to 9900) +// Runs for time duration, and then stops +// Runs even if any bumper switch is active +void MotorBackward(uint16_t duty, uint32_t times_10ms) { + // write this code +} + +// Drives just the left motor forward at duty (100 to 9900) +// Right motor is stopped (sleeping) +// Runs for time duration, and then stops +// Stop the motor and return if any bumper switch is active +void MotorLeft(uint16_t duty, uint32_t times_10ms) { + // write this code +} + +// Drives just the right motor forward at duty (100 to 9900) +// Left motor is stopped (sleeping) +// Runs for time duration, and then stops +// Stop the motor and return if any bumper switch is active +void MotorRight(uint16_t duty, uint32_t times_10ms) { + // write this code +} \ No newline at end of file diff --git a/common/motor_simple.h b/common/motor_simple.h new file mode 100644 index 0000000..ae3be83 --- /dev/null +++ b/common/motor_simple.h @@ -0,0 +1,13 @@ +#ifndef MOTOR_SIMPLE_H +#define MOTOR_SIMPLE_H + +#include + +void MotorInit(void); +void MotorStop(void); +void MotorForward(uint16_t duty, uint32_t times_10ms); +void MotorBackward(uint16_t duty, uint32_t times_10ms); +void MotorLeft(uint16_t duty, uint32_t times_10ms); +void MotorRight(uint16_t duty, uint32_t times_10ms); + +#endif /* MOTOR_SIMPLE_H */ \ No newline at end of file diff --git a/common/systick.c b/common/systick.c new file mode 100644 index 0000000..24a21c2 --- /dev/null +++ b/common/systick.c @@ -0,0 +1,18 @@ +#include "systick.h" + +#include "inc/msp432p401r.h" + +void SysTickInit(void) { + SysTick->LOAD = 0x00FFFFFF; // maximum reload value + SysTick->CTRL = 0x00000005; // enable SysTick with no interrupts +} + +// Assumes 48 MHz bus clock +void SysTickWait(uint32_t delay_ticks) { + // write this code + // any write to CVR clears it and COUNTFLAG in CSR +} + +void SysTickWait1us(uint32_t times) { + // write this code +} \ No newline at end of file diff --git a/common/systick.h b/common/systick.h new file mode 100644 index 0000000..974c181 --- /dev/null +++ b/common/systick.h @@ -0,0 +1,10 @@ +#ifndef SYSTICK_H +#define SYSTICK_H + +#include + +void SysTickInit(void); +void SysTickWait(uint32_t delay); +void SysTickWait1us(uint32_t times); + +#endif /* SYSTICK_H */ \ No newline at end of file diff --git a/lab4/Makefile b/lab4/Makefile new file mode 100644 index 0000000..1ede360 --- /dev/null +++ b/lab4/Makefile @@ -0,0 +1,74 @@ +CC = arm-none-eabi-gcc + +# The location of the C compiler +# ARMGCC_ROOT is used by some makefiles that need to know where the compiler +# is installed. +ARMGCC_BIN := ${shell which ${CC}} +ifeq (${shell test -h ${ARMGCC_BIN} && echo "true" || echo "false"}, true) + ARMGCC_ROOT := ${shell dirname ${shell readlink ${ARMGCC_BIN}}}/.. +else + ARMGCC_ROOT := ${shell dirname ${ARMGCC_BIN}}/.. +endif + +# Search for source files that are not in this directory +VPATH = ../common/ + +OBJECTS = main.o motor_simple.o systick.o bump.o clock.o system.o startup.o syscalls.o + +NAME = lab + +CFLAGS = -I.. -I../inc -I../common \ + -D__MSP432P401R__ \ + -DDeviceFamily_MSP432P401x \ + -mcpu=cortex-m4 \ + -march=armv7e-m \ + -mthumb \ + -std=c99 \ + -mfloat-abi=hard \ + -mfpu=fpv4-sp-d16 \ + -ffunction-sections \ + -fdata-sections \ + -gstrict-dwarf \ + -Wall \ + -I$(ARMGCC_ROOT)/arm-none-eabi/include/newlib-nano \ + -I$(ARMGCC_ROOT)/arm-none-eabi/include + +LFLAGS = -Wl,-T,../config.lds \ + -Wl,-Map,$(NAME).map \ + -march=armv7e-m \ + -mthumb \ + -mfloat-abi=hard \ + -mfpu=fpv4-sp-d16 \ + -static \ + -Wl,--gc-sections \ + -lgcc \ + -lc \ + -lm \ + -lnosys \ + --specs=nano.specs + +all: $(NAME).out + @echo "SUCCESS: Compilation completed successfully." + +%.o: %.c + @$(CC) $(CFLAGS) -g $< -c -o $@ + +clock.o: ../common/clock.c + @$(CC) $(CFLAGS) $< -c -o $@ + +system.o: ../system.c + @$(CC) $(CFLAGS) $< -c -o $@ + +startup.o: ../startup.c + @$(CC) $(CFLAGS) $< -c -o $@ + +syscalls.o: ../syscalls.c + @$(CC) $(CFLAGS) $< -c -o $@ + +$(NAME).out: $(OBJECTS) + @$(CC) $(OBJECTS) $(LFLAGS) -o $(NAME).out + +clean: # Redirecting both the stderr and stdout to /dev/null + @rm -f $(OBJECTS) > /dev/null 2>&1 + @rm -f $(NAME).out > /dev/null 2>&1 + @rm -f $(NAME).map > /dev/null 2>&1 diff --git a/lab4/main.c b/lab4/main.c new file mode 100644 index 0000000..00bdcd3 --- /dev/null +++ b/lab4/main.c @@ -0,0 +1,93 @@ +#include +#include + +#include "bump.h" +#include "systick.h" +#include "motor_simple.h" +#include "clock.h" + +#include "inc/msp432p401r.h" + +// bit-banded addresses, positive logic +#define SW2IN ((*((volatile uint8_t *)(0x42098010)))^1) +#define SW1IN ((*((volatile uint8_t *)(0x42098004)))^1) + +#define SIZE 100 + +// sinusoidal duty plot table +const uint32_t pulse_us[SIZE] = { + 5000, 5308, 5614, 5918, 6219, 6514, 6804, 7086, 7361, 7626, + 7880, 8123, 8354, 8572, 8776, 8964, 9137, 9294, 9434, 9556, + 9660, 9746, 9813, 9861, 9890, 9900, 9890, 9861, 9813, 9746, + 9660, 9556, 9434, 9294, 9137, 8964, 8776, 8572, 8354, 8123, + 7880, 7626, 7361, 7086, 6804, 6514, 6219, 5918, 5614, 5308, + 5000, 4692, 4386, 4082, 3781, 3486, 3196, 2914, 2639, 2374, + 2120, 1877, 1646, 1428, 1224, 1036, 863, 706, 566, 444, + 340, 254, 187, 139, 110, 100, 110, 139, 187, 254, + 340, 444, 566, 706, 863, 1036, 1224, 1428, 1646, 1877, + 2120, 2374, 2639, 2914, 3196, 3486, 3781, 4082, 4386, 4692 +}; + +void RedLEDInit(void) { + P1->SEL0 &= ~0x01; + P1->SEL1 &= ~0x01; // 1) configure P1.0 as GPIO + P1->DIR |= 0x01; // 2) make P1.0 out + P1->OUT &= ~0x01; +} + +void SwitchInit(void) { + P1->SEL0 &= ~0x12; + P1->SEL1 &= ~0x12; // 1) configure P1.4 and P1.1 as GPIO + P1->DIR &= ~0x12; // 2) make P1.4 and P1.1 in + P1->REN |= 0x12; // 3) enable pull resistors on P1.4 and P1.1 + P1->OUT |= 0x12; // P1.4 and P1.1 are pull-up +} + +void WaitTouchRelease(void) { + while(!(SW1IN || SW2IN)) {} // wait for touch + while(SW1IN || SW2IN) {} // wait for release +} + +int main_test_systick(void) { + ClockInit48MHz(); + SysTickInit(); + RedLEDInit(); + uint32_t H = 7500; + uint32_t L = 10000 - H; + while (true) { + P1->OUT |= 0x01; + SysTickWait1us(H); + P1->OUT &= ~0x01; + SysTickWait1us(L); + } +} + +// The heartbeat starts when the operator pushes Button 1 +// The heartbeat stops when the operator pushes Button 2 +// When beating, the P1.0 LED oscillates at 100 Hz (too fast to see with the eye) +// and the duty cycle is varied sinuosoidally once a second +int main_heartbeat(void) { + ClockInit48MHz(); + // write this code + while (true) { + // write this code + } +} + +int main_test_wheels(void) { + ClockInit48MHz(); + SysTickInit(); + SwitchInit(); + BumpInit(); + MotorInit(); // your function + while (true) { + WaitTouchRelease(); + MotorForward(1500, 100); // your function + WaitTouchRelease(); + MotorBackward(1500, 100); // your function + WaitTouchRelease(); + MotorLeft(1500, 100); // your function + WaitTouchRelease(); + MotorRight(1500, 100); // your function + } +} From c279b684a30ef3c1a1007de19253d8142540d68e Mon Sep 17 00:00:00 2001 From: AntonJ Date: Thu, 24 Apr 2025 14:11:16 +0300 Subject: [PATCH 5/5] Fixed older text in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3751d9c..99f524f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ In this repository you will find all of the labs that are required for Robot Kit using MSP432 completion during the IAS0330 course in TalTech. ## Requirements -Linux (or WSL), VS Code, openOCD, ARM compilers (arm-none-eabi), Cortex Debug VS Code extension is required to run and debug these labs. Place the whole labs catalogue folder under simplelink_msp432p4_VERSION/. For additional information go to the [Moodle wiki](https://moodle.taltech.ee/mod/wiki/view.php?id=696448). +Linux (or WSL), VS Code, openOCD, ARM compilers (arm-none-eabi), Cortex Debug VS Code extension is required to run and debug these labs. For additional information go to the [Moodle wiki](https://moodle.taltech.ee/mod/wiki/view.php?id=696448). ## Usage Open the folder of any lab in VS Code. Open the terminal and type: