diff --git a/README.md b/README.md index d1eb787..66f7aa2 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 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: diff --git a/common/bump.c b/common/bump.c new file mode 100644 index 0000000..960a33f --- /dev/null +++ b/common/bump.c @@ -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 +} \ No newline at end of file diff --git a/common/bump.h b/common/bump.h new file mode 100644 index 0000000..d4a00f1 --- /dev/null +++ b/common/bump.h @@ -0,0 +1,19 @@ +#ifndef BUMP_H +#define BUMP_H + +#include + +// 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 */ \ No newline at end of file diff --git a/common/clock.c b/common/clock.c new file mode 100644 index 0000000..0ce9619 --- /dev/null +++ b/common/clock.c @@ -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); +} \ No newline at end of file diff --git a/common/clock.h b/common/clock.h new file mode 100644 index 0000000..050bff7 --- /dev/null +++ b/common/clock.h @@ -0,0 +1,6 @@ +#ifndef CLOCK_H +#define CLOCK_H + +void ClockInit48MHz(void); + +#endif /* CLOCK_H */ \ No newline at end of file diff --git a/common/delay.c b/common/delay.c new file mode 100644 index 0000000..3471c22 --- /dev/null +++ b/common/delay.c @@ -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); + } +} \ No newline at end of file diff --git a/common/delay.h b/common/delay.h new file mode 100644 index 0000000..f492478 --- /dev/null +++ b/common/delay.h @@ -0,0 +1,9 @@ +#ifndef DELAY_H +#define DELAY_H + +#include + +void Delay1ms(uint32_t n); +void Delay1us(uint32_t n); + +#endif /* DELAY_H */ \ No newline at end of file diff --git a/lab2/Makefile b/lab2/Makefile new file mode 100644 index 0000000..147fa6e --- /dev/null +++ b/lab2/Makefile @@ -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 diff --git a/lab2/main.c b/lab2/main.c new file mode 100644 index 0000000..ab0a9d2 --- /dev/null +++ b/lab2/main.c @@ -0,0 +1,21 @@ +#include +#include + +#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 + } +}