Wednesday, August 28, 2013

usb_test.c

/*
 **********************************************************************
 *name:         stmusb_test.c
 *author:       Samuel Igwe
 *date:         08/12/2013
 *description:  stm32 usb test code.
 **********************************************************************
 */
#include "IE_stm32.h"
#include "IE_tclib.h"
/*#include "usb_test.h"*/





/*
 **********************************************************************
 *mappings
 *PA0           = external wire jumpered to usb d+
 **********************************************************************
 */
#define USB_TEST_GPIO_PIN_USB                           STM32_GPIO_PIN_USB
#define USB_TEST_GPIO_PIN_DELAY                         5000
#define USB_TEST_GPIO_PIN_CONNECT_CHAR                  'c'
#define USB_TEST_GPIO_PIN_DISCONNECT_CHAR               'd'



/*
 **********************************************************************
 *macros
 **********************************************************************
 */
void    usb_test_user_connect(void);
#define STMUSB_SHOW_TIME(ptrString)                     \
        {                                               \
        stmlib_printf("%x\t", stm32_get_seconds);\
        stmlib_printf("%s\n", ptrString);               \
        }



/*
 **********************************************************************
 *description:  main() function
 *              this is where it all happens
 **********************************************************************
 */
int main()
{



/*
 **********************************************************************
 *stm32_init()     initialization ... must be called first
 *stm32_usb_init() initialization
 **********************************************************************
 */
stm32_init();
stm32_usb_init();
stm32_systick_hook_services(usb_test_user_connect);
stm32_usb_disconnect_pullup(USB_TEST_GPIO_PIN_USB);
stm32_timer_uS_delay(250000);
stm32_usb_connect_pullup(USB_TEST_GPIO_PIN_USB);


/*
 **********************************************************************
 *now loop forever
 **********************************************************************
 */
while(1)
        ;

return 0;
}





/*
 **********************************************************************
 *description:  used to check for rx value 'c'|'C' which is a trigger
 *              to call stm32_usb_connect_pullup()
 *inputs:       none
 **********************************************************************
 */
void    usb_test_user_connect(void)
{
volatile unsigned int wdTemp;



/*
 **********************************************************************
 *check the uart rx read status
 *retrieve the data
 **********************************************************************
 */
wdTemp  = (*PTR_STM32_UART1_SR);
if((wdTemp & STM32_UART_SR_RXNE) != STM32_UART_SR_RXNE)
        return;


wdTemp  = (*PTR_STM32_UART1_DR);
wdTemp &= 0x1ff;
switch(wdTemp)
        {
        case    USB_TEST_GPIO_PIN_CONNECT_CHAR:
                {
                tclib_printf("-------user-usb-connect----request------\n", 0);
                stm32_usb_connect_pullup(USB_TEST_GPIO_PIN_USB);
                break;
                }
        case    USB_TEST_GPIO_PIN_DISCONNECT_CHAR:
                {
                tclib_printf("-------user-usb-disconnect-request------\n", 0);
                stm32_usb_disconnect_pullup(USB_TEST_GPIO_PIN_USB);
                break;
                }
        default:
                break;
        }
}






No comments:

Post a Comment