Merge remote-tracking branch 'micropython/master'

This commit is contained in:
Scott Shawcroft 2016-08-23 16:51:47 -07:00
commit dea22b0b5d
7 changed files with 47 additions and 13 deletions

View File

@ -133,6 +133,7 @@ STATIC mp_obj_t btree_seq(size_t n_args, const mp_obj_t *args) {
}
int res = __bt_seq(self->db, &key, &val, flags);
CHECK_ERROR(res);
if (res == RET_SPECIAL) {
return mp_const_none;
}

View File

@ -94,8 +94,8 @@ mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode
}
const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) {
mp_obj_base_t *o = (mp_obj_base_t*)MP_OBJ_TO_PTR(self_in);
const mp_stream_p_t *stream_p = o->type->protocol;
mp_obj_type_t *type = mp_obj_get_type(self_in);
const mp_stream_p_t *stream_p = type->protocol;
if (stream_p == NULL
|| ((flags & MP_STREAM_OP_READ) && stream_p->read == NULL)
|| ((flags & MP_STREAM_OP_WRITE) && stream_p->write == NULL)
@ -167,7 +167,7 @@ STATIC mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte fl
// TODO what if we have read only half a non-ASCII char?
vstr_cut_tail_bytes(&vstr, more_bytes - out_sz);
if (out_sz == 0) {
break;
break;
}
}

View File

@ -126,9 +126,6 @@ MP_DECLARE_CONST_FUN_OBJ(pyb_irq_stats_obj);
#define IRQ_PRI_OTG_HS 6
#define IRQ_SUBPRI_OTG_HS 0
#define IRQ_PRI_TIM3 6
#define IRQ_SUBPRI_TIM3 0
#define IRQ_PRI_TIM5 6
#define IRQ_SUBPRI_TIM5 0

View File

@ -556,6 +556,12 @@ void TIM1_TRG_COM_TIM17_IRQHandler(void) {
}
#endif
void TIM1_CC_IRQHandler(void) {
IRQ_ENTER(TIM1_CC_IRQn);
timer_irq_handler(1);
IRQ_EXIT(TIM1_CC_IRQn);
}
void TIM2_IRQHandler(void) {
IRQ_ENTER(TIM2_IRQn);
timer_irq_handler(2);
@ -581,18 +587,23 @@ void TIM5_IRQHandler(void) {
IRQ_EXIT(TIM5_IRQn);
}
#if defined(TIM6) // STM32F401 doesn't have TIM6
void TIM6_DAC_IRQHandler(void) {
IRQ_ENTER(TIM6_DAC_IRQn);
timer_irq_handler(6);
IRQ_EXIT(TIM6_DAC_IRQn);
}
#endif
#if defined(TIM7) // STM32F401 doesn't have TIM7
void TIM7_IRQHandler(void) {
IRQ_ENTER(TIM7_IRQn);
timer_irq_handler(7);
IRQ_EXIT(TIM7_IRQn);
}
#endif
#if defined(TIM8) // STM32F401 doesn't have TIM8
void TIM8_BRK_TIM12_IRQHandler(void) {
IRQ_ENTER(TIM8_BRK_TIM12_IRQn);
timer_irq_handler(12);
@ -614,11 +625,18 @@ void TIM8_UP_IRQHandler(void) {
}
#endif
void TIM8_CC_IRQHandler(void) {
IRQ_ENTER(TIM8_CC_IRQn);
timer_irq_handler(8);
IRQ_EXIT(TIM8_CC_IRQn);
}
void TIM8_TRG_COM_TIM14_IRQHandler(void) {
IRQ_ENTER(TIM8_TRG_COM_TIM14_IRQn);
timer_irq_handler(14);
IRQ_EXIT(TIM8_TRG_COM_TIM14_IRQn);
}
#endif
// UART/USART IRQ handlers
void USART1_IRQHandler(void) {

View File

@ -601,8 +601,15 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, mp_uint_t n_args, c
}
// set IRQ priority (if not a special timer)
if (self->tim_id != 3 && self->tim_id != 5) {
if (self->tim_id != 5) {
HAL_NVIC_SetPriority(self->irqn, IRQ_PRI_TIMX, IRQ_SUBPRI_TIMX);
if (self->tim_id == 1) {
HAL_NVIC_SetPriority(TIM1_CC_IRQn, IRQ_PRI_TIMX, IRQ_SUBPRI_TIMX);
#if defined(TIM8)
} else if (self->tim_id == 8) {
HAL_NVIC_SetPriority(TIM8_CC_IRQn, IRQ_PRI_TIMX, IRQ_SUBPRI_TIMX);
#endif
}
}
// init TIM
@ -932,7 +939,7 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp
if (chan->callback == mp_const_none) {
HAL_TIM_PWM_Start(&self->tim, TIMER_CHANNEL(chan));
} else {
HAL_TIM_PWM_Start_IT(&self->tim, TIMER_CHANNEL(chan));
pyb_timer_channel_callback(chan, chan->callback);
}
// Start the complimentary channel too (if its supported)
if (IS_TIM_CCXN_INSTANCE(self->tim.Instance, TIMER_CHANNEL(chan))) {
@ -970,7 +977,7 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp
if (chan->callback == mp_const_none) {
HAL_TIM_OC_Start(&self->tim, TIMER_CHANNEL(chan));
} else {
HAL_TIM_OC_Start_IT(&self->tim, TIMER_CHANNEL(chan));
pyb_timer_channel_callback(chan, chan->callback);
}
// Start the complimentary channel too (if its supported)
if (IS_TIM_CCXN_INSTANCE(self->tim.Instance, TIMER_CHANNEL(chan))) {
@ -997,7 +1004,7 @@ STATIC mp_obj_t pyb_timer_channel(mp_uint_t n_args, const mp_obj_t *pos_args, mp
if (chan->callback == mp_const_none) {
HAL_TIM_IC_Start(&self->tim, TIMER_CHANNEL(chan));
} else {
HAL_TIM_IC_Start_IT(&self->tim, TIMER_CHANNEL(chan));
pyb_timer_channel_callback(chan, chan->callback);
}
break;
}
@ -1294,7 +1301,16 @@ STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback)
self->callback = mp_const_none;
} else if (mp_obj_is_callable(callback)) {
self->callback = callback;
HAL_NVIC_EnableIRQ(self->timer->irqn);
uint8_t tim_id = self->timer->tim_id;
if (tim_id == 1) {
HAL_NVIC_EnableIRQ(TIM1_CC_IRQn);
#if defined(TIM8) // STM32F401 doesn't have a TIM8
} else if (tim_id == 8) {
HAL_NVIC_EnableIRQ(TIM8_CC_IRQn);
#endif
} else {
HAL_NVIC_EnableIRQ(self->timer->irqn);
}
// start timer, so that it interrupts on overflow
switch (self->mode) {
case CHANNEL_MODE_PWM_NORMAL:

View File

@ -302,7 +302,7 @@ soft_reset:
#endif
#if MICROPY_MODULE_FROZEN
pyexec_frozen_module("boot");
pyexec_frozen_module("boot.py");
#else
if (!pyexec_file("/boot.py")) {
flash_error(4);
@ -314,7 +314,7 @@ soft_reset:
// run main script
#if MICROPY_MODULE_FROZEN
pyexec_frozen_module("main");
pyexec_frozen_module("main.py");
#else
{
vstr_t *vstr = vstr_new();

View File

@ -1,3 +1,5 @@
import pyb
print("Executing main.py")
led = pyb.LED(1)