efm32gg11_hal.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <stdint.h>
  2. #include <string.h>
  3. #include "em_device.h"
  4. #include "em_chip.h"
  5. #include "em_cmu.h"
  6. #include "em_gpio.h"
  7. #include "em_usart.h"
  8. #include "efm32gg11_hal.h"
  9. //make flashing device lock bootloader
  10. //const uint32_t __attribute__((section (".debug_lock"))) user_lock_word[1] = {0xFFFFFFFD};
  11. void platform_init(void)
  12. {
  13. CHIP_Init();
  14. CMU_HFXOInit_TypeDef hfxoInit = CMU_HFXOINIT_EXTERNAL_CLOCK;
  15. CMU_HFXOInit(&hfxoInit);
  16. CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
  17. CMU_OscillatorEnable(cmuOsc_HFRCO, false, false);
  18. CMU_ClockEnable(cmuClock_GPIO, true);
  19. CMU_ClockEnable(cmuClock_USART1, true);
  20. }
  21. void init_uart(void)
  22. {
  23. GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 1); //PE10 = Tx
  24. GPIO_PinModeSet(gpioPortE, 11, gpioModeInput, 0); //PE11 = RX
  25. #error "Unfinished HAL - need to enable IO pin mux here"
  26. USART_InitAsync_TypeDef init = USART_INITASYNC_DEFAULT;
  27. init.baudrate = 38400;
  28. init.refFreq = 7.3728E6;
  29. USART_InitAsync(USART0, &init);
  30. }
  31. void putch(char c)
  32. {
  33. USART_Tx(USART0, c);
  34. }
  35. char getch(void)
  36. {
  37. return USART_Rx(USART0);
  38. }
  39. void trigger_setup(void)
  40. {
  41. GPIO_PinModeSet(gpioPortB, 8, gpioModePushPull, 0);
  42. }
  43. void trigger_low(void)
  44. {
  45. GPIO_PinOutClear(gpioPortB, 8);
  46. }
  47. void trigger_high(void)
  48. {
  49. GPIO_PinOutSet(gpioPortB, 8);
  50. }