diff --git a/miosix/arch/cortexM3_stm32/stm32f103c8_skyward_alderaan/interfaces-impl/bsp.cpp b/miosix/arch/cortexM3_stm32/stm32f103c8_skyward_alderaan/interfaces-impl/bsp.cpp index d978f972054b83697fb4f0148ba5119c6bbfa1cb..641251394701cb8d777ed32b48968321420f963c 100644 --- a/miosix/arch/cortexM3_stm32/stm32f103c8_skyward_alderaan/interfaces-impl/bsp.cpp +++ b/miosix/arch/cortexM3_stm32/stm32f103c8_skyward_alderaan/interfaces-impl/bsp.cpp @@ -63,23 +63,50 @@ void IRQbspInit() RCC_SYNC(); - //PORT INITIALIZATION - using namespace interfaces; - spi1::sck::mode(Mode::OUTPUT); - spi1::miso::mode(Mode::INPUT); - spi1::mosi::mode(Mode::OUTPUT); + // Actuator Pins Initialization + // Abort pin logic : 0 -> ABORT (burn fuse) + // 1 -> NOT ABORT + // Ignition pin logic : 0 -> NO IGNITION + // 1 -> IGNITION + using namespace actuators; + abortPin::mode(Mode::OUTPUT); + abortPin::high(); + + ignitionPin::mode(Mode::OUTPUT); + ignitionPin::low(); + using namespace interfaces; + // Spare Pin initialization + // Spare pin logic : 0 -> AVR BUSY + // 1 -> AVR READY + sparePin::mode(Mode::INPUT); + sparePin::high(); + + // SPI1 intialization + spi1::cs::mode(Mode::OUTPUT); + spi1::cs::high(); + spi1::sck::mode(Mode::ALTERNATE); + spi1::miso::mode(Mode::ALTERNATE); + spi1::mosi::mode(Mode::ALTERNATE); + RCC->APB2ENR |= RCC_APB2ENR_SPI1EN; + SPI1->CR1=SPI_CR1_SSM //No HW cs + | SPI_CR1_SSI + | SPI_CR1_SPE //SPI enabled + | SPI_CR1_BR_2 //SPI clock 24MHz / 32 = 750kHz + | SPI_CR1_MSTR;//Master mode + + // UART1 initialization uart1::tx::mode(Mode::OUTPUT); uart1::rx::mode(Mode::INPUT); - using namespace actuators; - abortPin::mode(Mode::OUTPUT); - ignitionPin::mode(Mode::OUTPUT); - umbilicalPin::mode(Mode::OUTPUT); + // CAN1 initialization + can1::rx::mode(Mode::ALTERNATE); + can1::tx::mode(Mode::ALTERNATE); + RCC->APB1ENR |= RCC_APB1ENR_CAN1EN; + RCC_SYNC(); - abortPin::high(); - umbilicalPin::high(); - ignitionPin::low(); + NVIC_SetPriority(CAN1_RX1_IRQn, 15); + NVIC_EnableIRQ(CAN1_RX1_IRQn); #ifdef DEBUG _led::mode(Mode::OUTPUT_2MHz); diff --git a/miosix/arch/cortexM3_stm32/stm32f103c8_skyward_alderaan/interfaces-impl/hwmapping.h b/miosix/arch/cortexM3_stm32/stm32f103c8_skyward_alderaan/interfaces-impl/hwmapping.h index a0729674a96fef93312d49b42db57ea15240ce2f..ac92770dea77517769bf16500d4213e66bd322d1 100644 --- a/miosix/arch/cortexM3_stm32/stm32f103c8_skyward_alderaan/interfaces-impl/hwmapping.h +++ b/miosix/arch/cortexM3_stm32/stm32f103c8_skyward_alderaan/interfaces-impl/hwmapping.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2018 by Terraneo Federico * + * Copyright (C) 2018 by Terraneo Federico, Alvise de' Faveri Tron * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -36,6 +36,7 @@ namespace interfaces { namespace spi1 { + using cs = Gpio<GPIOA_BASE, 4>; using sck = Gpio<GPIOA_BASE, 5>; using miso = Gpio<GPIOA_BASE, 6>; using mosi = Gpio<GPIOA_BASE, 7>; @@ -46,15 +47,21 @@ namespace interfaces using rx = Gpio<GPIOA_BASE, 10>; } //namespace uart1 + namespace can1 { + using rx = Gpio<GPIOB_BASE, 8>; + using tx = Gpio<GPIOB_BASE, 9>; + } + + using sparePin = Gpio<GPIOA_BASE, 3>; + + } //namespace interfaces namespace actuators { - using abortPin = Gpio<GPIOA_BASE, 1>; using ignitionPin = Gpio<GPIOA_BASE, 2>; - using umbilicalPin = Gpio<GPIOA_BASE, 3>; } //namespace actuators