Added Lab 2 and common files

This commit is contained in:
AntonJ 2025-02-12 18:59:14 +02:00
parent c5948abbc2
commit cd1d2a08f5
9 changed files with 189 additions and 1 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.
## 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 msp432/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. 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).
## Usage
Open the folder of any lab in VS Code. Open the terminal and type:

12
common/bump.c Normal file
View File

@ -0,0 +1,12 @@
#include "bump.h"
#include "ti/devices/msp432p4xx/inc/msp432p401r.h"
void BumpInit(void) {
// write this as part of Lab 2
}
uint8_t BumpRead(void) {
// write this as part of Lab 2
return 0; // replace this line
}

19
common/bump.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef BUMP_H
#define BUMP_H
#include <stdint.h>
// Set port pins Port 4.0, 4.2, 4.3, 4.5, 4.6 and 4.7 and enable internal resistors as needed
void BumpInit(void);
// Read current state of 6 switches
// Returns a 6-bit positive logic result (0 to 63)
// bit 5 Bump5
// bit 4 Bump4
// bit 3 Bump3
// bit 2 Bump2
// bit 1 Bump1
// bit 0 Bump0
uint8_t BumpRead(void);
#endif /* BUMP_H */

21
common/clock.c Normal file
View File

@ -0,0 +1,21 @@
#include "clock.h"
#include "ti/devices/msp432p4xx/inc/msp432p401r.h"
#include "ti/devices/msp432p4xx/driverlib/driverlib.h"
void ClockInit48MHz(void) {
/* Halting WDT and disabling master interrupts */
MAP_WDT_A_holdTimer();
MAP_Interrupt_disableMaster();
/* Set the core voltage level to VCORE1 */
MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);
/* Set 2 flash wait states for Flash bank 0 and 1*/
MAP_FlashCtl_setWaitState(FLASH_BANK0, 2);
MAP_FlashCtl_setWaitState(FLASH_BANK1, 2);
/* Initializes Clock System */
MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);
MAP_CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
MAP_CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
}

6
common/clock.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef CLOCK_H
#define CLOCK_H
void ClockInit48MHz(void);
#endif /* CLOCK_H */

20
common/delay.c Normal file
View File

@ -0,0 +1,20 @@
#include "delay.h"
void __attribute__((naked))
Delay(uint32_t count) {
__asm(" subs r0, #1\n"
" bne Delay\n"
" bx lr");
}
// 1us tuned at 48 MHz
void Delay1us(uint32_t n) {
for (n = (382 * n) / 100; n; n--) {}
}
// 1 msec, tuned at 48 MHz
void Delay1ms(uint32_t n) {
for (; n; n--) {
Delay(48000000 / 9162);
}
}

9
common/delay.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef DELAY_H
#define DELAY_H
#include <stdint.h>
void Delay1ms(uint32_t n);
void Delay1us(uint32_t n);
#endif /* DELAY_H */

80
lab2/Makefile Normal file
View File

@ -0,0 +1,80 @@
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}}}}/..
ROOT ?= $(abspath ../..)
OBJECTS = main.o bump.o delay.o clock.o system.o startup.o
NAME = lab
CFLAGS = -I.. -I../common \
-I$(ROOT)/source \
-I$(ROOT)/source/third_party/CMSIS/Include \
-D__MSP432P401R__ \
-DDeviceFamily_MSP432P401x \
-mcpu=cortex-m4 \
-march=armv7e-m \
-mthumb \
-std=c99 \
-mfloat-abi=hard \
-mfpu=fpv4-sp-d16 \
-ffunction-sections \
-fdata-sections \
-g \
-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 \
-L$(ROOT)/source \
-l:ti/display/lib/display.am4fg \
-l:ti/grlib/lib/gcc/m4f/grlib.a \
-l:third_party/spiffs/lib/gcc/m4f/spiffs.a \
-l:ti/drivers/lib/drivers_msp432p401x.am4fg \
-l:third_party/fatfs/lib/gcc/m4f/fatfs.a \
-l:ti/devices/msp432p4xx/driverlib/gcc/msp432p4xx_driverlib.a \
-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
main.o: main.c
@$(CC) $(CFLAGS) $< -c -o $@
bump.o: ../common/bump.c
@$(CC) $(CFLAGS) $< -c -o $@
delay.o: ../common/delay.c
@$(CC) $(CFLAGS) $< -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 $@
$(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

21
lab2/main.c Normal file
View File

@ -0,0 +1,21 @@
#include <stdbool.h>
#include <stdint.h>
#include "bump.h"
#include "delay.h"
#include "clock.h"
void DebugDump(uint8_t bump) {
// write this as part of Lab 2
}
int main(void) {
// write this as part of Lab 2
ClockInit48MHz();
while (true) {
// write this as part of Lab 2
// 10ms delay
// debug dump
}
}