Skip to content

Instantly share code, notes, and snippets.

@ansemjo
Last active May 26, 2020 16:16
Show Gist options
  • Save ansemjo/ab1c12f7c78abb140f7272501aff2a55 to your computer and use it in GitHub Desktop.
Save ansemjo/ab1c12f7c78abb140f7272501aff2a55 to your computer and use it in GitHub Desktop.
minimal blink exmaple for the otterpill with platformio and the stm32cube-hal
; not exactly the correct board but *close enough*
; the ..RBTx only has more io
[env:otterpill]
platform = ststm32
board = disco_f072rb
framework = stm32cube
upload_protocol = dfu
// blink example from platformio/platform-ststm32:
// https://github.com/platformio/platform-ststm32/tree/master/examples/stm32cube-hal-blink
#include "stm32f0xx_hal.h"
// led on otterpill is on pin 13 of port B
#define LED_PIN GPIO_PIN_13
#define LED_GPIO_PORT GPIOB
#define LED_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
int main(void)
{
HAL_Init();
LED_GPIO_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = LED_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct);
while (1)
{
HAL_GPIO_TogglePin(LED_GPIO_PORT, LED_PIN);
HAL_Delay(1000);
}
}
void SysTick_Handler(void)
{
HAL_IncTick();
}
void NMI_Handler(void)
{
}
void HardFault_Handler(void)
{
while (1) {}
}
void MemManage_Handler(void)
{
while (1) {}
}
void BusFault_Handler(void)
{
while (1) {}
}
void UsageFault_Handler(void)
{
while (1) {}
}
void SVC_Handler(void)
{
}
void DebugMon_Handler(void)
{
}
void PendSV_Handler(void)
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment