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.
|
# limitations under the License.
|
||||||
|
|
||||||
TARGET ?= jerry
|
TARGET ?= jerry
|
||||||
CROSS_COMPILE ?=
|
CROSS_COMPILE ?= arm-none-eabi-
|
||||||
OBJ_DIR = obj
|
OBJ_DIR = ./obj
|
||||||
OUT_DIR = ./out
|
OUT_DIR = ./out
|
||||||
|
|
||||||
MAIN_MODULE_SRC = ./src/main.c
|
MAIN_MODULE_SRC = ./src/main.c
|
||||||
UNITTESTS_SRC_DIR = ./tests/unit
|
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:
|
# FIXME:
|
||||||
# Place jerry-libc.c, pretty-printer.c to some subdirectory (libruntime?)
|
# Place jerry-libc.c, pretty-printer.c to some subdirectory (libruntime?)
|
||||||
# and add them to the SOURCES list through wildcard.
|
# and add them to the SOURCES list through wildcard.
|
||||||
@ -34,6 +38,9 @@ SOURCES = \
|
|||||||
$(wildcard ./src/liballocator/*.c) \
|
$(wildcard ./src/liballocator/*.c) \
|
||||||
$(wildcard ./src/libcoreint/*.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 = \
|
HEADERS = \
|
||||||
$(sort \
|
$(sort \
|
||||||
$(wildcard ./src/*.h) \
|
$(wildcard ./src/*.h) \
|
||||||
@ -51,6 +58,11 @@ INCLUDES = \
|
|||||||
-I src/liballocator \
|
-I src/liballocator \
|
||||||
-I src/libcoreint
|
-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 = \
|
UNITTESTS = \
|
||||||
$(sort \
|
$(sort \
|
||||||
$(patsubst %.c,%,$(notdir \
|
$(patsubst %.c,%,$(notdir \
|
||||||
@ -58,38 +70,59 @@ UNITTESTS = \
|
|||||||
|
|
||||||
OBJS = \
|
OBJS = \
|
||||||
$(sort \
|
$(sort \
|
||||||
$(patsubst %.c,./$(OBJ_DIR)/%.o,$(notdir $(MAIN_MODULE_SRC) $(SOURCES))))
|
$(patsubst %.c,./%.o,$(notdir $(MAIN_MODULE_SRC) $(SOURCES))))
|
||||||
|
|
||||||
CC = $(CROSS_COMPILE)gcc
|
CC = gcc
|
||||||
LD = $(CROSS_COMPILE)ld
|
LD = ld
|
||||||
OBJDUMP = $(CROSS_COMPILE)objdump
|
OBJDUMP = objdump
|
||||||
OBJCOPY = $(CROSS_COMPILE)objcopy
|
OBJCOPY = objcopy
|
||||||
SIZE = $(CROSS_COMPILE)size
|
SIZE = size
|
||||||
STRIP = $(CROSS_COMPILE)strip
|
STRIP = strip
|
||||||
|
|
||||||
# General flags
|
# General flags
|
||||||
CFLAGS ?= $(INCLUDES) -std=c99 #-fdiagnostics-color=always
|
CFLAGS ?= $(INCLUDES) -std=c99 #-fdiagnostics-color=always
|
||||||
CFLAGS += -Wall -Wextra -Wpedantic -Wlogical-op -Winline
|
#CFLAGS += -Wall -Wextra -Wpedantic -Wlogical-op -Winline
|
||||||
CFLAGS += -Wformat-nonliteral -Winit-self -Wstack-protector
|
#CFLAGS += -Wformat-nonliteral -Winit-self -Wstack-protector
|
||||||
CFLAGS += -Wconversion -Wsign-conversion -Wformat-security
|
#CFLAGS += -Wconversion -Wsign-conversion -Wformat-security
|
||||||
CFLAGS += -Wstrict-prototypes -Wmissing-prototypes
|
#CFLAGS += -Wstrict-prototypes -Wmissing-prototypes
|
||||||
|
|
||||||
# Flags for MCU
|
# Flags for MCU
|
||||||
MCU_CFLAGS += -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m -mthumb
|
MCU_CFLAGS += -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m -mthumb
|
||||||
MCU_CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
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
|
DEBUG_OPTIONS = -g3 -O0 # -fsanitize=address
|
||||||
RELEASE_OPTIONS = -Os -Werror -DJERRY_NDEBUG
|
RELEASE_OPTIONS = -Os -Werror -DJERRY_NDEBUG
|
||||||
|
|
||||||
DEFINES = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768 -DMEM_STATS
|
DEFINES = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768 -DMEM_STATS
|
||||||
TARGET_HOST = -D__HOST
|
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
|
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
|
debug: clean
|
||||||
mkdir -p $(OUT_DIR)/debug.host/
|
mkdir -p $(OUT_DIR)/debug.host/
|
||||||
$(CC) $(CFLAGS) $(DEBUG_OPTIONS) $(DEFINES) $(TARGET_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 (3, getop_call_1 (0, 14));
|
||||||
// save_op_data (4, getop_call_1 (0, 15));
|
// save_op_data (4, getop_call_1 (0, 15));
|
||||||
// save_op_data (5, getop_jmp (0));
|
// save_op_data (5, getop_jmp (0));
|
||||||
|
|
||||||
#ifdef __MCU
|
|
||||||
// It's mandatory to restart app!
|
|
||||||
save_op_data (getop_jmp (0));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
62
src/main.c
62
src/main.c
@ -14,9 +14,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef JERRY_NDEBUG
|
#ifdef JERRY_NDEBUG
|
||||||
# include <stdio.h>
|
#include <stdio.h>
|
||||||
# include <stdlib.h>
|
#include <stdlib.h>
|
||||||
# include <string.h>
|
#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
|
#endif
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
@ -33,7 +44,52 @@ void fake_exit ();
|
|||||||
void
|
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 (;;);
|
for (;;);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user