Fix more sources to use HAL

This commit is contained in:
iabdalkader 2014-06-18 21:20:22 +02:00
parent 51458b1c2e
commit c1dab26fca
18 changed files with 154 additions and 80 deletions

View File

@ -33,9 +33,9 @@ CFLAGS += -O2 -ggdb3 -DNDEBUG
endif
# Compiler Flags
CFLAGS += -std=gnu99 -Wall -mlittle-endian -mthumb -nostartfiles -mabi=aapcs-linux
CFLAGS += -std=gnu99 -Wall -mlittle-endian -mthumb -nostartfiles -mabi=aapcs-linux -fdata-sections -ffunction-sections
CFLAGS += -fsingle-precision-constant -Wdouble-promotion -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
CFLAGS += -DARM_MATH_CM4 -D__FPU_PRESENT=1 -D__FPU_USED=1 -DUSE_USB_FS -DUSE_DEVICE_MODE -DUSE_USB_OTG_ID=0 -DSTM32F407xx -DHSE_VALUE=12000000
CFLAGS += -DARM_MATH_CM4 -D__FPU_PRESENT=1 -D__FPU_PRESENT -D__FPU_USED=1 -DUSE_USB_FS -DUSE_DEVICE_MODE -DUSE_USB_OTG_ID=0 -DSTM32F407xx -DHSE_VALUE=12000000
CFLAGS += -I. -Iinclude
CFLAGS += -I$(TOP_DIR)/$(CMSIS_DIR)/include/
@ -58,7 +58,7 @@ CFLAGS += -I$(TOP_DIR)/$(OMV_DIR)/img/
# Linker Flags
LDFLAGS = -mcpu=cortex-m4 -mabi=aapcs-linux -mthumb -mlittle-endian -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostdlib -Wl,-T$(OMV_DIR)/stm32f407.ld
LDFLAGS = -mcpu=cortex-m4 -mabi=aapcs-linux -mthumb -mlittle-endian -mfloat-abi=hard -mfpu=fpv4-sp-d16 -nostdlib -Wl,-T$(OMV_DIR)/stm32f407.ld -Wl,--gc-sections
# Sources
#SRC_C = $(addprefix $(CMSIS_DIR)/src/st/,\
@ -67,6 +67,16 @@ LDFLAGS = -mcpu=cortex-m4 -mabi=aapcs-linux -mthumb -mlittle-endian -mfloat-abi=
OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/st/*.o)
OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/CommonTables/*.o)
#OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/ComplexMathFunctions/*.o)
#OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/ControllerFunctions/*.o)
OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/FastMathFunctions/*.o)
#OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/FilteringFunctions/*.o)
OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/MatrixFunctions/*.o)
#OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/StatisticsFunctions/*.o)
#OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/SupportFunctions/*.o)
#OBJ += $(wildcard $(BUILD)/$(CMSIS_DIR)/src/dsp/TransformFunctions/*.o)
OBJ += $(wildcard $(BUILD)/$(STHAL_DIR)/src/*.o)
OBJ += $(wildcard $(BUILD)/$(FATFS_DIR)/src/*.o)
OBJ += $(wildcard $(BUILD)/$(FATFS_DIR)/src/option/*.o)
@ -101,16 +111,12 @@ OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/,\
math.o \
mathsincos.o \
rtc.o \
rng.o \
pin.o \
pin_named_pins.o \
timer.o \
i2c.o \
spi.o \
servo.o\
extint.o \
adc.o \
modos.o \
modstm.o \
modtime.o \
pins_$(TARGET).o \
@ -126,20 +132,43 @@ OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/usbdev/,\
class/cdc_msc_hid/src/usbd_msc_data.o \
)
OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/,\
main.o \
systick.o\
usbdbg.o\
sccb.o\
ov9650.o\
ov2640.o\
sensor.o\
led.o \
OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/, \
main.o \
xalloc.o \
array.o \
usbdbg.o \
systick.o \
sccb.o \
ov9650.o \
ov2640.o \
sensor.o \
led.o \
rng.o \
)
OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/py/,\
py_led.o \
py_sensor.o \
OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/img/,\
blob.o \
fmath.o \
haar.o \
imlib.o \
integral.o \
kmeans.o \
lab.o \
median.o \
point.o \
ppm.o \
rectangle.o \
surf.o \
template.o \
)
OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/py/, \
py_led.o \
py_sensor.o \
py_image.o \
py_file.o \
py_time.o \
py_clock.o \
)
###################################################

View File

@ -1,16 +1,17 @@
# Sources
SRCS = src/st/startup_stm32f407xx.s
#SRCS += $(wildcard src/CommonTables/*.c)
#SRCS += $(wildcard src/ComplexMathFunctions/*.c)
#SRCS += $(wildcard src/ControllerFunctions/*.c)
#SRCS += $(wildcard src/FastMathFunctions/*.c)
#SRCS += $(wildcard src/FilteringFunctions/*.c)
#SRCS += $(wildcard src/MatrixFunctions/*.c)
#SRCS += $(wildcard src/StatisticsFunctions/*.c)
#SRCS += $(wildcard src/SupportFunctions/*.c)
#SRCS += $(wildcard src/TransformFunctions/*.c)
SRC_S = src/st/startup_stm32f407xx.s
SRC_C += $(wildcard src/dsp/CommonTables/*.c)
#SRC_C += $(wildcard src/dsp/ComplexMathFunctions/*.c)
#SRC_C += $(wildcard src/dsp/ControllerFunctions/*.c)
SRC_C += $(wildcard src/dsp/FastMathFunctions/*.c)
#SRC_C += $(wildcard src/dsp/FilteringFunctions/*.c)
SRC_C += $(wildcard src/dsp/MatrixFunctions/*.c)
#SRC_C += $(wildcard src/dsp/StatisticsFunctions/*.c)
#SRC_C += $(wildcard src/dsp/SupportFunctions/*.c)
#SRC_C += $(wildcard src/dsp/TransformFunctions/*.c)
OBJS = $(addprefix $(BUILD)/, $(SRCS:.s=.o))
OBJS = $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJS += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ_DIRS = $(sort $(dir $(OBJS)))
all: | $(OBJ_DIRS) $(OBJS)

View File

@ -1,21 +1,41 @@
# Sources
SRCS += $(addprefix ,\
main.c\
systick.c\
usbdbg.c\
sccb.c\
ov9650.c\
ov2640.c\
sensor.c\
led.c\
SRCS += $(addprefix , \
main.c \
xalloc.c \
array.c \
usbdbg.c \
systick.c \
sccb.c \
ov9650.c \
ov2640.c \
sensor.c \
led.c \
rng.c \
)
SRCS += $(addprefix img/,\
SRCS += $(addprefix img/, \
blob.c \
fmath.c \
haar.c \
imlib.c \
integral.c \
kmeans.c \
lab.c \
median.c \
point.c \
ppm.c \
rectangle.c \
surf.c \
template.c \
)
SRCS += $(addprefix py/,\
py_led.c\
py_sensor.c\
SRCS += $(addprefix py/, \
py_led.c \
py_sensor.c \
py_image.c \
py_file.c \
py_time.c \
py_clock.c \
)
OBJS = $(addprefix $(BUILD)/, $(SRCS:.c=.o))

View File

@ -1,4 +1,3 @@
#include <libmp.h>
#include "xalloc.h"
#include "imlib.h"
#include <arm_math.h>

View File

@ -1,4 +1,5 @@
#include <libmp.h>
#include <ff.h>
#include <stdio.h>
#include "xalloc.h"
#include "imlib.h"
#include <arm_math.h>

View File

@ -1,4 +1,3 @@
#include <libmp.h>
#include "xalloc.h"
#include "imlib.h"
#include <arm_math.h>

View File

@ -1,4 +1,5 @@
#include <libmp.h>
#include <ff.h>
#include <stdio.h>
#include "xalloc.h"
#include "imlib.h"
#include "mdefs.h"

View File

@ -1,4 +1,3 @@
#include <libmp.h>
#include "xalloc.h"
#include "imlib.h"
#include <arm_math.h>

View File

@ -22,21 +22,20 @@
#include "timer.h"
#include "pin.h"
#include "extint.h"
#include "usrsw.h"
#include "usb.h"
#include "rtc.h"
#include "storage.h"
#include "sdcard.h"
#include "ff.h"
#include "lcd.h"
#include "mdefs.h"
#include "led.h"
#include "rng.h"
#include "sensor.h"
#include "usbdbg.h"
#include "led.h"
#include "py_led.h"
#include "sensor.h"
#include "py_time.h"
#include "py_sensor.h"
int errno;
@ -110,12 +109,17 @@ STATIC mp_obj_t pyb_usb_mode(mp_obj_t usb_mode) {
MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_mode_obj, pyb_usb_mode);
STATIC mp_obj_t py_vcp_is_connected(void ) {
return MP_BOOL(usb_vcp_is_connected());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(py_vcp_is_connected_obj, py_vcp_is_connected);
static const char fresh_main_py[] =
"# main.py -- put your code here!\n"
"import led, sensor\n"
"led.on(led.BLUE)\n"
"sensor.set_pixformat(sensor.RGB565)\n"
"while (True):\n"
"while (vcp_is_connected()==False):\n"
" image = sensor.snapshot()\n"
;
@ -146,7 +150,7 @@ typedef struct {
static const module_t exported_modules[] ={
{MP_QSTR_sensor,py_sensor_init},
{MP_QSTR_led, py_led_init},
// {MP_QSTR_time, py_time_init},
{MP_QSTR_time, py_time_init},
// {MP_QSTR_gpio, py_gpio_init},
// {MP_QSTR_spi, py_spi_init},
{0, NULL}
@ -333,15 +337,12 @@ soft_reset:
timer_init0();
rng_init();
usbdbg_init();
#if MICROPY_HW_ENABLE_RNG
//rng_init0();
#endif
/* Add functions to the global python namespace */
// mp_store_global(qstr_from_str("open"), mp_make_function_n(2, py_file_open));
// mp_store_global(qstr_from_str("vcp_connected"), mp_make_function_n(0, py_vcp_connected));
mp_store_global(qstr_from_str("vcp_is_connected"), mp_make_function_n(0, py_vcp_is_connected));
// mp_store_global(qstr_from_str("info"), mp_make_function_n(0, py_info));
// mp_store_global(qstr_from_str("gc_collect"), mp_make_function_n(0, py_gc_collect));
// mp_store_global(qstr_from_str("Image"), mp_make_function_n(1, py_image_load_image));

