snickerdoodle Platform Controller
firmware for STM32F0 platform controller
Platform Functions

Functions

void sd_wl18xx_ant_config (uint8_t ant)
 WL18xx Antenna Configuration Outputs antenna select pins for the wireless module. More...
 
void sd_zynq_clk_enable (uint8_t en)
 Zynq Clock Enable Enables the main clock source for the Zynq APU. More...
 
void sd_zynq_jtag_enable (uint8_t en)
 Zynq JTAG Enable Enables the JTAG interface for programming the PS or PL. More...
 
void sd_wl_clk_enable (uint8_t en)
 Wireless Clock Enable Enable the wireless module 32kHz clock source. More...
 
void sd_bt_enable (uint8_t en)
 Bluetooth Enable Enable the Bluetooth interface on the wireless module. More...
 
void sd_zynq_boot_config (enum sd_zynq_boot boot)
 Zynq Boot Config Outputs boot select pins to zynq for desired boot media source. More...
 
enum sd_zynq_boot sd_boot_select (void)
 Boot selection.
 
enum sd_uart_usb_err sd_uart_usb_bridge_init (void)
 UART to USB Bridge Initialization Initialize UART device structure, UART to USB bridge buffer and set the UART device to use the (previously initialized) UART peripheral and newly initialized buffer. More...
 
enum sd_uart_usb_err sd_uart_usb_transmit (struct sd_uart_dev *dev)
 UART to USB Bridge Transmission Transmit the buffer that has been recieved on the bridged UART over USB communications device. More...
 
void sd_dfu_start (void)
 Enter Device Firmware Upgrade Mode Prepare device to enter system memory by disabling peripheral clocks, disable PLL, clear pending interrupts and disable interrupts. More...
 
void sd_zynq_enable (void)
 Enable Zynq Power Enable the Zynq power rails by setting the enable pin high. More...
 
void sd_zynq_disable (void)
 Disable Zynq Power Disable the Zynq power rails by setting the enable pin low. More...
 

Detailed Description

Function Documentation

◆ sd_bt_enable()

void sd_bt_enable ( uint8_t  enable)

#include <Inc/sd_platform.h>

Bluetooth Enable Enable the Bluetooth interface on the wireless module.

Parameters
enableState to set for Bluetooth interface
Return values
None
160 {
161  GPIO_PinState en = enable ? GPIO_PIN_SET : GPIO_PIN_RESET;
162 
163  HAL_GPIO_WritePin(WL18xx_BT_EN_GPIO_Port,
164  WL18xx_BT_EN_Pin, en);
165 }

◆ sd_dfu_start()

void sd_dfu_start ( void  )

#include <Inc/sd_platform.h>

Enter Device Firmware Upgrade Mode Prepare device to enter system memory by disabling peripheral clocks, disable PLL, clear pending interrupts and disable interrupts.

Disable peripheral clocks

Disable PLL

Disable systick

Run to stack pointer and execute code from system memory

447 {
448  void (*boot_jump)(void);
449 
453  __GPIOA_CLK_DISABLE();
454  __GPIOB_CLK_DISABLE();
455  __GPIOC_CLK_DISABLE();
456  __GPIOD_CLK_DISABLE();
457  __GPIOE_CLK_DISABLE();
458  __GPIOF_CLK_DISABLE();
459 
463  RCC->CR |= (uint32_t)0x00000001; /* Set HSION bit */
464  RCC->CFGR &= (uint32_t)0x08FFB80C; /* Reset SW[1:0], HPRE[3:0], PPRE[2:0], ADCPRE, MCOSEL[2:0], MCOPRE[2:0] and PLLNODIV bits */
465  RCC->CR &= (uint32_t)0xFEF6FFFF; /* Reset HSEON, CSSON and PLLON bits */
466  RCC->CR &= (uint32_t)0xFFFBFFFF; /* Reset HSEBYP bit */
467  RCC->CFGR &= (uint32_t)0xFFC0FFFF; /* Reset PLLSRC, PLLXTPRE and PLLMUL[3:0] bits */
468  RCC->CFGR2 &= (uint32_t)0xFFFFFFF0; /* Reset PREDIV1[3:0] bits */
469  RCC->CFGR3 &= (uint32_t)0xFFF0FEAC; /* Reset USARTSW[1:0], I2CSW, CECSW and ADCSW bits */
470  RCC->CR2 &= (uint32_t)0xFFFFFFFE; /* Reset HSI14 bit */
471  RCC->CIR = 0x00000000; /* Disable all interrupts */
472 
476  SysTick->CTRL = 0;
477  SysTick->LOAD = 0;
478  SysTick->VAL = 0;
479 
483  __set_MSP(BOOT_STACK_ADDR);
484  boot_jump = (void (*)(void))(*((uint32_t *)(SYS_MEM_START_ADDR + 4)));
485  boot_jump();
486  while (1);
487 }
#define BOOT_STACK_ADDR
Definition: sd_platform.h:78
#define SYS_MEM_START_ADDR
Definition: sd_platform.h:79

