Skip to content

Commit

Permalink
Implement samx7x host
Browse files Browse the repository at this point in the history
  • Loading branch information
rechrtb committed Apr 29, 2024
1 parent 7dad5d9 commit 80d423d
Show file tree
Hide file tree
Showing 4 changed files with 720 additions and 2 deletions.
1 change: 1 addition & 0 deletions hw/bsp/duet_mb6hc/board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ LD_FILE = $(ASF_DIR)/same70b/gcc/gcc/same70q21b_flash.ld

SRC_C += \
src/portable/microchip/samx7x/dcd_samx7x.c \
src/portable/microchip/samx7x/hcd_samx7x.c \
$(ASF_DIR)/same70b/gcc/gcc/startup_same70q21b.c \
$(ASF_DIR)/same70b/gcc/system_same70q21b.c \
$(ASF_DIR)/hpl/core/hpl_init.c \
Expand Down
19 changes: 17 additions & 2 deletions hw/bsp/duet_mb6hc/duet_mb6hc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
#define LED_PIN GPIO(GPIO_PORTD, 26)
#if CFG_TUH_ENABLED
#define USB_HOST_POWER_PIN GPIO(GPIO_PORTC, 6)
#endif

#define LED_PIN GPIO(GPIO_PORTB, 26)
#define BUTTON_PIN GPIO(GPIO_PORTD, 25)
#define BUTTON_STATE_ACTIVE 0

Expand All @@ -62,6 +65,14 @@ void board_init(void)
/* Disable Watchdog */
hri_wdt_set_MR_WDDIS_bit(WDT);

#if CFG_TUH_ENABLED
// USB_HOST_POWER_PIN
_pmc_enable_periph_clock(ID_PIOC);
gpio_set_pin_level(USB_HOST_POWER_PIN, false);
gpio_set_pin_direction(USB_HOST_POWER_PIN, GPIO_DIRECTION_OUT);
gpio_set_pin_function(USB_HOST_POWER_PIN, GPIO_PIN_FUNCTION_OFF);
#endif

_pmc_enable_periph_clock(ID_PIOD);

// LED
Expand Down Expand Up @@ -92,7 +103,7 @@ void board_init(void)
_pmc_enable_periph_clock(ID_USBHS);

#if CFG_TUH_ENABLED
gpio_set_pin_level(USB_HOST_POWER_PIN, state);
gpio_set_pin_level(USB_HOST_POWER_PIN, true);
# endif
}

Expand All @@ -104,6 +115,10 @@ void USBHS_Handler(void)
#if CFG_TUD_ENABLED
tud_int_handler(0);
#endif

#if CFG_TUH_ENABLED
tuh_int_handler(0);
#endif
}

//--------------------------------------------------------------------+
Expand Down
82 changes: 82 additions & 0 deletions src/portable/microchip/samx7x/common_usb_defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Microchip Technology Inc.
* Copyright (c) 2018, hathach (tinyusb.org)
* Copyright (c) 2024, Duet3D
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
#ifndef _COMMON_USB_DEFS_H_
#define _COMMON_USB_DEFS_H_

#include <stdint.h>

#include "common/tusb_types.h"
#include "common/tusb_common.h"
#include "common_usb_regs.h"

#define PEP_GET_FIFO_PTR(ep, scale) (((TU_XSTRCAT(TU_STRCAT(uint, scale),_t) (*)[0x8000 / ((scale) / 8)])FIFO_RAM_ADDR)[(ep)])
#define DMA_TRANS_MAX 0x10000
#define PIPE_MAX_PACKET_SIZE 1024


TU_ATTR_ALWAYS_INLINE static inline void hw_enter_critical(volatile uint32_t *atomic)
{
*atomic = __get_PRIMASK();
__disable_irq();
__DMB();
}

TU_ATTR_ALWAYS_INLINE static inline void hw_exit_critical(volatile uint32_t *atomic)
{
__DMB();
__set_PRIMASK(*atomic);
}

TU_ATTR_ALWAYS_INLINE static inline void hw_cache_invalidate(uint32_t *addr, int32_t size)
{
if (SCB->CCR & SCB_CCR_DC_Msk)
{
SCB_CleanInvalidateDCache_by_Addr(addr, size);
}
else
{
__DSB();
__ISB();
}
}

TU_ATTR_ALWAYS_INLINE static inline tusb_speed_t hw_port_speed_get(void)
{
switch (USB_REG->SR & SR_SPEED)
{
case SR_SPEED_FULL_SPEED:
default:
return TUSB_SPEED_FULL;
case SR_SPEED_HIGH_SPEED:
return TUSB_SPEED_HIGH;
case SR_SPEED_LOW_SPEED:
return TUSB_SPEED_LOW;
};
}

#endif
Loading

0 comments on commit 80d423d

Please sign in to comment.