View File

@ -1,4 +1,4 @@
#include <libmp.h>
#include <mp.h>
#include "systick.h"
#include "py_clock.h"

View File

@ -1,4 +1,4 @@
#include <libmp.h>
#include <mp.h>
#include "py_assert.h"
#include "py_file.h"
typedef struct _py_file_obj_t {

View File

@ -4,6 +4,7 @@
#include "sensor.h"
#include "py_assert.h"
#include "py_image.h"
#include "ff.h"
extern struct sensor_dev sensor;
static const mp_obj_type_t py_cascade_type;

View File

@ -15,11 +15,9 @@ static mp_obj_t py_sensor_reset() {
}
static mp_obj_t py_sensor_snapshot() {
// mp_obj_t image = py_image(0, 0, 0, 0);
// sensor_snapshot((struct image*) py_image_cobj(image));
// return image;
sensor_snapshot(0);
return mp_const_none;
mp_obj_t image = py_image(0, 0, 0, 0);
sensor_snapshot((struct image*) py_image_cobj(image));
return image;
}
static mp_obj_t py_sensor_set_pixformat(mp_obj_t pixformat) {

View File

@ -1,4 +1,4 @@
#include <libmp.h>
#include <mp.h>
#include "systick.h"
#include "py_time.h"
#include "py_clock.h"

View File

@ -1,19 +1,26 @@
#include <stm32f4xx_rng.h>
#include <stm32f4xx_rcc.h>
#include <stm32f4xx_hal.h>
#include "rng.h"
static RNG_HandleTypeDef RNGHandle;
void rng_init()
{
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
RNG_Cmd(ENABLE);
__RNG_CLK_ENABLE();
RNGHandle.Instance = RNG;
__HAL_RNG_ENABLE(&RNGHandle);
}
uint32_t rng_randint(uint32_t min, uint32_t max)
{
uint32_t rand;
uint32_t rand=0;
if (min==max) {
return 0;
}
rand = RNG_GetRandomNumber();
// Wait until the RNG is ready
while (HAL_RNG_GetState(&RNGHandle) != RNG_FLAG_DRDY);
rand = HAL_RNG_GetRandomNumber(&RNGHandle);
return (rand%(max-min))+min;
}

View File

@ -349,11 +349,16 @@ int sensor_snapshot(struct image *image)
/* Enable the Frame capture complete interrupt */
__HAL_DCMI_ENABLE_IT(&DCMIHandle, DCMI_IT_FRAME);
HAL_DCMI_Start_DMA(&DCMIHandle, DCMI_MODE_SNAPSHOT, (uint32_t) fb->pixels, (fb->w * fb->h * 2)/4);
if (sensor.pixformat==PIXFORMAT_GRAYSCALE) {
HAL_DCMI_Start_DMA(&DCMIHandle, DCMI_MODE_SNAPSHOT, (uint32_t) fb->pixels+(fb->w * fb->h), (fb->w * fb->h * 2)/4);
} else {
HAL_DCMI_Start_DMA(&DCMIHandle, DCMI_MODE_SNAPSHOT, (uint32_t) fb->pixels, (fb->w * fb->h * 2)/4);
}
/* Wait for frame */
while (HAL_DCMI_GetState(&DCMIHandle) == HAL_DCMI_STATE_BUSY);
#if 0
if (sensor.pixformat == PIXFORMAT_GRAYSCALE) {
/* Extract Y channel from YUYV */
for (int i=0; i<(fb->w * fb->h); i++) {
@ -361,10 +366,22 @@ int sensor_snapshot(struct image *image)
}
}
// image->w = fb->w;
// image->h = fb->h;
// image->bpp = fb->bpp;
// image->pixels = fb->pixels;
#endif
if (sensor.pixformat == PIXFORMAT_GRAYSCALE) {
int i;
/* extract Y channel */
for (i=0; i<(fb->w * fb->h); i++) {
fb->pixels[i] = fb->pixels[i*2+(fb->w * fb->h)];
}
}
if (image != NULL) {
image->w = fb->w;
image->h = fb->h;
image->bpp = fb->bpp;
image->pixels = fb->pixels;
}
return 0;
}

View File

@ -23,4 +23,5 @@ uint32_t systick_current_millis()
bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms)
{
systick_sleep(delay_ms);
return true;
}

View File

@ -1,4 +1,4 @@
#include <libmp.h>
#include <mp.h>
#include "mdefs.h"
#include "xalloc.h"