◆ sd_uart_usb_bridge_init()

enum sd_uart_usb_err sd_uart_usb_bridge_init ( void  )

#include <Inc/sd_platform.h>

UART to USB Bridge Initialization Initialize UART device structure, UART to USB bridge buffer and set the UART device to use the (previously initialized) UART peripheral and newly initialized buffer.

Return values
Stateof UART USB bridge after initialization
351 {
352  /* Initialize the UART device(s) */
353 // if (sd_uart_dev_init(&uart1_dev) != SD_UART_SUCCESS)
354 // return SD_UART_USB_ERROR;
355 //
356 // if (sd_uart_dev_init(&uart2_dev) != SD_UART_SUCCESS)
357 // return SD_UART_USB_ERROR;
358 //
359 // /* Initialize the UART <--> USB Buffer */
360 // if (sd_char_buff_init(&uart1_rx_cbuff,
361 // CONS_UART_RX_BUFF_SIZE,
362 // uart1_rx_buff) != SD_BUFF_SUCCESS)
363 // return SD_UART_USB_ERROR;
364 //
365 // if (sd_char_buff_init(&uart2_rx_cbuff,
366 // CONS_UART_RX_BUFF_SIZE,
367 // uart2_rx_buff) != SD_BUFF_SUCCESS)
368 // return SD_UART_USB_ERROR;
369 //
370 // /* Set the UART device with the peripheral and buffer*/
371 // if (sd_uart_rx_init(&uart1_dev, &huart1, &uart1_rx_cbuff) != SD_BUFF_SUCCESS)
372 // return SD_UART_USB_ERROR;
373 //
374 // if (sd_uart_rx_init(&uart2_dev, &huart2, &uart2_rx_cbuff) != SD_BUFF_SUCCESS)
375 // return SD_UART_USB_ERROR;
376 
377  return SD_UART_USB_SUCCESS;
378 }
Definition: sd_platform.h:137

◆ sd_uart_usb_transmit()

enum sd_uart_usb_err sd_uart_usb_transmit ( struct sd_uart_dev dev)
inline

#include <Inc/sd_platform.h>

UART to USB Bridge Transmission Transmit the buffer that has been recieved on the bridged UART over USB communications device.

