[dartuino][bootloader] Merge bootloader branch into master.
This commit is contained in:
@@ -38,10 +38,16 @@
|
||||
#include <target/bmi055.h>
|
||||
#include <target/debugconfig.h>
|
||||
#include <target/gpioconfig.h>
|
||||
#include <target/memory_lcd.h>
|
||||
#include <target/sensor_bus.h>
|
||||
#include <reg.h>
|
||||
|
||||
#if ENABLE_LCD
|
||||
#include <target/memory_lcd.h>
|
||||
#endif
|
||||
|
||||
#if ENABLE_SENSORBUS
|
||||
#include <target/sensor_bus.h>
|
||||
#endif
|
||||
|
||||
#if WITH_LIB_MINIP
|
||||
#include <lib/minip.h>
|
||||
#endif
|
||||
@@ -90,16 +96,6 @@ void target_early_init(void)
|
||||
gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_LED114) | GPIO_TO_PIN_MASK(GPIO_LED115);
|
||||
HAL_GPIO_Init(GPIOJ, &gpio_init);
|
||||
|
||||
// Initialize to a pattern just so we know we have something
|
||||
gpio_set(GPIO_LED108, GPIO_LED_ON);
|
||||
gpio_set(GPIO_LED109, GPIO_LED_ON);
|
||||
gpio_set(GPIO_LED110, GPIO_LED_ON);
|
||||
gpio_set(GPIO_LED111, GPIO_LED_ON);
|
||||
gpio_set(GPIO_LED112, GPIO_LED_ON);
|
||||
gpio_set(GPIO_LED113, GPIO_LED_ON);
|
||||
gpio_set(GPIO_LED114, GPIO_LED_ON);
|
||||
gpio_set(GPIO_LED115, GPIO_LED_ON);
|
||||
|
||||
// Initialize the switches GPIOs for interrupt on raising edge. In order
|
||||
// to use stm32_EXTI15_10_IRQ() handler needs to be provided and EXTI15_10_IRQn
|
||||
// needs to be enabled.
|
||||
@@ -112,8 +108,10 @@ void target_early_init(void)
|
||||
GPIO_TO_PIN_MASK(GPIO_SW102) | GPIO_TO_PIN_MASK(GPIO_SW103);
|
||||
HAL_GPIO_Init(GPIOJ, &gpio_init);
|
||||
|
||||
#if ENABLE_SENSORBUS
|
||||
// Initialize Sensor bus (accelerometer / gyroscope / nrf51 spi bus
|
||||
sensor_bus_init_early();
|
||||
#endif
|
||||
|
||||
// now that the uart gpios are configured, enable the debug uart.
|
||||
stm32_debug_early_init();
|
||||
@@ -132,7 +130,9 @@ void target_init(void)
|
||||
|
||||
qspi_flash_init(N25Q128A_FLASH_SIZE);
|
||||
|
||||
#if ENABLE_LCD
|
||||
memory_lcd_init();
|
||||
#endif
|
||||
|
||||
#if WITH_LIB_MINIP
|
||||
uint8_t mac_addr[6];
|
||||
@@ -164,7 +164,9 @@ void target_init(void)
|
||||
// start usb
|
||||
target_usb_setup();
|
||||
|
||||
#if ENABLE_SENSORBUS
|
||||
sensor_bus_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
|
||||
@@ -203,7 +205,6 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_12;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
|
||||
/*##-3- Configure the NVIC for SPI #########################################*/
|
||||
/* NVIC for SPI */
|
||||
HAL_NVIC_EnableIRQ(SPI2_IRQn);
|
||||
|
||||
51
target/dartuinoP0/projects/bootloader/bootloader_stubs.c
Normal file
51
target/dartuinoP0/projects/bootloader/bootloader_stubs.c
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2016 Google Inc. All Rights Reserved.
|
||||
* Author: gkalsi@google.com (Gurjant Kalsi)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
static char bootloader_primary_flash_name[] = "flash0";
|
||||
static char bootloader_secondary_flash_name[] = "qspi-flash";
|
||||
static char bootloader_mount_point[] = "/spifs";
|
||||
|
||||
#include <lib/fs.h>
|
||||
#include <err.h>
|
||||
#include <app/moot/stubs.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define BOOTLOADER_SIZE_KB (64)
|
||||
#define SYSTEM_FLASH_SIZE_KB (1024)
|
||||
|
||||
status_t moot_mount_default_fs(char **mount_path, char **device_name)
|
||||
{
|
||||
*mount_path = bootloader_mount_point;
|
||||
*device_name = bootloader_secondary_flash_name;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
const moot_sysinfo_t moot_system_info = {
|
||||
.sys_base_addr = 0x00210000,
|
||||
.btldr_offset = 0x0,
|
||||
.bootloader_len = 1024 * BOOTLOADER_SIZE_KB,
|
||||
.system_offset = 1024 * BOOTLOADER_SIZE_KB,
|
||||
.system_len = (1024 * (SYSTEM_FLASH_SIZE_KB - BOOTLOADER_SIZE_KB)),
|
||||
.system_flash_name = bootloader_primary_flash_name,
|
||||
};
|
||||
12
target/dartuinoP0/projects/bootloader/rules.mk
Normal file
12
target/dartuinoP0/projects/bootloader/rules.mk
Normal file
@@ -0,0 +1,12 @@
|
||||
LOCAL_DIR := $(GET_LOCAL_DIR)
|
||||
|
||||
MODULE := $(LOCAL_DIR)
|
||||
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/bootloader_stubs.c
|
||||
|
||||
|
||||
MODULE_DEPS += \
|
||||
lib/fs
|
||||
|
||||
include make/module.mk
|
||||
8
target/dartuinoP0/projects/system/rules.mk
Normal file
8
target/dartuinoP0/projects/system/rules.mk
Normal file
@@ -0,0 +1,8 @@
|
||||
LOCAL_DIR := $(GET_LOCAL_DIR)
|
||||
|
||||
MODULE := $(LOCAL_DIR)
|
||||
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/system_stubs.c
|
||||
|
||||
include make/module.mk
|
||||
28
target/dartuinoP0/projects/system/system_stubs.c
Normal file
28
target/dartuinoP0/projects/system/system_stubs.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2016 Google Inc. All Rights Reserved.
|
||||
* Author: gkalsi@google.com (Gurjant Kalsi)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
void append_usb_interfaces(void)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
@@ -9,8 +9,6 @@ PLATFORM := stm32f7xx
|
||||
SDRAM_SIZE := 0x00800000
|
||||
SDRAM_BASE := 0xc0000000
|
||||
|
||||
DISPLAY_PANEL_TYPE ?= LS013B7DH06
|
||||
|
||||
GLOBAL_DEFINES += \
|
||||
ENABLE_UART3=1 \
|
||||
ENABLE_SDRAM=1 \
|
||||
@@ -25,43 +23,15 @@ GLOBAL_DEFINES += \
|
||||
\
|
||||
TARGET_HAS_DEBUG_LED=1
|
||||
|
||||
MODULE_DEPS += \
|
||||
app/accelerometer \
|
||||
|
||||
GLOBAL_INCLUDES += $(LOCAL_DIR)/include
|
||||
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/init.c \
|
||||
$(LOCAL_DIR)/sensor_bus.c \
|
||||
$(LOCAL_DIR)/usb.c \
|
||||
|
||||
ifneq ($(DISPLAY_PANEL_TYPE),)
|
||||
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/memory_lcd.c
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(DISPLAY_PANEL_TYPE),LS013B7DH06)
|
||||
|
||||
GLOBAL_DEFINES += \
|
||||
LCD_LS013B7DH06=1
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/display/LS013B7DH06.c
|
||||
|
||||
else ifeq ($(DISPLAY_PANEL_TYPE),LS027B7DH01)
|
||||
|
||||
GLOBAL_DEFINES += \
|
||||
LCD_LS027B7DH01=1
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/display/memory_lcd_mono.c
|
||||
|
||||
else ifeq ($(DISPLAY_PANEL_TYPE),LS013B7DH03)
|
||||
GLOBAL_DEFINES += \
|
||||
LCD_LS013B7DH03=1
|
||||
MODULE_SRCS += \
|
||||
$(LOCAL_DIR)/display/memory_lcd_mono.c
|
||||
endif
|
||||
MODULE_DEPS += \
|
||||
dev/usb
|
||||
|
||||
include make/module.mk
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#define W(w) (w & 0xff), (w >> 8)
|
||||
#define W3(w) (w & 0xff), ((w >> 8) & 0xff), ((w >> 16) & 0xff)
|
||||
|
||||
extern void append_usb_interfaces(void);
|
||||
|
||||
/* top level device descriptor */
|
||||
static const uint8_t dev_descr[] = {
|
||||
0x12, /* descriptor length */
|
||||
@@ -80,34 +82,6 @@ static const uint8_t cfg_descr[] = {
|
||||
|
||||
static const uchar langid[] = { 0x04, 0x03, 0x09, 0x04 };
|
||||
|
||||
static const uint8_t if_descriptor_lowspeed[] = {
|
||||
0x09, /* length */
|
||||
INTERFACE, /* type */
|
||||
0x01, /* interface num */
|
||||
0x00, /* alternates */
|
||||
0x02, /* endpoint count */
|
||||
0xff, /* interface class */
|
||||
0xff, /* interface subclass */
|
||||
0x00, /* interface protocol */
|
||||
0x00, /* string index */
|
||||
|
||||
/* endpoint 1 IN */
|
||||
0x07, /* length */
|
||||
ENDPOINT, /* type */
|
||||
0x81, /* address: 1 IN */
|
||||
0x02, /* type: bulk */
|
||||
W(64), /* max packet size: 64 */
|
||||
00, /* interval */
|
||||
|
||||
/* endpoint 1 OUT */
|
||||
0x07, /* length */
|
||||
ENDPOINT, /* type */
|
||||
0x01, /* address: 1 OUT */
|
||||
0x02, /* type: bulk */
|
||||
W(64), /* max packet size: 64 */
|
||||
00, /* interval */
|
||||
};
|
||||
|
||||
usb_config config = {
|
||||
.lowspeed = {
|
||||
.device = USB_DESC_STATIC(dev_descr),
|
||||
@@ -123,97 +97,15 @@ usb_config config = {
|
||||
.langid = USB_DESC_STATIC(langid),
|
||||
};
|
||||
|
||||
static status_t ep_cb_rx(ep_t endpoint, usbc_transfer_t *t);
|
||||
static status_t ep_cb_tx(ep_t endpoint, usbc_transfer_t *t);
|
||||
|
||||
static void queue_rx(void)
|
||||
{
|
||||
static usbc_transfer_t transfer;
|
||||
static uint8_t buf[512];
|
||||
|
||||
transfer.callback = &ep_cb_rx;
|
||||
transfer.result = 0;
|
||||
transfer.buf = &buf;
|
||||
transfer.buflen = sizeof(buf);
|
||||
transfer.bufpos = 0;
|
||||
transfer.extra = 0;
|
||||
|
||||
usbc_queue_rx(1, &transfer);
|
||||
}
|
||||
|
||||
static void queue_tx(void)
|
||||
{
|
||||
static usbc_transfer_t transfer;
|
||||
static uint8_t buf[512];
|
||||
|
||||
for (uint i = 0; i < sizeof(buf); i++) {
|
||||
buf[i] = ~i;
|
||||
}
|
||||
|
||||
transfer.callback = &ep_cb_tx;
|
||||
transfer.result = 0;
|
||||
transfer.buf = &buf;
|
||||
transfer.buflen = sizeof(buf);
|
||||
transfer.bufpos = 0;
|
||||
transfer.extra = 0;
|
||||
|
||||
usbc_queue_tx(1, &transfer);
|
||||
}
|
||||
|
||||
static status_t ep_cb_rx(ep_t endpoint, usbc_transfer_t *t)
|
||||
{
|
||||
#if LOCAL_TRACE
|
||||
LTRACEF("ep %u transfer %p\n", endpoint, t);
|
||||
usbc_dump_transfer(t);
|
||||
|
||||
if (t->result >= 0) {
|
||||
hexdump8(t->buf, t->bufpos);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (t->result >= 0)
|
||||
queue_rx();
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
static status_t ep_cb_tx(ep_t endpoint, usbc_transfer_t *t)
|
||||
{
|
||||
#if LOCAL_TRACE
|
||||
LTRACEF("ep %u transfer %p\n", endpoint, t);
|
||||
usbc_dump_transfer(t);
|
||||
#endif
|
||||
|
||||
if (t->result >= 0)
|
||||
queue_tx();
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
static status_t usb_cb(void *cookie, usb_callback_op_t op, const union usb_callback_args *args)
|
||||
{
|
||||
LTRACEF("cookie %p, op %u, args %p\n", cookie, op, args);
|
||||
|
||||
if (op == USB_CB_ONLINE) {
|
||||
usbc_setup_endpoint(1, USB_IN, 0x40);
|
||||
usbc_setup_endpoint(1, USB_OUT, 0x40);
|
||||
|
||||
queue_rx();
|
||||
queue_tx();
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
void target_usb_setup(void)
|
||||
{
|
||||
usb_setup(&config);
|
||||
|
||||
printf("appending interfaces\n");
|
||||
usb_append_interface_lowspeed(if_descriptor_lowspeed, sizeof(if_descriptor_lowspeed));
|
||||
usb_append_interface_highspeed(if_descriptor_lowspeed, sizeof(if_descriptor_lowspeed));
|
||||
append_usb_interfaces();
|
||||
|
||||
usb_add_string("LK", 1);
|
||||
usb_add_string("LK Industries", 2);
|
||||
|
||||
usb_register_callback(&usb_cb, NULL);
|
||||
usb_start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user