trying to get CDC working on chinese 407 minimum board (I have code ready on 407 Disco and want to put smaller board in robot)
Board is relativelly minimum (from USB standpoint) with V bus directly to 5VIn, ID grounded, D-/+ connected to PA11/12 throught 22R resistor and D+ is pulled up with 1.5k
There is 25Mhz osc and also 32.768 osc32. I changed timings accordingly CubeMX and by led time it looks somehow correct.
But SDU1 doesn't get recognized as CDC - same code as I had in Disco where it worked.
Board.h is changed so additional usb pins from Disco is removed, #define BOARD_OTG_NOVBUSSENS addede on beginning of board.h and still not luck. I scanned what I found on forum on CDC and still don't know what I am doing wrong
board.h
Code: Select all
/*
#ifndef BOARD_H
#define BOARD_H
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
/*
* Setup for STMicroelectronics STM32F4-Discovery board.
*/
/*
* Board identifier.
*/
#define BOARD_ST_STM32F4MINI
#define BOARD_NAME "STM32F407Mini"
#define BOARD_OTG_NOVBUSSENS
/*
* Board oscillators-related settings.
* NOTE: LSE not fitted.
*/
#define STM32_LSECLK 32768U
#define STM32_HSECLK 25000000U
/*
* Board voltages.
* Required for performance limits calculation.
*/
#define STM32_VDD 330U
/*
* MCU type as defined in the ST header.
*/
#define STM32F407xx
/*
* IO pins assignments.
*/
#define GPIOA_BUTTON 0U
#define GPIOA_PIN1 1U
#define GPIOA_PIN2 2U
#define GPIOA_PIN3 3U
#define GPIOA_LRCK 4U
#define GPIOA_SPC 5U
#define GPIOA_SDO 6U
#define GPIOA_SDI 7U
#define GPIOA_PIN8 8U
#define GPIOA_OTG_FS_DM 11U
#define GPIOA_OTG_FS_DP 12U
#define GPIOA_SWDIO 13U
#define GPIOA_SWCLK 14U
#define GPIOA_PIN15 15U
#define GPIOB_PIN0 0U
#define GPIOB_PIN1 1U
#define GPIOB_PIN2 2U
#define GPIOB_SWO 3U
#define GPIOB_PIN4 4U
#define GPIOB_PIN5 5U
#define GPIOB_SCL 6U
#define GPIOB_PIN7 7U
#define GPIOB_PIN8 8U
#define GPIOB_SDA 9U
#define GPIOB_CLK_IN 10U
#define GPIOB_PIN11 11U
#define GPIOB_PIN12 12U
#define GPIOB_PIN13 13U
#define GPIOB_PIN14 14U
#define GPIOB_PIN15 15U
..................
/*
* IO lines assignments.
*/
#define LINE_BUTTON PAL_LINE(GPIOA, 0U)
#define LINE_LRCK PAL_LINE(GPIOA, 4U)
#define LINE_SPC PAL_LINE(GPIOA, 5U)
#define LINE_SDO PAL_LINE(GPIOA, 6U)
#define LINE_SDI PAL_LINE(GPIOA, 7U)
#define LINE_VBUS_FS PAL_LINE(GPIOA, 9U)
#define LINE_OTG_FS_ID PAL_LINE(GPIOA, 10U)
#define LINE_OTG_FS_DM PAL_LINE(GPIOA, 11U)
#define LINE_OTG_FS_DP PAL_LINE(GPIOA, 12U)
#define LINE_SWDIO PAL_LINE(GPIOA, 13U)
#define LINE_SWCLK PAL_LINE(GPIOA, 14U)
#define LINE_SWO PAL_LINE(GPIOB, 3U)
#define LINE_SCL PAL_LINE(GPIOB, 6U)
#define LINE_SDA PAL_LINE(GPIOB, 9U)
#define LINE_CLK_IN PAL_LINE(GPIOB, 10U)
#define LINE_OTG_FS_POWER_ON PAL_LINE(GPIOC, 0U)
#define LINE_PDM_OUT PAL_LINE(GPIOC, 3U)
#define LINE_MCLK PAL_LINE(GPIOC, 7U)
#define LINE_SCLK PAL_LINE(GPIOC, 10U)
#define LINE_SDIN PAL_LINE(GPIOC, 12U)
#define LINE_RESET PAL_LINE(GPIOD, 4U)
#define LINE_OVER_CURRENT PAL_LINE(GPIOD, 5U)
#define LINE_LED4 PAL_LINE(GPIOD, 12U)
#define LINE_LED3 PAL_LINE(GPIOD, 13U)
#define LINE_LED5 PAL_LINE(GPIOD, 14U)
#define LINE_LED6 PAL_LINE(GPIOD, 15U)
#define LINE_INT1 PAL_LINE(GPIOE, 0U)
#define LINE_INT2 PAL_LINE(GPIOE, 1U)
#define LINE_CS_SPI PAL_LINE(GPIOE, 3U)
#define LINE_OSC_IN PAL_LINE(GPIOH, 0U)
#define LINE_OSC_OUT PAL_LINE(GPIOH, 1U)
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
/*
* I/O ports initial setup, this configuration is established soon after reset
* in the initialization code.
* Please refer to the STM32 Reference Manual for details.
*/
#define PIN_MODE_INPUT(n) (0U << ((n) * 2U))
#define PIN_MODE_OUTPUT(n) (1U << ((n) * 2U))
#define PIN_MODE_ALTERNATE(n) (2U << ((n) * 2U))
#define PIN_MODE_ANALOG(n) (3U << ((n) * 2U))
#define PIN_ODR_LOW(n) (0U << (n))
#define PIN_ODR_HIGH(n) (1U << (n))
#define PIN_OTYPE_PUSHPULL(n) (0U << (n))
#define PIN_OTYPE_OPENDRAIN(n) (1U << (n))
#define PIN_OSPEED_VERYLOW(n) (0U << ((n) * 2U))
#define PIN_OSPEED_LOW(n) (1U << ((n) * 2U))
#define PIN_OSPEED_MEDIUM(n) (2U << ((n) * 2U))
#define PIN_OSPEED_HIGH(n) (3U << ((n) * 2U))
#define PIN_PUPDR_FLOATING(n) (0U << ((n) * 2U))
#define PIN_PUPDR_PULLUP(n) (1U << ((n) * 2U))
#define PIN_PUPDR_PULLDOWN(n) (2U << ((n) * 2U))
#define PIN_AFIO_AF(n, v) ((v) << (((n) % 8U) * 4U))
/*
* GPIOA setup:
*
* PA0 - BUTTON (input floating).
* PA1 - PIN1 (input pullup).
* PA2 - PIN2 (input pullup).
* PA3 - PIN3 (input pullup).
* PA4 - LRCK (alternate 6).
* PA5 - SPC (alternate 5).
* PA6 - SDO (alternate 5).
* PA7 - SDI (alternate 5).
* PA8 - PIN8 (input pullup).
* PA9 - VBUS_FS (input floating).
* PA10 - OTG_FS_ID (alternate 10).
* PA11 - OTG_FS_DM (alternate 10).
* PA12 - OTG_FS_DP (alternate 10).
* PA13 - SWDIO (alternate 0).
* PA14 - SWCLK (alternate 0).
* PA15 - PIN15 (input pullup).
*/
#define VAL_GPIOA_MODER (PIN_MODE_INPUT(GPIOA_BUTTON) | \
PIN_MODE_INPUT(GPIOA_PIN1) | \
PIN_MODE_INPUT(GPIOA_PIN2) | \
PIN_MODE_INPUT(GPIOA_PIN3) | \
PIN_MODE_ALTERNATE(GPIOA_LRCK) | \
PIN_MODE_ALTERNATE(GPIOA_SPC) | \
PIN_MODE_ALTERNATE(GPIOA_SDO) | \
PIN_MODE_ALTERNATE(GPIOA_SDI) | \
PIN_MODE_INPUT(GPIOA_PIN8) | \
PIN_MODE_ALTERNATE(GPIOA_OTG_FS_DM) | \
PIN_MODE_ALTERNATE(GPIOA_OTG_FS_DP) | \
PIN_MODE_ALTERNATE(GPIOA_SWDIO) | \
PIN_MODE_ALTERNATE(GPIOA_SWCLK) | \
PIN_MODE_INPUT(GPIOA_PIN15))
#define VAL_GPIOA_OTYPER (PIN_OTYPE_PUSHPULL(GPIOA_BUTTON) | \
PIN_OTYPE_PUSHPULL(GPIOA_PIN1) | \
PIN_OTYPE_PUSHPULL(GPIOA_PIN2) | \
PIN_OTYPE_PUSHPULL(GPIOA_PIN3) | \
PIN_OTYPE_PUSHPULL(GPIOA_LRCK) | \
PIN_OTYPE_PUSHPULL(GPIOA_SPC) | \
PIN_OTYPE_PUSHPULL(GPIOA_SDO) | \
PIN_OTYPE_PUSHPULL(GPIOA_SDI) | \
PIN_OTYPE_PUSHPULL(GPIOA_PIN8) | \
PIN_OTYPE_PUSHPULL(GPIOA_OTG_FS_DM) | \
PIN_OTYPE_PUSHPULL(GPIOA_OTG_FS_DP) | \
PIN_OTYPE_PUSHPULL(GPIOA_SWDIO) | \
PIN_OTYPE_PUSHPULL(GPIOA_SWCLK) | \
PIN_OTYPE_PUSHPULL(GPIOA_PIN15))
#define VAL_GPIOA_OSPEEDR (PIN_OSPEED_HIGH(GPIOA_BUTTON) | \
PIN_OSPEED_HIGH(GPIOA_PIN1) | \
PIN_OSPEED_HIGH(GPIOA_PIN2) | \
PIN_OSPEED_HIGH(GPIOA_PIN3) | \
PIN_OSPEED_HIGH(GPIOA_LRCK) | \
PIN_OSPEED_MEDIUM(GPIOA_SPC) | \
PIN_OSPEED_MEDIUM(GPIOA_SDO) | \
PIN_OSPEED_MEDIUM(GPIOA_SDI) | \
PIN_OSPEED_HIGH(GPIOA_PIN8) | \
PIN_OSPEED_HIGH(GPIOA_OTG_FS_DM) | \
PIN_OSPEED_HIGH(GPIOA_OTG_FS_DP) | \
PIN_OSPEED_HIGH(GPIOA_SWDIO) | \
PIN_OSPEED_HIGH(GPIOA_SWCLK) | \
PIN_OSPEED_HIGH(GPIOA_PIN15))
#define VAL_GPIOA_PUPDR (PIN_PUPDR_FLOATING(GPIOA_BUTTON) | \
PIN_PUPDR_PULLUP(GPIOA_PIN1) | \
PIN_PUPDR_PULLUP(GPIOA_PIN2) | \
PIN_PUPDR_PULLUP(GPIOA_PIN3) | \
PIN_PUPDR_FLOATING(GPIOA_LRCK) | \
PIN_PUPDR_FLOATING(GPIOA_SPC) | \
PIN_PUPDR_FLOATING(GPIOA_SDO) | \
PIN_PUPDR_FLOATING(GPIOA_SDI) | \
PIN_PUPDR_PULLUP(GPIOA_PIN8) | \
PIN_PUPDR_FLOATING(GPIOA_OTG_FS_DM) | \
PIN_PUPDR_FLOATING(GPIOA_OTG_FS_DP) | \
PIN_PUPDR_FLOATING(GPIOA_SWDIO) | \
PIN_PUPDR_FLOATING(GPIOA_SWCLK) | \
PIN_PUPDR_PULLUP(GPIOA_PIN15))
#define VAL_GPIOA_ODR (PIN_ODR_HIGH(GPIOA_BUTTON) | \
PIN_ODR_HIGH(GPIOA_PIN1) | \
PIN_ODR_HIGH(GPIOA_PIN2) | \
PIN_ODR_HIGH(GPIOA_PIN3) | \
PIN_ODR_HIGH(GPIOA_LRCK) | \
PIN_ODR_HIGH(GPIOA_SPC) | \
PIN_ODR_HIGH(GPIOA_SDO) | \
PIN_ODR_HIGH(GPIOA_SDI) | \
PIN_ODR_HIGH(GPIOA_PIN8) | \
PIN_ODR_HIGH(GPIOA_OTG_FS_DM) | \
PIN_ODR_HIGH(GPIOA_OTG_FS_DP) | \
PIN_ODR_HIGH(GPIOA_SWDIO) | \
PIN_ODR_HIGH(GPIOA_SWCLK) | \
PIN_ODR_HIGH(GPIOA_PIN15))
#define VAL_GPIOA_AFRL (PIN_AFIO_AF(GPIOA_BUTTON, 0U) | \
PIN_AFIO_AF(GPIOA_PIN1, 0U) | \
PIN_AFIO_AF(GPIOA_PIN2, 0U) | \
PIN_AFIO_AF(GPIOA_PIN3, 0U) | \
PIN_AFIO_AF(GPIOA_LRCK, 6U) | \
PIN_AFIO_AF(GPIOA_SPC, 5U) | \
PIN_AFIO_AF(GPIOA_SDO, 5U) | \
PIN_AFIO_AF(GPIOA_SDI, 5U))
#define VAL_GPIOA_AFRH (PIN_AFIO_AF(GPIOA_PIN8, 0U) | \
PIN_AFIO_AF(GPIOA_OTG_FS_DM, 10U) | \
PIN_AFIO_AF(GPIOA_OTG_FS_DP, 10U) | \
PIN_AFIO_AF(GPIOA_SWDIO, 0U) | \
PIN_AFIO_AF(GPIOA_SWCLK, 0U) | \
PIN_AFIO_AF(GPIOA_PIN15, 0U))
........................
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#if !defined(_FROM_ASM_)
#ifdef __cplusplus
extern "C" {
#endif
void boardInit(void);
#ifdef __cplusplus
}
#endif
#endif /* _FROM_ASM_ */
#endif /* BOARD_H */
mcuconf.h
Code: Select all
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
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 MCUCONF_H
#define MCUCONF_H
/*
* STM32F4xx drivers configuration.
* The following settings override the default settings present in
* the various device driver implementation headers.
* Note that the settings for each driver only have effect if the whole
* driver is enabled in halconf.h.
*
* IRQ priorities:
* 15...0 Lowest...Highest.
*
* DMA priorities:
* 0...3 Lowest...Highest.
*/
#define STM32F4xx_MCUCONF
/*
* HAL driver system settings.
*/
#define STM32_NO_INIT FALSE
#define STM32_HSI_ENABLED FALSE
#define STM32_LSI_ENABLED FALSE
#define STM32_HSE_ENABLED TRUE
#define STM32_LSE_ENABLED TRUE
#define STM32_CLOCK48_REQUIRED TRUE
#define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSE
#define STM32_PLLM_VALUE 25
#define STM32_PLLN_VALUE 336
#define STM32_PLLP_VALUE 2
#define STM32_PLLQ_VALUE 7
#define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE1 STM32_PPRE1_DIV4
#define STM32_PPRE2 STM32_PPRE2_DIV2
#define STM32_RTCSEL STM32_RTCSEL_LSE
#define STM32_RTCPRE_VALUE 2
#define STM32_MCO1SEL STM32_MCO1SEL_HSE
#define STM32_MCO1PRE STM32_MCO1PRE_DIV1
#define STM32_MCO2SEL STM32_MCO2SEL_SYSCLK
#define STM32_MCO2PRE STM32_MCO2PRE_DIV1
#define STM32_I2SSRC STM32_I2SSRC_CKIN
#define STM32_PLLI2SN_VALUE 192
#define STM32_PLLI2SR_VALUE 5
#define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_BKPRAM_ENABLE FALSE
.....................
#endif /* MCUCONF_H */
main.cpp
Code: Select all
/
#include "ch.hpp"
#include "hal.h"
#include "usbcfg.h"
#include "chprintf.h"
using namespace chibios_rt;
#define cls(chp) chprintf(chp, "\033[2J\033[1;1H")
/*
* Application entry point.
*/
uint16_t channels[16];
bool failSafe;
bool lostFrame;
int main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
System::init();
/* Initializes a serial-over-USB CDC driver.*/
sduObjectInit(&SDU1);
sduStart(&SDU1, &serusbcfg);
BaseSequentialStream * chp = (BaseSequentialStream *)&SDU1;
/*
* Activates the USB driver and then the USB bus pull-up on D+.
* Note, a delay is inserted in order to not have to disconnect the cable
* after a reset.
*/
usbDisconnectBus(serusbcfg.usbp);
chThdSleepMilliseconds(1500);
usbStart(serusbcfg.usbp, &usbcfg);
usbConnectBus(serusbcfg.usbp);
int i = 0;
/* Normal main() thread activity, printing MEMS data on the SDU1.*/
while (true) {
palClearPad(GPIOG, 15);
chprintf(chp,"workling : %d ", i++);
chThdSleepMilliseconds(500);
palSetPad(GPIOG, 15U);
chThdSleepMilliseconds(500);
cls(chp);
}
return 0;
}
My guess is something in mcuconf because there is not too much other place where I can screw it but Clock48 is required and Cube and build looks satisified with settings.