Parameters
uart_devUART device structure that is bridged
Return values
SD_UART_USB_SUCCESSon success, error state otherwise
390 {
391  struct sd_cbuf *rxbuff = dev->rx_buff;
392  static uint8_t txbuff[CONS_UART_RX_BUFF_SIZE];
393  static uint32_t idx;
394  uint8_t state;
395 
396  while (rxbuff->len && (idx < CONS_UART_RX_BUFF_SIZE)) {
397  /* Check for the end of the buffer and wrap */
398  if (rxbuff->out >= rxbuff->size)
399  rxbuff->out = 0;
400 
401  /* Put the character in the secondary buffer */
402  txbuff[idx++] = rxbuff->buff[rxbuff->out++];
403 
404  /* Check for the end of the buffer and wrap */
405  if (rxbuff->out >= rxbuff->size)
406  rxbuff->out = 0;
407 
408  if (--rxbuff->len <= 0)
409  rxbuff->len = 0;
410 
411  /* Check if the UART interrupt has been triggered and end this loop */
412  if ((__HAL_UART_GET_IT(dev->uart, UART_IT_RXNE) != RESET) &&
413  (__HAL_UART_GET_IT_SOURCE(dev->uart, UART_IT_RXNE) != RESET))
414  return SD_UART_USB_SUCCESS; /* End the loop here so that the UART can operate */
415  }
416 
417  /* Transmit if there is anything to transmit */
418  if (idx) {
419  state = sd_cdc_get_state();
420 
421  if (state == USBD_STATE_CONFIGURED) {
422  sd_cdc_transmit(txbuff, idx);
423  idx = 0; /* Reset the index once we've transmitted */
424  }
425  }
426 
427  return SD_UART_USB_SUCCESS;
428 }
uint32_t size
Definition: sd_buffer.h:107
struct sd_cbuf * rx_buff
Definition: sd_uart.h:142
uint8_t * buff
Definition: sd_buffer.h:103
enum sd_buff_state state
Definition: sd_buffer.h:108
Character buffer structure.
Definition: sd_buffer.h:102
Definition: sd_platform.h:137
UART_HandleTypeDef * uart
Definition: sd_uart.h:140
uint8_t sd_cdc_transmit(uint8_t *buf, uint16_t len)
USB Communications Class Device Transmit Data send over USB IN endpoint are sent over CDC interface t...
Definition: sd_usbd_cdc_if.c:265
#define CONS_UART_RX_BUFF_SIZE
Definition: sd_platform.h:61
uint32_t out
Definition: sd_buffer.h:105
uint32_t len
Definition: sd_buffer.h:106

◆ sd_wl18xx_ant_config()

void sd_wl18xx_ant_config ( uint8_t  ant)

#include <Inc/sd_platform.h>

WL18xx Antenna Configuration Outputs antenna select pins for the wireless module.

Parameters
antValue defining antenna configuration (two LSBs used)
Return values
None
313 {
314  GPIO_PinState ant_select_1, ant_select_2;
315 
316  /* Check that the antenna selection is valid */
317  if (!IS_WL18xx_ANTENNA_MODE(ant))
318  return;
319 
320  /* Determine antenna select pins from bits */
321  ant_select_1 = (ant & 0x01) ? GPIO_PIN_SET : GPIO_PIN_RESET;
322  ant_select_2 = (ant & 0x02) ? GPIO_PIN_SET : GPIO_PIN_RESET;
323 
324  /* Output GPIO selection pins */
325  HAL_GPIO_WritePin(ANT_SELECT_1_GPIO_Port, ANT_SELECT_2_Pin,
326  ant_select_1);
327  HAL_GPIO_WritePin(ANT_SELECT_2_GPIO_Port, ANT_SELECT_2_Pin,
328  ant_select_2);
329 }
#define IS_WL18xx_ANTENNA_MODE(__MODE__)
Check that the antenna selection is valid.
Definition: sd_platform.h:90

◆ sd_wl_clk_enable()

void sd_wl_clk_enable ( uint8_t  enable)

#include <Inc/sd_platform.h>

Wireless Clock Enable Enable the wireless module 32kHz clock source.

Parameters
enableState to set for clock
Return values
None
144 {
145  GPIO_PinState en = enable ? GPIO_PIN_SET : GPIO_PIN_RESET;
146 
147  HAL_GPIO_WritePin(WL_32KHZ_CLK_EN_GPIO_Port,
148  WL_32KHZ_CLK_EN_Pin, en);
149 }

◆ sd_zynq_boot_config()

void sd_zynq_boot_config ( enum sd_zynq_boot  boot)

#include <Inc/sd_platform.h>

Zynq Boot Config Outputs boot select pins to zynq for desired boot media source.

