diff options
| -rw-r--r-- | py/objexcept.c | 10 | ||||
| -rw-r--r-- | py/qstrdefs.h | 23 | ||||
| -rw-r--r-- | py/runtime.c | 10 | ||||
| -rw-r--r-- | stmhal/Makefile | 1 | ||||
| -rw-r--r-- | stmhal/input.c | 25 | ||||
| -rw-r--r-- | stmhal/led.c | 85 | ||||
| -rw-r--r-- | stmhal/main.c | 4 | ||||
| -rw-r--r-- | stmhal/mpconfigport.h | 2 | ||||
| -rw-r--r-- | stmhal/pybmodule.c | 13 | ||||
| -rw-r--r-- | stmhal/qstrdefsport.h | 3 | ||||
| -rw-r--r-- | stmhal/stm32f4xx_hal_msp.c | 57 | ||||
| -rw-r--r-- | stmhal/stm32f4xx_it.c | 3 | ||||
| -rw-r--r-- | stmhal/usbd_cdc_interface.c | 50 | ||||
| -rw-r--r-- | stmhal/usbd_cdc_interface.h | 12 |
14 files changed, 161 insertions, 137 deletions
diff --git a/py/objexcept.c b/py/objexcept.c index 7fd783b3a..de9bf1694 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -107,23 +107,23 @@ MP_DEFINE_EXCEPTION(Exception, BaseException) MP_DEFINE_EXCEPTION_BASE(NameError) MP_DEFINE_EXCEPTION(UnboundLocalError, NameError) MP_DEFINE_EXCEPTION(OSError, Exception) + MP_DEFINE_EXCEPTION_BASE(OSError) // Probably don't need these - /*MP_DEFINE_EXCEPTION_BASE(OSError) - MP_DEFINE_EXCEPTION(BlockingIOError, OSError) + /*MP_DEFINE_EXCEPTION(BlockingIOError, OSError) MP_DEFINE_EXCEPTION(ChildProcessError, OSError) MP_DEFINE_EXCEPTION(ConnectionError, OSError) MP_DEFINE_EXCEPTION(BrokenPipeError, ConnectionError) MP_DEFINE_EXCEPTION(ConnectionAbortedError, ConnectionError) MP_DEFINE_EXCEPTION(ConnectionRefusedError, ConnectionError) MP_DEFINE_EXCEPTION(ConnectionResetError, ConnectionError) - MP_DEFINE_EXCEPTION(FileExistsError, OSError) - MP_DEFINE_EXCEPTION(FileNotFoundError, OSError) MP_DEFINE_EXCEPTION(InterruptedError, OSError) MP_DEFINE_EXCEPTION(IsADirectoryError, OSError) MP_DEFINE_EXCEPTION(NotADirectoryError, OSError) MP_DEFINE_EXCEPTION(PermissionError, OSError) MP_DEFINE_EXCEPTION(ProcessLookupError, OSError) MP_DEFINE_EXCEPTION(TimeoutError, OSError)*/ + MP_DEFINE_EXCEPTION(FileExistsError, OSError) + MP_DEFINE_EXCEPTION(FileNotFoundError, OSError) MP_DEFINE_EXCEPTION(ReferenceError, Exception) MP_DEFINE_EXCEPTION(RuntimeError, Exception) MP_DEFINE_EXCEPTION_BASE(RuntimeError) @@ -137,6 +137,7 @@ MP_DEFINE_EXCEPTION(Exception, BaseException) MP_DEFINE_EXCEPTION(TypeError, Exception) MP_DEFINE_EXCEPTION(ValueError, Exception) //TODO: Implement UnicodeErrors which take arguments + /* MP_DEFINE_EXCEPTION(Warning, Exception) MP_DEFINE_EXCEPTION_BASE(Warning) MP_DEFINE_EXCEPTION(DeprecationWarning, Warning) @@ -149,6 +150,7 @@ MP_DEFINE_EXCEPTION(Exception, BaseException) MP_DEFINE_EXCEPTION(UnicodeWarning, Warning) MP_DEFINE_EXCEPTION(BytesWarning, Warning) MP_DEFINE_EXCEPTION(ResourceWarning, Warning) + */ mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type) { return mp_obj_new_exception_msg_varg(exc_type, NULL); diff --git a/py/qstrdefs.h b/py/qstrdefs.h index b30177acf..898e67582 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -37,56 +37,33 @@ Q(BaseException) Q(ArithmeticError) Q(AssertionError) Q(AttributeError) -Q(BlockingIOError) -Q(BrokenPipeError) Q(BufferError) -Q(BytesWarning) -Q(ChildProcessError) -Q(ConnectionAbortedError) -Q(ConnectionError) -Q(ConnectionRefusedError) -Q(ConnectionResetError) -Q(DeprecationWarning) Q(EOFError) Q(EnvironmentError) Q(Exception) Q(FileExistsError) Q(FileNotFoundError) Q(FloatingPointError) -Q(FutureWarning) Q(GeneratorExit) Q(IOError) Q(ImportError) -Q(ImportWarning) Q(IndentationError) Q(IndexError) -Q(InterruptedError) -Q(IsADirectoryError) Q(KeyError) Q(LookupError) Q(MemoryError) Q(NameError) -Q(NotADirectoryError) Q(NotImplementedError) Q(OSError) Q(OverflowError) -Q(PendingDeprecationWarning) -Q(PermissionError) -Q(ProcessLookupError) Q(ReferenceError) -Q(ResourceWarning) Q(RuntimeError) -Q(RuntimeWarning) Q(SyntaxError) -Q(SyntaxWarning) Q(SystemError) Q(SystemExit) Q(TabError) -Q(TimeoutError) Q(TypeError) Q(UnboundLocalError) -Q(UnicodeWarning) -Q(UserWarning) Q(ValueError) Q(Warning) Q(ZeroDivisionError) diff --git a/py/runtime.c b/py/runtime.c index 03b662798..3a613eaf2 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -149,17 +149,13 @@ STATIC const mp_builtin_elem_t builtin_table[] = { { MP_QSTR_AssertionError, (mp_obj_t)&mp_type_AssertionError }, { MP_QSTR_AttributeError, (mp_obj_t)&mp_type_AttributeError }, { MP_QSTR_BufferError, (mp_obj_t)&mp_type_BufferError }, - { MP_QSTR_BytesWarning, (mp_obj_t)&mp_type_BytesWarning }, - { MP_QSTR_DeprecationWarning, (mp_obj_t)&mp_type_DeprecationWarning }, { MP_QSTR_EOFError, (mp_obj_t)&mp_type_EOFError }, { MP_QSTR_EnvironmentError, (mp_obj_t)&mp_type_EnvironmentError }, { MP_QSTR_Exception, (mp_obj_t)&mp_type_Exception }, { MP_QSTR_FloatingPointError, (mp_obj_t)&mp_type_FloatingPointError }, - { MP_QSTR_FutureWarning, (mp_obj_t)&mp_type_FutureWarning }, { MP_QSTR_GeneratorExit, (mp_obj_t)&mp_type_GeneratorExit }, { MP_QSTR_IOError, (mp_obj_t)&mp_type_IOError }, { MP_QSTR_ImportError, (mp_obj_t)&mp_type_ImportError }, - { MP_QSTR_ImportWarning, (mp_obj_t)&mp_type_ImportWarning }, { MP_QSTR_IndentationError, (mp_obj_t)&mp_type_IndentationError }, { MP_QSTR_IndexError, (mp_obj_t)&mp_type_IndexError }, { MP_QSTR_KeyError, (mp_obj_t)&mp_type_KeyError }, @@ -169,21 +165,15 @@ STATIC const mp_builtin_elem_t builtin_table[] = { { MP_QSTR_NotImplementedError, (mp_obj_t)&mp_type_NotImplementedError }, { MP_QSTR_OSError, (mp_obj_t)&mp_type_OSError }, { MP_QSTR_OverflowError, (mp_obj_t)&mp_type_OverflowError }, - { MP_QSTR_PendingDeprecationWarning, (mp_obj_t)&mp_type_PendingDeprecationWarning }, { MP_QSTR_ReferenceError, (mp_obj_t)&mp_type_ReferenceError }, - { MP_QSTR_ResourceWarning, (mp_obj_t)&mp_type_ResourceWarning }, { MP_QSTR_RuntimeError, (mp_obj_t)&mp_type_RuntimeError }, - { MP_QSTR_RuntimeWarning, (mp_obj_t)&mp_type_RuntimeWarning }, { MP_QSTR_SyntaxError, (mp_obj_t)&mp_type_SyntaxError }, - { MP_QSTR_SyntaxWarning, (mp_obj_t)&mp_type_SyntaxWarning }, { MP_QSTR_SystemError, (mp_obj_t)&mp_type_SystemError }, { MP_QSTR_SystemExit, (mp_obj_t)&mp_type_SystemExit }, { MP_QSTR_TabError, (mp_obj_t)&mp_type_TabError }, { MP_QSTR_TypeError, (mp_obj_t)&mp_type_TypeError }, { MP_QSTR_UnboundLocalError, (mp_obj_t)&mp_type_UnboundLocalError }, - { MP_QSTR_UserWarning, (mp_obj_t)&mp_type_UserWarning }, { MP_QSTR_ValueError, (mp_obj_t)&mp_type_ValueError }, - { MP_QSTR_Warning, (mp_obj_t)&mp_type_Warning }, { MP_QSTR_ZeroDivisionError, (mp_obj_t)&mp_type_ZeroDivisionError }, { MP_QSTR_StopIteration, (mp_obj_t)&mp_type_StopIteration }, // Somehow CPython managed to have OverflowError not inherit from ValueError ;-/ diff --git a/stmhal/Makefile b/stmhal/Makefile index 938871aef..292bfdd61 100644 --- a/stmhal/Makefile +++ b/stmhal/Makefile @@ -72,6 +72,7 @@ SRC_C = \ malloc0.c \ gccollect.c \ pyexec.c \ + input.c \ pybmodule.c \ osmodule.c \ timemodule.c \ diff --git a/stmhal/input.c b/stmhal/input.c new file mode 100644 index 000000000..f53018a42 --- /dev/null +++ b/stmhal/input.c @@ -0,0 +1,25 @@ +#include "nlr.h" +#include "misc.h" +#include "mpconfig.h" +#include "qstr.h" +#include "obj.h" +#include "usb.h" + +extern int readline(vstr_t *line, const char *prompt); + +STATIC mp_obj_t mp_builtin_input(uint n_args, const mp_obj_t *args) { + if (n_args == 1) { + mp_obj_print(args[0], PRINT_REPR); + } + vstr_t line; + vstr_init(&line, 16); + int ret = readline(&line, ""); + if (line.len == 0 && ret == VCP_CHAR_CTRL_D) { + nlr_jump(mp_obj_new_exception(&mp_type_EOFError)); + } + mp_obj_t o = mp_obj_new_str((const byte*)line.buf, line.len, false); + vstr_clear(&line); + return o; +} + +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj, 0, 1, mp_builtin_input); diff --git a/stmhal/led.c b/stmhal/led.c index 80c1e145f..e9a97d1de 100644 --- a/stmhal/led.c +++ b/stmhal/led.c @@ -1,10 +1,13 @@ #include <stdio.h> #include <stm32f4xx_hal.h> +#include "usbd_cdc_msc.h" +#include "usbd_cdc_interface.h" #include "misc.h" #include "mpconfig.h" #include "qstr.h" #include "obj.h" +#include "runtime.h" #include "led.h" #include "pin.h" #include "build/pins.h" @@ -38,12 +41,43 @@ void led_init(void) { GPIO_InitStructure.Pin = gLed[led]->pin_mask; HAL_GPIO_Init(gLed[led]->gpio, &GPIO_InitStructure); } + + // LED4 (blue) is on PB4 which is TIM3_CH1 + // we use PWM on this channel to fade the LED + + // GPIO configuration + GPIO_InitStructure.Pin = GPIO_PIN_4; + GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.Speed = GPIO_SPEED_FAST; + GPIO_InitStructure.Pull = GPIO_NOPULL; + GPIO_InitStructure.Alternate = GPIO_AF2_TIM3; + HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); + + // PWM mode configuration + TIM_OC_InitTypeDef oc_init; + oc_init.OCMode = TIM_OCMODE_PWM1; + oc_init.Pulse = 0; // off + oc_init.OCPolarity = TIM_OCPOLARITY_HIGH; + oc_init.OCFastMode = TIM_OCFAST_DISABLE; + HAL_TIM_PWM_ConfigChannel(&TIM3_Handle, &oc_init, TIM_CHANNEL_1); + + // start PWM + TIM_CCxChannelCmd(TIM3, TIM_CHANNEL_1, TIM_CCx_ENABLE); + //HAL_TIM_PWM_Start(&USBD_CDC_TIM3_Handle, TIM_CHANNEL_1); } void led_state(pyb_led_t led, int state) { if (led < 1 || led > NUM_LEDS) { return; } + if (led == 4) { + if (state) { + TIM3->CCR1 = 0xffff; + } else { + TIM3->CCR1 = 0; + } + return; + } const pin_obj_t *led_pin = gLed[led - 1]; //printf("led_state(%d,%d)\n", led, state); if (state == 0) { @@ -73,6 +107,23 @@ void led_toggle(pyb_led_t led) { } } +int led_get_state(pyb_led_t led) { + if (led < 1 || led > NUM_LEDS) { + return 0; + } + const pin_obj_t *led_pin = gLed[led - 1]; + GPIO_TypeDef *gpio = led_pin->gpio; + + // TODO convert high/low to on/off depending on board + if (gpio->ODR & led_pin->pin_mask) { + // pin is high + return 1; + } else { + // pin is low + return 0; + } +} + void led_debug(int n, int delay) { led_state(1, n & 1); led_state(2, n & 2); @@ -112,25 +163,47 @@ mp_obj_t led_obj_toggle(mp_obj_t self_in) { return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on); -static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); -static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle); +mp_obj_t led_obj_state(uint n_args, const mp_obj_t *args) { + pyb_led_obj_t *self = args[0]; + if (n_args == 0) { + return MP_BOOL(led_get_state(self->led_id)); + } else { + led_state(self->led_id, rt_is_true(args[1])); + return mp_const_none; + } +} + +mp_obj_t led_obj_intensity(mp_obj_t self_in, mp_obj_t intensity) { + pyb_led_obj_t *self = self_in; + if (self->led_id == 4) { + TIM3->CCR1 = mp_obj_get_int(intensity); + } + return mp_const_none; +} + +STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(led_obj_toggle_obj, led_obj_toggle); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(led_obj_state_obj, 1, 2, led_obj_state); +STATIC MP_DEFINE_CONST_FUN_OBJ_2(led_obj_intensity_obj, led_obj_intensity); -static const mp_method_t led_methods[] = { +STATIC const mp_method_t led_methods[] = { { "on", &led_obj_on_obj }, { "off", &led_obj_off_obj }, { "toggle", &led_obj_toggle_obj }, + { "state", &led_obj_state_obj }, + { "intensity", &led_obj_intensity_obj }, { NULL, NULL }, }; -static const mp_obj_type_t led_obj_type = { +STATIC const mp_obj_type_t led_obj_type = { { &mp_type_type }, .name = MP_QSTR_Led, .print = led_obj_print, .methods = led_methods, }; -static mp_obj_t pyb_Led(mp_obj_t led_id) { +STATIC mp_obj_t pyb_Led(mp_obj_t led_id) { pyb_led_obj_t *o = m_new_obj(pyb_led_obj_t); o->base.type = &led_obj_type; o->led_id = mp_obj_get_int(led_id); diff --git a/stmhal/main.c b/stmhal/main.c index 6511891a1..9d8820697 100644 --- a/stmhal/main.c +++ b/stmhal/main.c @@ -37,10 +37,10 @@ #include "lcd.h" #include "accel.h" #include "servo.h" +#include "pin.h" #if 0 #include "timer.h" #include "pybwlan.h" -#include "pin.h" #endif void SystemClock_Config(void); @@ -266,9 +266,7 @@ soft_reset: #endif #endif -#if 0 pin_map_init(); -#endif // add some functions to the builtin Python namespace rt_store_name(MP_QSTR_help, rt_make_function_n(0, pyb_help)); diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index 8ff801335..59c91942a 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -19,8 +19,10 @@ #define MICROPY_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */ // extra built in names to add to the global namespace +extern const struct _mp_obj_fun_native_t mp_builtin_input_obj; extern const struct _mp_obj_fun_native_t mp_builtin_open_obj; #define MICROPY_EXTRA_BUILTINS \ + { MP_QSTR_input, (mp_obj_t)&mp_builtin_input_obj }, \ { MP_QSTR_open, (mp_obj_t)&mp_builtin_open_obj }, // type definitions for the specific machine diff --git a/stmhal/pybmodule.c b/stmhal/pybmodule.c index 09cdf83b8..772732984 100644 --- a/stmhal/pybmodule.c +++ b/stmhal/pybmodule.c @@ -196,12 +196,20 @@ STATIC mp_obj_t pyb_hid_send_report(mp_obj_t arg) { return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(pyb_hid_send_report_obj, pyb_hid_send_report); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_hid_send_report_obj, pyb_hid_send_report); #if 0 MP_DEFINE_CONST_FUN_OBJ_2(pyb_I2C_obj, pyb_I2C); // TODO put this in i2c.c #endif +extern int stdin_rx_chr(void); + +STATIC mp_obj_t pyb_input(void ) { + return mp_obj_new_int(stdin_rx_chr()); +} + +STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_input_obj, pyb_input); + MP_DECLARE_CONST_FUN_OBJ(pyb_source_dir_obj); // defined in main.c MP_DECLARE_CONST_FUN_OBJ(pyb_main_obj); // defined in main.c @@ -268,6 +276,9 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = { #endif #endif + // input + { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&pyb_input_obj }, + // pin mapper { MP_OBJ_NEW_QSTR(MP_QSTR_Pin), (mp_obj_t)&pin_map_obj }, diff --git a/stmhal/qstrdefsport.h b/stmhal/qstrdefsport.h index 9961102a3..55d4b1b09 100644 --- a/stmhal/qstrdefsport.h +++ b/stmhal/qstrdefsport.h @@ -70,3 +70,6 @@ Q(urandom) // for time module Q(time) Q(sleep) + +// for input +Q(input) diff --git a/stmhal/stm32f4xx_hal_msp.c b/stmhal/stm32f4xx_hal_msp.c index c64f37795..a8587c384 100644 --- a/stmhal/stm32f4xx_hal_msp.c +++ b/stmhal/stm32f4xx_hal_msp.c @@ -5,16 +5,7 @@ * @version V1.0.1
* @date 26-February-2014
* @brief HAL MSP module.
- *
- @verbatim
- ===============================================================================
- ##### How to use this driver #####
- ===============================================================================
- [..]
- This file is generated automatically by MicroXplorer and eventually modified
- by the user
-
- @endverbatim
+ *
******************************************************************************
* @attention
*
@@ -56,25 +47,7 @@ #include "obj.h"
#include "servo.h"
-/** @addtogroup STM32F4xx_HAL_Driver
- * @{
- */
-
-/** @defgroup HAL_MSP
- * @brief HAL MSP module.
- * @{
- */
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-
-/** @defgroup HAL_MSP_Private_Functions
- * @{
- */
+TIM_HandleTypeDef TIM3_Handle;
/**
* @brief Initializes the Global MSP.
@@ -83,9 +56,21 @@ */
void HAL_MspInit(void) {
// set up the timer for USBD CDC
- USBD_CDC_TIMx_CLK_ENABLE();
- HAL_NVIC_SetPriority(USBD_CDC_TIMx_IRQn, 6, 0);
- HAL_NVIC_EnableIRQ(USBD_CDC_TIMx_IRQn);
+ __TIM3_CLK_ENABLE();
+
+ TIM3_Handle.Instance = TIM3;
+ TIM3_Handle.Init.Period = (USBD_CDC_POLLING_INTERVAL*1000) - 1;
+ TIM3_Handle.Init.Prescaler = 84-1;
+ TIM3_Handle.Init.ClockDivision = 0;
+ TIM3_Handle.Init.CounterMode = TIM_COUNTERMODE_UP;
+ HAL_TIM_Base_Init(&TIM3_Handle);
+
+ HAL_NVIC_SetPriority(TIM3_IRQn, 6, 0);
+ HAL_NVIC_EnableIRQ(TIM3_IRQn);
+
+ if (HAL_TIM_Base_Start(&TIM3_Handle) != HAL_OK) {
+ /* Starting Error */
+ }
}
/**
@@ -94,9 +79,9 @@ void HAL_MspInit(void) { * @retval None
*/
void HAL_MspDeInit(void) {
- // reset USBD CDC timer
- USBD_CDC_TIMx_FORCE_RESET();
- USBD_CDC_TIMx_RELEASE_RESET();
+ // reset TIM3 timer
+ __TIM3_FORCE_RESET();
+ __TIM3_RELEASE_RESET();
}
/**
@@ -162,7 +147,7 @@ void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc) }
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
- if (htim == &USBD_CDC_TIM3_Handle) {
+ if (htim == &TIM3_Handle) {
USBD_CDC_HAL_TIM_PeriodElapsedCallback();
} else if (htim == &servo_TIM2_Handle) {
servo_timer_irq_callback();
diff --git a/stmhal/stm32f4xx_it.c b/stmhal/stm32f4xx_it.c index 30ded5f7b..cfd24dd33 100644 --- a/stmhal/stm32f4xx_it.c +++ b/stmhal/stm32f4xx_it.c @@ -357,8 +357,7 @@ void TIM2_IRQHandler(void) { }
void TIM3_IRQHandler(void) {
- // USBD CDC timer is TIM3
- HAL_TIM_IRQHandler(&USBD_CDC_TIM3_Handle);
+ HAL_TIM_IRQHandler(&TIM3_Handle);
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/stmhal/usbd_cdc_interface.c b/stmhal/usbd_cdc_interface.c index e190e3479..8a2470c85 100644 --- a/stmhal/usbd_cdc_interface.c +++ b/stmhal/usbd_cdc_interface.c @@ -65,8 +65,6 @@ static uint16_t UserTxBufPtrOut = 0; // increment this pointer modulo APP_TX_DAT static int user_interrupt_char = VCP_CHAR_NONE; static void *user_interrupt_data = NULL; -/* TIM handler declaration */ -TIM_HandleTypeDef USBD_CDC_TIM3_Handle; /* USB handler declaration */ extern USBD_HandleTypeDef hUSBDDevice; @@ -76,8 +74,6 @@ static int8_t CDC_Itf_DeInit (void); static int8_t CDC_Itf_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length); static int8_t CDC_Itf_Receive (uint8_t* pbuf, uint32_t *Len); -static void TIM_Config(void); - const USBD_CDC_ItfTypeDef USBD_CDC_fops = { CDC_Itf_Init, CDC_Itf_DeInit, @@ -125,21 +121,19 @@ static int8_t CDC_Itf_Init(void) /* Transfer error in reception process */ Error_Handler(); } -#endif /*##-3- Configure the TIM Base generation #################################*/ + now done in HAL_MspInit TIM_Config(); +#endif - /*##-4- Start the TIM Base generation in interrupt mode ####################*/ - /* Start Channel1 */ - if(HAL_TIM_Base_Start_IT(&USBD_CDC_TIM3_Handle) != HAL_OK) - { - /* Starting Error */ - } + /*##-4- Start the TIM Base generation in interrupt mode ####################*/ + /* Start Channel1 */ + __HAL_TIM_ENABLE_IT(&TIM3_Handle, TIM_IT_UPDATE); - /*##-5- Set Application Buffers ############################################*/ - USBD_CDC_SetTxBuffer(&hUSBDDevice, UserTxBuffer, 0); - USBD_CDC_SetRxBuffer(&hUSBDDevice, UserRxBuffer); + /*##-5- Set Application Buffers ############################################*/ + USBD_CDC_SetTxBuffer(&hUSBDDevice, UserTxBuffer, 0); + USBD_CDC_SetRxBuffer(&hUSBDDevice, UserRxBuffer); UserRxBufCur = 0; UserRxBufLen = 0; @@ -147,7 +141,7 @@ static int8_t CDC_Itf_Init(void) user_interrupt_char = VCP_CHAR_NONE; user_interrupt_data = NULL; - return (USBD_OK); + return (USBD_OK); } /** @@ -378,29 +372,3 @@ int USBD_CDC_RxGet(void) { } return c; } - -/** - * @brief TIM_Config: Configure TIMx timer - * @param None. - * @retval None. - */ -static void TIM_Config(void) -{ - /* Set TIMx instance */ - USBD_CDC_TIM3_Handle.Instance = USBD_CDC_TIMx; - - /* Initialize TIM3 peripheral as follow: - + Period = 10000 - 1 - + Prescaler = ((SystemCoreClock/2)/10000) - 1 - + ClockDivision = 0 - + Counter direction = Up - */ - USBD_CDC_TIM3_Handle.Init.Period = (USBD_CDC_POLLING_INTERVAL*1000) - 1; - USBD_CDC_TIM3_Handle.Init.Prescaler = 84-1; - USBD_CDC_TIM3_Handle.Init.ClockDivision = 0; - USBD_CDC_TIM3_Handle.Init.CounterMode = TIM_COUNTERMODE_UP; - if(HAL_TIM_Base_Init(&USBD_CDC_TIM3_Handle) != HAL_OK) - { - /* Initialization Error */ - } -} diff --git a/stmhal/usbd_cdc_interface.h b/stmhal/usbd_cdc_interface.h index f0c8404ff..5ed5ecef4 100644 --- a/stmhal/usbd_cdc_interface.h +++ b/stmhal/usbd_cdc_interface.h @@ -33,21 +33,11 @@ /* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
-/* Definition for TIMx clock resources */
-#define USBD_CDC_TIMx TIM3
-#define USBD_CDC_TIMx_CLK_ENABLE __TIM3_CLK_ENABLE
-#define USBD_CDC_TIMx_FORCE_RESET() __TIM3_FORCE_RESET()
-#define USBD_CDC_TIMx_RELEASE_RESET() __TIM3_RELEASE_RESET()
-
-/* Definition for TIMx's NVIC */
-#define USBD_CDC_TIMx_IRQn TIM3_IRQn
-//#define USBD_CDC_TIMx_IRQHandler TIM3_IRQHandler // this is hard coded in stm32f4xx_it.c
-
/* Periodically, the state of the buffer "UserTxBuffer" is checked.
The period depends on USBD_CDC_POLLING_INTERVAL */
#define USBD_CDC_POLLING_INTERVAL 10 /* in ms. The max is 65 and the min is 1 */
-extern TIM_HandleTypeDef USBD_CDC_TIM3_Handle;
+extern TIM_HandleTypeDef TIM3_Handle;
extern const USBD_CDC_ItfTypeDef USBD_CDC_fops;
void USBD_CDC_HAL_TIM_PeriodElapsedCallback(void);
|
