Test application for getting the Nucleo F0 30 board to work with Evan's prototype LED board.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 5:9a662dec2ddb
- Parent:
- 4:4eeacb39a417
- Child:
- 6:e4da8955cf65
--- a/main.cpp Tue Aug 05 23:11:15 2014 +0000 +++ b/main.cpp Tue Aug 05 23:53:59 2014 +0000 @@ -3,6 +3,18 @@ #define OK (0) #define ERROR (-1) +#define PIN_41 PB_5 +#define PIN_46 PB_9 +#define PIN_32 PA_11 +#define PIN_20 PB_2 +#define HEX_ONE_THOUSAND (0x03E8) + +DigitalOut ENA(PIN_41); +DigitalOut ENB(PIN_46); +DigitalOut ENC(PIN_32); +DigitalOut EnSclk(PIN_20); + + // Forward Declarations void pwmout_period_ns(pwmout_t* obj, int us); int cmd_S0(uint16_t value); @@ -11,10 +23,17 @@ // Globals bool gSpiMode = false; SPI* gSpiPtr = NULL; -DigitalOut gbbTRANS(D8); // Global bit bang TRANS (data) line +DigitalOut gbbTRANS(PA_4); // Global bit bang TRANS (data) line +const int SCLK_ENABLED = 0; int main() { + ENA = 1; + ENB = 1; + ENC = 1; + EnSclk = SCLK_ENABLED; + + // NOTE: 24MHz is half the 48MHz clock rate. The PWM registers // seem to only allow 24MHz at this point, so I'm matching // the SPI bus speed to be the same. @@ -30,9 +49,10 @@ // PWMCLK pwmout_t outs; - pwmout_init(&outs, D9); - pwmout_period_ns(&outs, 2); // 24 MHz (not very clean on the scope) + pwmout_init(&outs, PB_4); + //pwmout_period_ns(&outs, 2); // 24 MHz (not very clean on the scope) // pwmout_period_ns(&outs, 40); // 1.2 MHz on the scope + pwmout_period_us(&outs, 2); // 1.2 MHz on the scope pwmout_write(&outs, 0.5f); int ret = OK; // Return value @@ -40,9 +60,9 @@ printf("17:10\n"); - while (1) { - for (i=0; i<16; i++) { - ret = cmd_S0(0xFFFF); + //while (1) { + for (i=0; i<400; i++) { + ret = cmd_S0(0x0900); // ORIG: ret = cmd_S0(0xFFFF); if (ret != OK) { printf("ERROR cmd_S0()\n"); @@ -50,7 +70,7 @@ } } cmd_S1(); - } + //} } @@ -123,10 +143,10 @@ } - +/* USED FOR THE F030 BOARD // This code is based off: // mbed/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/pwmout_api.c pwmout_period_us() -void pwmout_period_ns(pwmout_t* obj, int us) { +void pwmout_period_ns_NOT_USED(pwmout_t* obj, int us) { TIM_TypeDef *tim = (TIM_TypeDef *)(obj->pwm); TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; float dc = pwmout_read(obj); @@ -149,3 +169,36 @@ TIM_Cmd(tim, ENABLE); } +*/ + + + +/* HAVE NOT GOTTEN THIS WORKNIG FOR THE F072 +// This code is based off: +// mbed/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F072* /pwmout_api.c pwmout_period_us() +void pwmout_period_ns(pwmout_t* obj, int us) { + TimHandle.Instance = (TIM_TypeDef *)(obj->pwm); + + float dc = pwmout_read(obj); + + __HAL_TIM_DISABLE(&TimHandle); + + // Update the SystemCoreClock variable + SystemCoreClockUpdate(); + + TimHandle.Init.Period = us - 1; + // TimHandle.Init.Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick + TimHandle.Init.Prescaler = 0; // BAG 1 ns tick (?) + TimHandle.Init.ClockDivision = 0; + TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; + HAL_TIM_PWM_Init(&TimHandle); + + // Set duty cycle again + pwmout_write(obj, dc); + + // Save for future use + obj->period = us; + + __HAL_TIM_ENABLE(&TimHandle); +} +*/ \ No newline at end of file