Parameters
bootValue defining boot pin outputs
Return values
None
178 {
179  GPIO_PinState mio4_out, mio5_out;
180 
181  switch (boot) {
182  case SD_ZYNQ_BOOT_JTAG:
183  mio4_out = GPIO_PIN_RESET; /* 0 */
184  mio5_out = GPIO_PIN_RESET; /* 0 */
185  break;
186 
187  case SD_ZYNQ_BOOT_NAND:
188  mio4_out = GPIO_PIN_SET; /* 1 */
189  mio5_out = GPIO_PIN_RESET; /* 0 */
190  break;
191 
192  case SD_ZYNQ_BOOT_QSPI:
193  mio4_out = GPIO_PIN_RESET; /* 0 */
194  mio5_out = GPIO_PIN_SET; /* 1 */
195  break;
196 
197  case SD_ZYNQ_BOOT_SD:
198  mio4_out = GPIO_PIN_SET; /* 1 */
199  mio5_out = GPIO_PIN_SET; /* 1 */
200  break;
201  }
202 
203  /* Write boot select pins */
204  HAL_GPIO_WritePin(MIO4_BOOT_SELECT_GPIO_Port,
205  MIO4_BOOT_SELECT_Pin,
206  mio4_out);
207 
208  HAL_GPIO_WritePin(MIO5_BOOT_SELECT_GPIO_Port,
209  MIO5_BOOT_SELECT_Pin,
210  mio5_out);
211 }
Definition: sd_platform.h:155
Definition: sd_platform.h:156
Definition: sd_platform.h:154
Definition: sd_platform.h:157

◆ sd_zynq_clk_enable()

void sd_zynq_clk_enable ( uint8_t  enable)

#include <Inc/sd_platform.h>

Zynq Clock Enable Enables the main clock source for the Zynq APU.

Parameters
enableState to set for clock
Return values
None
111 {
112  GPIO_PinState en = enable ? GPIO_PIN_SET : GPIO_PIN_RESET;
113 
114  HAL_GPIO_WritePin(ZYNQ_CLK_EN_GPIO_Port,
115  ZYNQ_CLK_EN_Pin, en);
116 
117 }

◆ sd_zynq_disable()

void sd_zynq_disable ( void  )

#include <Inc/sd_platform.h>

Disable Zynq Power Disable the Zynq power rails by setting the enable pin low.

Parameters
buttButton used to trigger this function
Return values
None
240 {
241  HAL_GPIO_WritePin(ZYNQ_POWER_EN_GPIO_Port,
242  ZYNQ_POWER_EN_Pin, GPIO_PIN_RESET);
244 }
enum sd_led_err sd_led_rapid(struct sd_led *led)
LED rapid blinking Set an LED to a continuous rapid blinking.
Definition: sd_led_pattern.c:197
struct sd_led app_led
Definition: sd_led.c:67

◆ sd_zynq_enable()

void sd_zynq_enable ( void  )

#include <Inc/sd_platform.h>

Enable Zynq Power Enable the Zynq power rails by setting the enable pin high.

Parameters
buttButton used to trigger this function
Return values
None
255 {
256  HAL_GPIO_WritePin(ZYNQ_POWER_EN_GPIO_Port,
257  ZYNQ_POWER_EN_Pin, GPIO_PIN_SET);
258 
260 }
enum sd_led_err sd_led_reset(struct sd_led *led)
LED reset Reset the LED configuration and clear the pattern.
Definition: sd_led.c:174
struct sd_led app_led
Definition: sd_led.c:67

◆ sd_zynq_jtag_enable()

void sd_zynq_jtag_enable ( uint8_t  enable)

#include <Inc/sd_platform.h>

Zynq JTAG Enable Enables the JTAG interface for programming the PS or PL.

Parameters
enableState to set for JTAG interface
Return values
None
128 {
129  GPIO_PinState en = enable ? GPIO_PIN_SET : GPIO_PIN_RESET;
130 
131  HAL_GPIO_WritePin(ZYNQ_JTAG_NRST_GPIO_Port,
132  ZYNQ_JTAG_NRST_Pin, en);
133 }