Support of STM32F3 board.
This commit is contained in:
+187
-57
@@ -13,88 +13,218 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#include "stm32f4xx_conf.h"
|
||||
#include "stm32f4xx.h"
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#include "actuators.h"
|
||||
#include "common-io.h"
|
||||
#include "jerry-libc.h"
|
||||
|
||||
void
|
||||
led_toggle (uint32_t led_id)
|
||||
{
|
||||
#ifdef __TARGET_HOST
|
||||
/**
|
||||
* Host stub for LEDToggle operation
|
||||
*/
|
||||
void
|
||||
led_toggle (uint32_t led_id) /**< index of LED */
|
||||
{
|
||||
__printf ("led_toggle: %d\n", led_id);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
GPIOD->ODR ^= (uint16_t) (1 << led_id);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Host stub for LEDOn operation
|
||||
*/
|
||||
void
|
||||
led_on (uint32_t led_id)
|
||||
led_on (uint32_t led_id) /**< index of LED */
|
||||
{
|
||||
#ifdef __TARGET_HOST
|
||||
__printf ("led_on: %d\n", led_id);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
GPIO_WriteBit (GPIOD, (uint16_t) (1 << led_id), Bit_SET);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Host stub for LEDOff operation
|
||||
*/
|
||||
void
|
||||
led_off (uint32_t led_id)
|
||||
led_off (uint32_t led_id) /**< index of LED */
|
||||
{
|
||||
#ifdef __TARGET_HOST
|
||||
__printf ("led_off: %d\n", led_id);
|
||||
#endif
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
GPIO_WriteBit (GPIOD, (uint16_t) (1 << led_id), Bit_RESET);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Host stub for LEDOnce operation
|
||||
*/
|
||||
void
|
||||
led_blink_once (uint32_t led_id)
|
||||
led_blink_once (uint32_t led_id) /**< index of LED */
|
||||
{
|
||||
#ifdef __TARGET_HOST
|
||||
__printf ("led_blink_once: %d\n", led_id);
|
||||
#endif
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
uint32_t dot = 300000;
|
||||
|
||||
GPIOD->BSRRL = (uint16_t) (1 << led_id);
|
||||
wait_ms (dot);
|
||||
GPIOD->BSRRH = (uint16_t) (1 << led_id);
|
||||
#endif
|
||||
}
|
||||
#else /* !__TARGET_HOST */
|
||||
#ifndef __TARGET_MCU
|
||||
# error "!__TARGET_HOST && !__TARGET_MCU"
|
||||
#endif /* !__TARGET_MCU */
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
#include "mcu-headers.h"
|
||||
|
||||
void
|
||||
initialize_leds ()
|
||||
#ifdef __TARGET_MCU_STM32F4
|
||||
/**
|
||||
* Number of LEDs on the board
|
||||
*/
|
||||
#define LED_NUMBER 4
|
||||
|
||||
/**
|
||||
* LEDs' GPIO pins
|
||||
*/
|
||||
static const uint16_t led_pins [LED_NUMBER] =
|
||||
{
|
||||
GPIO_Pin_12, /* LD4: Green */
|
||||
GPIO_Pin_13, /* LD3: Orange */
|
||||
GPIO_Pin_14, /* LD5: Red */
|
||||
GPIO_Pin_15 /* LD6: Blue */
|
||||
};
|
||||
|
||||
/**
|
||||
* LEDs' GPIO ports
|
||||
*/
|
||||
static GPIO_TypeDef* leds_port = GPIOD;
|
||||
|
||||
/**
|
||||
* Initialize LEDs on the board
|
||||
*/
|
||||
void
|
||||
initialize_leds (void)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOD, ENABLE);
|
||||
|
||||
GPIO_InitTypeDef gpioStructure;
|
||||
gpioStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
|
||||
gpioStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
gpioStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||
GPIO_Init (GPIOD, &gpioStructure);
|
||||
uint16_t led_pins_mask = 0;
|
||||
for (uint32_t led_index = 0;
|
||||
led_index < LED_NUMBER;
|
||||
led_index++)
|
||||
{
|
||||
led_pins_mask |= led_pins[led_index];
|
||||
}
|
||||
|
||||
GPIO_WriteBit (GPIOD,
|
||||
GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15,
|
||||
Bit_RESET);
|
||||
}
|
||||
#endif
|
||||
gpio_init_structure.GPIO_Pin = led_pins_mask;
|
||||
gpio_init_structure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
gpio_init_structure.GPIO_Speed = GPIO_Speed_100MHz;
|
||||
GPIO_Init (leds_port, &gpio_init_structure);
|
||||
|
||||
for (uint32_t led_index = 0;
|
||||
led_index < LED_NUMBER;
|
||||
led_index++)
|
||||
{
|
||||
led_off (led_index);
|
||||
}
|
||||
} /* initialize_leds */
|
||||
|
||||
#else /* !__TARGET_MCU_STM32F4 */
|
||||
|
||||
# ifndef __TARGET_MCU_STM32F3
|
||||
# error "!__TARGET_MCU_STM32F4 && !__TARGET_MCU_STM32F3"
|
||||
# endif /* !__TARGET_MCU_STM32F3 */
|
||||
|
||||
/**
|
||||
* Number of LEDs on the board
|
||||
*/
|
||||
#define LED_NUMBER 8
|
||||
|
||||
/**
|
||||
* LEDs' GPIO pins
|
||||
*/
|
||||
static const uint16_t led_pins [LED_NUMBER] =
|
||||
{
|
||||
GPIO_Pin_15, /* LD6 - Green */
|
||||
GPIO_Pin_14, /* LD8 - Orange */
|
||||
GPIO_Pin_13, /* LD10 - Red */
|
||||
GPIO_Pin_12, /* LD9 - Blue */
|
||||
GPIO_Pin_11, /* LD7 - Green */
|
||||
GPIO_Pin_10, /* LD5 - Orange */
|
||||
GPIO_Pin_9, /* LD3 - Red */
|
||||
GPIO_Pin_8 /* LD4 - Blue */
|
||||
};
|
||||
|
||||
/**
|
||||
* LEDs' GPIO ports
|
||||
*/
|
||||
static GPIO_TypeDef* leds_port = GPIOE;
|
||||
|
||||
/**
|
||||
* Initialize LEDs on the board
|
||||
*/
|
||||
void
|
||||
initialize_leds (void)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOE, ENABLE);
|
||||
|
||||
uint16_t led_pins_mask = 0;
|
||||
for (uint32_t led_index = 0;
|
||||
led_index < LED_NUMBER;
|
||||
led_index++)
|
||||
{
|
||||
led_pins_mask |= led_pins[led_index];
|
||||
}
|
||||
|
||||
gpio_init_structure.GPIO_Pin = led_pins_mask;
|
||||
gpio_init_structure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
gpio_init_structure.GPIO_OType = GPIO_OType_PP;
|
||||
gpio_init_structure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
gpio_init_structure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init (leds_port, &gpio_init_structure);
|
||||
|
||||
for (uint32_t led_index = 0;
|
||||
led_index < LED_NUMBER;
|
||||
led_index++)
|
||||
{
|
||||
led_off (led_index);
|
||||
}
|
||||
} /* initialize_leds */
|
||||
#endif /* !__TARGET_MCU_STM32F4 && __TARGET_MCU_STM32F3 */
|
||||
|
||||
/**
|
||||
* Toggle specified LED
|
||||
*/
|
||||
void
|
||||
led_toggle (uint32_t led_id) /**< index of LED */
|
||||
{
|
||||
if (led_id < LED_NUMBER)
|
||||
{
|
||||
leds_port->ODR ^= led_pins [led_id];
|
||||
}
|
||||
} /* led_toggle */
|
||||
|
||||
/**
|
||||
* Turn specified LED on
|
||||
*/
|
||||
void
|
||||
led_on (uint32_t led_id) /**< index of LED */
|
||||
{
|
||||
if (led_id < LED_NUMBER)
|
||||
{
|
||||
GPIO_WriteBit (leds_port, led_pins[led_id], Bit_SET);
|
||||
}
|
||||
} /* led_on */
|
||||
|
||||
/**
|
||||
* Turn specified LED off
|
||||
*/
|
||||
void
|
||||
led_off (uint32_t led_id) /**< index of LED */
|
||||
{
|
||||
if (led_id < LED_NUMBER)
|
||||
{
|
||||
GPIO_WriteBit (leds_port, led_pins[led_id], Bit_RESET);
|
||||
}
|
||||
} /* led_off */
|
||||
|
||||
/**
|
||||
* Blink once with specified LED
|
||||
*/
|
||||
void
|
||||
led_blink_once (uint32_t led_id) /**< index of LED */
|
||||
{
|
||||
uint32_t dot = 300;
|
||||
|
||||
led_on (led_id);
|
||||
wait_ms (dot);
|
||||
led_off (led_id);
|
||||
} /* led_blink_once */
|
||||
|
||||
#endif /* !__TARGET_HOST && __TARGET_MCU */
|
||||
|
||||
@@ -13,23 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "actuators.h"
|
||||
#include "common-io.h"
|
||||
#include "jerry-libc.h"
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#include "stm32f4xx_conf.h"
|
||||
#include "stm32f4xx.h"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
// STM32 F4
|
||||
#define LED_GREEN 12
|
||||
#define LED_ORANGE 13
|
||||
#define LED_RED 14
|
||||
#define LED_BLUE 15
|
||||
#endif
|
||||
#include "mcu-headers.h"
|
||||
|
||||
int
|
||||
digital_read (uint32_t arg1 __unused, uint32_t arg2 __unused)
|
||||
@@ -55,62 +43,17 @@ analog_write (uint32_t arg1 __unused, uint32_t arg2 __unused)
|
||||
JERRY_UNIMPLEMENTED ();
|
||||
}
|
||||
|
||||
#ifdef __TARGET_HOST
|
||||
void
|
||||
wait_ms (uint32_t time_ms)
|
||||
{
|
||||
#ifdef __TARGET_HOST
|
||||
// 1 millisecond = 1,000,000 Nanoseconds
|
||||
#define NANO_SECOND_MULTIPLIER 1000000
|
||||
__printf ("wait_ms: %d\n", time_ms);
|
||||
#endif
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
while (time_ms --)
|
||||
{
|
||||
wait_1ms ();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#else /* !__TARGET_HOST */
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
|
||||
void
|
||||
initialize_timer ()
|
||||
{
|
||||
RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM2, ENABLE);
|
||||
|
||||
TIM_TimeBaseInitTypeDef timerInitStructure;
|
||||
timerInitStructure.TIM_Prescaler = 40000;
|
||||
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
timerInitStructure.TIM_Period = 500;
|
||||
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
timerInitStructure.TIM_RepetitionCounter = 0;
|
||||
TIM_TimeBaseInit (TIM2, &timerInitStructure);
|
||||
TIM_Cmd (TIM2, ENABLE);
|
||||
}
|
||||
|
||||
void
|
||||
fake_exit (void)
|
||||
{
|
||||
uint32_t pin = LED_ORANGE;
|
||||
volatile GPIO_TypeDef* gpio = GPIOD;
|
||||
volatile int index;
|
||||
|
||||
int dot = 600000;
|
||||
int dash = dot * 3;
|
||||
|
||||
while (1)
|
||||
{
|
||||
gpio->BSRRL = (uint16_t) (1 << pin);
|
||||
for ( index = 0; index < dot; index ++)
|
||||
{
|
||||
};
|
||||
gpio->BSRRH = (uint16_t) (1 << pin);
|
||||
for (index = 0; index < dash; index ++)
|
||||
{
|
||||
};
|
||||
}
|
||||
}
|
||||
#ifndef __TARGET_MCU
|
||||
# error "!__TARGET_HOST && !__TARGET_MCU"
|
||||
#endif /* !__TARGET_MCU */
|
||||
|
||||
static __IO uint32_t sys_tick_counter;
|
||||
|
||||
@@ -163,4 +106,49 @@ wait_1ms (void)
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
wait_ms (uint32_t time_ms)
|
||||
{
|
||||
while (time_ms --)
|
||||
{
|
||||
wait_1ms ();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
fake_exit (void)
|
||||
{
|
||||
uint32_t pin = LED_ORANGE;
|
||||
volatile int index;
|
||||
|
||||
int dot = 600000;
|
||||
int dash = dot * 3;
|
||||
|
||||
while (1)
|
||||
{
|
||||
led_on (pin);
|
||||
for ( index = 0; index < dot; index ++)
|
||||
{
|
||||
};
|
||||
led_off (pin);
|
||||
for (index = 0; index < dash; index ++)
|
||||
{
|
||||
};
|
||||
}
|
||||
}
|
||||
void
|
||||
initialize_timer ()
|
||||
{
|
||||
RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM2, ENABLE);
|
||||
|
||||
TIM_TimeBaseInitTypeDef timerInitStructure;
|
||||
timerInitStructure.TIM_Prescaler = 40000;
|
||||
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
timerInitStructure.TIM_Period = 500;
|
||||
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
timerInitStructure.TIM_RepetitionCounter = 0;
|
||||
TIM_TimeBaseInit (TIM2, &timerInitStructure);
|
||||
TIM_Cmd (TIM2, ENABLE);
|
||||
}
|
||||
#endif /* !__TARGET_HOST && __TARGET_MCU */
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/* Copyright 2014 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MCU_HEADERS_H
|
||||
#define MCU_HEADERS_H
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
# ifdef __TARGET_MCU_STM32F4
|
||||
# include "stm32f4xx_conf.h"
|
||||
# include "stm32f4xx.h"
|
||||
|
||||
# define LED_GREEN 0
|
||||
# define LED_ORANGE 1
|
||||
# define LED_RED 2
|
||||
# define LED_BLUE 3
|
||||
# elif defined (__TARGET_MCU_STM32F3)
|
||||
# include "stm32f30x_conf.h"
|
||||
# include "stm32f30x.h"
|
||||
|
||||
# define LED_GREEN 0
|
||||
# define LED_ORANGE 1
|
||||
# define LED_RED 2
|
||||
# define LED_BLUE 3
|
||||
# else /* !__TARGET_MCU_STM32F4 && !__TARGET_MCU_STM32F3 */
|
||||
# error "!__TARGET_MCU_STM32F4 && !__TARGET_MCU_STM32F3"
|
||||
# endif /* !__TARGET_MCU_STM32F4 && !__TARGET_MCU_STM32F3 */
|
||||
#pragma GCC diagnostic pop
|
||||
#endif /* __TARGET_MCU */
|
||||
|
||||
#endif /* !MCU_HEADERS_H */
|
||||
Reference in New Issue
Block a user