The Board Support Package is a module that contains the hardware initialization and configuration of the microcontroller.
The bsp.cpp
and bsp_impl.h
files can be found under: /libs/miosix-kernel/arch/<your-arch>/<your-board>/interfaces_impl/
.
The bsp.cpp
contains the implementation of some functions that are called when the board is powered up and initialized.
IRQbspInit
In this function the speed of the GPIO ports is configured. Here you can also configure the GPIO mode (e.g. configuring the correct alternate mode for the pins that belong to an SPI bus), the default serial port along with its speed and so on.
void IRQbspInit()
{
// Enable all gpios
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN |
RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIODEN |
RCC_AHB1ENR_GPIOEEN | RCC_AHB1ENR_GPIOHEN;
RCC_SYNC();
// Default to 50MHz speed for all GPIOS
GPIOA->OSPEEDR=0xaaaaaaaa;
GPIOB->OSPEEDR=0xaaaaaaaa;
GPIOC->OSPEEDR=0xaaaaaaaa;
GPIOD->OSPEEDR=0xaaaaaaaa;
GPIOE->OSPEEDR=0xaaaaaaaa;
GPIOH->OSPEEDR=0xaaaaaaaa;
// Peripherals initialization
using namespace interfaces;
myspi::sck::mode(Mode::ALTERNATE);
myspi::sck::alternateFunction(5);
myspi::miso::mode(Mode::ALTERNATE);
myspi::miso::alternateFunction(5);
myspi::mosi::mode(Mode::ALTERNATE);
myspi::mosi::alternateFunction(5);
mysensor::cs::mode(Mode::OUTPUT);
mysensor::cs::high();
mysensor::int1::mode(Mode::INPUT);
// Setup default serial port on USART3 with a baud rate of 19200
DefaultConsole::instance().IRQset(intrusive_ref_ptr<Device>(
new STM32Serial(3, 19200,
defaultSerialFlowctrl ? STM32Serial::RTSCTS : STM32Serial::NOFLOWCTRL)));
}
Note that myspi
and mysensor
along with their corresponding GPIOs are defined in the hardware mapping file (hwmapping.h
).
bspInit2
This function contains the configurations needed to access other USART
ports of the microcontroller.
void bspInit2()
{
#ifdef WITH_FILESYSTEM
// Open GPS serial on USART2 with a baud rate of 115200
intrusive_ref_ptr<DevFs> devFs = basicFilesystemSetup(SDIODriver::instance());
devFs->addDevice("gps", intrusive_ref_ptr<Device>(new STM32Serial(2, 115200)));
#endif //WITH_FILESYSTEM
}
Shutdown and Reboot
Usually for safety reasons when designing a new board for a rocket, we never want the board to completely shotdown. So in that case the shutdown() function performs a reboot().
void shutdown()
{
reboot();
}
void reboot()
{
ioctl(STDOUT_FILENO,IOCTL_SYNC,0);
#ifdef WITH_FILESYSTEM
FilesystemManager::instance().umountAll();
#endif //WITH_FILESYSTEM
disableInterrupts();
miosix_private::IRQsystemReboot();
}