mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
Add support of stm32 in Makefile (ugly one)
This commit is contained in:
parent
74a0f470d2
commit
a787f17a1b
65
Makefile
65
Makefile
@ -13,13 +13,17 @@
|
||||
# limitations under the License.
|
||||
|
||||
TARGET ?= jerry
|
||||
CROSS_COMPILE ?=
|
||||
OBJ_DIR = obj
|
||||
CROSS_COMPILE ?= arm-none-eabi-
|
||||
OBJ_DIR = ./obj
|
||||
OUT_DIR = ./out
|
||||
|
||||
MAIN_MODULE_SRC = ./src/main.c
|
||||
UNITTESTS_SRC_DIR = ./tests/unit
|
||||
|
||||
LNK_SCRIPT_STM32F4 = ./third-party/stm32f4.ld
|
||||
SUP_STM32F4 = ./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f4xx.s
|
||||
|
||||
|
||||
# FIXME:
|
||||
# Place jerry-libc.c, pretty-printer.c to some subdirectory (libruntime?)
|
||||
# and add them to the SOURCES list through wildcard.
|
||||
@ -34,6 +38,9 @@ SOURCES = \
|
||||
$(wildcard ./src/liballocator/*.c) \
|
||||
$(wildcard ./src/libcoreint/*.c) )
|
||||
|
||||
SOURCES_STM32F4 = \
|
||||
third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c
|
||||
|
||||
HEADERS = \
|
||||
$(sort \
|
||||
$(wildcard ./src/*.h) \
|
||||
@ -51,6 +58,11 @@ INCLUDES = \
|
||||
-I src/liballocator \
|
||||
-I src/libcoreint
|
||||
|
||||
INCLUDES_STM32F4 = \
|
||||
-I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Include \
|
||||
-I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/STM32F4xx_StdPeriph_Driver/inc \
|
||||
-I third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/Include
|
||||
|
||||
UNITTESTS = \
|
||||
$(sort \
|
||||
$(patsubst %.c,%,$(notdir \
|
||||
@ -58,38 +70,59 @@ UNITTESTS = \
|
||||
|
||||
OBJS = \
|
||||
$(sort \
|
||||
$(patsubst %.c,./$(OBJ_DIR)/%.o,$(notdir $(MAIN_MODULE_SRC) $(SOURCES))))
|
||||
$(patsubst %.c,./%.o,$(notdir $(MAIN_MODULE_SRC) $(SOURCES))))
|
||||
|
||||
CC = $(CROSS_COMPILE)gcc
|
||||
LD = $(CROSS_COMPILE)ld
|
||||
OBJDUMP = $(CROSS_COMPILE)objdump
|
||||
OBJCOPY = $(CROSS_COMPILE)objcopy
|
||||
SIZE = $(CROSS_COMPILE)size
|
||||
STRIP = $(CROSS_COMPILE)strip
|
||||
CC = gcc
|
||||
LD = ld
|
||||
OBJDUMP = objdump
|
||||
OBJCOPY = objcopy
|
||||
SIZE = size
|
||||
STRIP = strip
|
||||
|
||||
# General flags
|
||||
CFLAGS ?= $(INCLUDES) -std=c99 #-fdiagnostics-color=always
|
||||
CFLAGS += -Wall -Wextra -Wpedantic -Wlogical-op -Winline
|
||||
CFLAGS += -Wformat-nonliteral -Winit-self -Wstack-protector
|
||||
CFLAGS += -Wconversion -Wsign-conversion -Wformat-security
|
||||
CFLAGS += -Wstrict-prototypes -Wmissing-prototypes
|
||||
#CFLAGS += -Wall -Wextra -Wpedantic -Wlogical-op -Winline
|
||||
#CFLAGS += -Wformat-nonliteral -Winit-self -Wstack-protector
|
||||
#CFLAGS += -Wconversion -Wsign-conversion -Wformat-security
|
||||
#CFLAGS += -Wstrict-prototypes -Wmissing-prototypes
|
||||
|
||||
# Flags for MCU
|
||||
MCU_CFLAGS += -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m -mthumb
|
||||
MCU_CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
||||
MCU_CFLAGS += -ffunction-sections -fdata-sections
|
||||
MCU_CFLAGS += -ffunction-sections -fdata-sections -nostdlib -fno-common
|
||||
|
||||
LDFLAGS = -nostartfiles -T$(LNK_SCRIPT_STM32F4)
|
||||
|
||||
DEBUG_OPTIONS = -g3 -O0 # -fsanitize=address
|
||||
RELEASE_OPTIONS = -Os -Werror -DJERRY_NDEBUG
|
||||
|
||||
DEFINES = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768 -DMEM_STATS
|
||||
TARGET_HOST = -D__HOST
|
||||
TARGET_MCU = -D__MCU
|
||||
TARGET_MCU = -D__TARGET_MCU
|
||||
|
||||
.PHONY: all debug debug.stm32f3 release clean tests check install
|
||||
#-I third-party/STM32F4-Discovery_FW_V1.1.0/Project/Demonstration \
|
||||
|
||||
.PHONY: all debug debug.stdm32f4 release clean tests check install
|
||||
|
||||
all: clean debug release check
|
||||
|
||||
debug.stdm32f4: clean debug.stdm32f4.bin
|
||||
|
||||
debug.stdm32f4.o:
|
||||
mkdir -p $(OUT_DIR)/debug.stdm32f4/
|
||||
$(CROSS_COMPILE)$(CC) \
|
||||
$(SUP_STM32F4) $(SOURCES_STM32F4) $(INCLUDES_STM32F4) \
|
||||
$(CFLAGS) $(MCU_CFLAGS) $(DEBUG_OPTIONS) \
|
||||
$(DEFINES) $(TARGET_MCU) $(MAIN_MODULE_SRC) -c
|
||||
|
||||
debug.stdm32f4.elf: debug.stdm32f4.o
|
||||
$(CROSS_COMPILE)$(LD) $(LDFLAGS) -o $(TARGET).elf *.o
|
||||
rm -f *.o
|
||||
|
||||
debug.stdm32f4.bin: debug.stdm32f4.elf
|
||||
$(CROSS_COMPILE)$(OBJCOPY) -Obinary $(TARGET).elf $(TARGET).bin
|
||||
rm -f *.elf
|
||||
|
||||
debug: clean
|
||||
mkdir -p $(OUT_DIR)/debug.host/
|
||||
$(CC) $(CFLAGS) $(DEBUG_OPTIONS) $(DEFINES) $(TARGET_HOST) \
|
||||
|
||||
@ -38,11 +38,6 @@ gen_bytecode ()
|
||||
// save_op_data (3, getop_call_1 (0, 14));
|
||||
// save_op_data (4, getop_call_1 (0, 15));
|
||||
// save_op_data (5, getop_jmp (0));
|
||||
|
||||
#ifdef __MCU
|
||||
// It's mandatory to restart app!
|
||||
save_op_data (getop_jmp (0));
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
56
src/main.c
56
src/main.c
@ -19,6 +19,17 @@
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f4xx_gpio.h"
|
||||
#include "stm32f4xx_rcc.h"
|
||||
|
||||
#define LED_GREEN 12
|
||||
#define LED_ORANGE 13
|
||||
#define LED_RED 14
|
||||
#define LED_BLUE 15
|
||||
#endif
|
||||
|
||||
#include "error.h"
|
||||
|
||||
#include "ctx-manager.h"
|
||||
@ -33,7 +44,52 @@ void fake_exit ();
|
||||
void
|
||||
fake_exit (void)
|
||||
{
|
||||
#ifdef __TARGET_MCU
|
||||
int pin = LED_RED;
|
||||
uint32_t mode = GPIO_Mode_OUT << (pin * 2);
|
||||
uint32_t speed = GPIO_Speed_100MHz << (pin * 2);
|
||||
uint32_t type = GPIO_OType_PP << pin;
|
||||
uint32_t pullup = GPIO_PuPd_NOPULL << (pin * 2);
|
||||
//
|
||||
// Initialise the peripheral clock.
|
||||
//
|
||||
RCC->AHB1ENR |= RCC_AHB1Periph_GPIOD;
|
||||
//
|
||||
// Initilaise the GPIO port.
|
||||
//
|
||||
GPIOD->MODER |= mode;
|
||||
GPIOD->OSPEEDR |= speed;
|
||||
GPIOD->OTYPER |= type;
|
||||
GPIOD->PUPDR |= pullup;
|
||||
//
|
||||
// Toggle the selected LED indefinitely.
|
||||
//
|
||||
int index;
|
||||
|
||||
// SOS
|
||||
|
||||
int dot = 600000;
|
||||
int dash = dot * 3;
|
||||
|
||||
while (1)
|
||||
{
|
||||
GPIOD->BSRRL = (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++);
|
||||
GPIOD->BSRRL = (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++);
|
||||
GPIOD->BSRRL = (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++);
|
||||
|
||||
GPIOD->BSRRL = (1 << pin); for (index = 0; index < dash; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++);
|
||||
GPIOD->BSRRL = (1 << pin); for (index = 0; index < dash; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++);
|
||||
GPIOD->BSRRL = (1 << pin); for (index = 0; index < dash; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++);
|
||||
|
||||
GPIOD->BSRRL = (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++);
|
||||
GPIOD->BSRRL = (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (1 << pin); for (index = 0; index < dash; index++);
|
||||
GPIOD->BSRRL = (1 << pin); for (index = 0; index < dot; index++); GPIOD->BSRRH = (1 << pin);
|
||||
|
||||
for (index = 0; index < dash * 7; index++);
|
||||
}
|
||||
#else
|
||||
for (;;);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user