Merge branch 'main' into dev

This commit is contained in:
Ondrej Hladuvka 2025-04-30 16:10:01 +03:00
commit c4d769003c
11 changed files with 329 additions and 25 deletions

View File

@ -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. 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 ## 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 ## Usage
Open the folder of any lab in VS Code. Open the terminal and type: Open the folder of any lab in VS Code. Open the terminal and type:

57
common/motor_simple.c Normal file
View File

@ -0,0 +1,57 @@
#include <stdbool.h>
#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
}

13
common/motor_simple.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef MOTOR_SIMPLE_H
#define MOTOR_SIMPLE_H
#include <stdint.h>
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 */

18
common/systick.c Normal file
View File

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

10
common/systick.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef SYSTICK_H
#define SYSTICK_H
#include <stdint.h>
void SysTickInit(void);
void SysTickWait(uint32_t delay);
void SysTickWait1us(uint32_t times);
#endif /* SYSTICK_H */

View File

@ -4,9 +4,18 @@ CC = arm-none-eabi-gcc
# ARMGCC_ROOT is used by some makefiles that need to know where the compiler # ARMGCC_ROOT is used by some makefiles that need to know where the compiler
# is installed. # is installed.
ARMGCC_ROOT := /usr/arm-none-eabi ARMGCC_ROOT := /usr/arm-none-eabi
# ${shell dirname ${shell readlink ${shell which ${CC}}}}/.. # 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 # Search for source files that are not in this directory
VPATH = ../common/
OBJECTS = main.o system.o startup.o syscalls.o
NAME = lab NAME = lab
@ -41,8 +50,9 @@ LFLAGS = -Wl,-T,../config.lds \
--specs=nano.specs --specs=nano.specs
all: $(NAME).out all: $(NAME).out
@echo "SUCCESS: Compilation completed successfully."
main.o: main.c %.o: %.c
@$(CC) $(CFLAGS) -g $< -c -o $@ @$(CC) $(CFLAGS) -g $< -c -o $@
system.o: ../system.c system.o: ../system.c
@ -51,6 +61,9 @@ system.o: ../system.c
startup.o: ../startup.c startup.o: ../startup.c
@$(CC) $(CFLAGS) $< -c -o $@ @$(CC) $(CFLAGS) $< -c -o $@
syscalls.o: ../syscalls.c
@$(CC) $(CFLAGS) $< -c -o $@
$(NAME).out: $(OBJECTS) $(NAME).out: $(OBJECTS)
@$(CC) $(OBJECTS) $(LFLAGS) -o $(NAME).out @$(CC) $(OBJECTS) $(LFLAGS) -o $(NAME).out

View File

@ -3,9 +3,17 @@ CC = arm-none-eabi-gcc
# The location of the C compiler # The location of the C compiler
# ARMGCC_ROOT is used by some makefiles that need to know where the compiler # ARMGCC_ROOT is used by some makefiles that need to know where the compiler
# is installed. # 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 # 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 NAME = lab
@ -40,14 +48,9 @@ LFLAGS = -Wl,-T,../config.lds \
--specs=nano.specs --specs=nano.specs
all: $(NAME).out all: $(NAME).out
@echo "SUCCESS: Compilation completed successfully."
main.o: main.c %.o: %.c
@$(CC) $(CFLAGS) -g $< -c -o $@
bump.o: ../common/bump.c
@$(CC) $(CFLAGS) -g $< -c -o $@
delay.o: ../common/delay.c
@$(CC) $(CFLAGS) -g $< -c -o $@ @$(CC) $(CFLAGS) -g $< -c -o $@
clock.o: ../common/clock.c clock.o: ../common/clock.c
@ -59,6 +62,9 @@ system.o: ../system.c
startup.o: ../startup.c startup.o: ../startup.c
@$(CC) $(CFLAGS) $< -c -o $@ @$(CC) $(CFLAGS) $< -c -o $@
syscalls.o: ../syscalls.c
@$(CC) $(CFLAGS) $< -c -o $@
$(NAME).out: $(OBJECTS) $(NAME).out: $(OBJECTS)
@$(CC) $(OBJECTS) $(LFLAGS) -o $(NAME).out @$(CC) $(OBJECTS) $(LFLAGS) -o $(NAME).out

View File

@ -3,9 +3,17 @@ CC = arm-none-eabi-gcc
# The location of the C compiler # The location of the C compiler
# ARMGCC_ROOT is used by some makefiles that need to know where the compiler # ARMGCC_ROOT is used by some makefiles that need to know where the compiler
# is installed. # 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 # 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 NAME = lab
@ -40,22 +48,14 @@ LFLAGS = -Wl,-T,../config.lds \
--specs=nano.specs --specs=nano.specs
all: $(NAME).out all: $(NAME).out
@echo "SUCCESS: Compilation completed successfully."
main.o: main.c %.o: %.c
@$(CC) $(CFLAGS) -g $< -c -o $@
bump.o: ../common/bump.c
@$(CC) $(CFLAGS) -g $< -c -o $@
delay.o: ../common/delay.c
@$(CC) $(CFLAGS) -g $< -c -o $@ @$(CC) $(CFLAGS) -g $< -c -o $@
clock.o: ../common/clock.c clock.o: ../common/clock.c
@$(CC) $(CFLAGS) $< -c -o $@ @$(CC) $(CFLAGS) $< -c -o $@
reflectance.o: ../common/reflectance.c
@$(CC) $(CFLAGS) -g $< -c -o $@
cpu.o: ../common/cpu.c cpu.o: ../common/cpu.c
@$(CC) $(CFLAGS) $< -c -o $@ @$(CC) $(CFLAGS) $< -c -o $@
@ -65,6 +65,9 @@ system.o: ../system.c
startup.o: ../startup.c startup.o: ../startup.c
@$(CC) $(CFLAGS) $< -c -o $@ @$(CC) $(CFLAGS) $< -c -o $@
syscalls.o: ../syscalls.c
@$(CC) $(CFLAGS) $< -c -o $@
$(NAME).out: $(OBJECTS) $(NAME).out: $(OBJECTS)
@$(CC) $(OBJECTS) $(LFLAGS) -o $(NAME).out @$(CC) $(OBJECTS) $(LFLAGS) -o $(NAME).out

74
lab4/Makefile Normal file
View File

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

93
lab4/main.c Normal file
View File

@ -0,0 +1,93 @@
#include <stdbool.h>
#include <stdint.h>
#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
}
}

17
syscalls.c Normal file
View File

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