Skip to content

Commit

Permalink
use max32 cmsis, fix NVIC_GetEnableIRQ() not defined when using with …
Browse files Browse the repository at this point in the history
…CMISIS < 5
  • Loading branch information
hathach committed Aug 14, 2024
1 parent f6b96f7 commit 0be427b
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 37 deletions.
16 changes: 14 additions & 2 deletions hw/bsp/max32650/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,24 @@
* This file is part of the TinyUSB stack.
*/

#include "board.h"
#include "bsp/board_api.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-prototypes" // _mxc_crit_get_state()
#endif

#include "gpio.h"
#include "mxc_sys.h"
#include "mxc_device.h"
#include "uart.h"

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#include "board.h"
#include "bsp/board_api.h"


//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
Expand Down
1 change: 0 additions & 1 deletion hw/bsp/max32650/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ function(add_board_target BOARD_TARGET)
)
target_include_directories(${BOARD_TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
${CMSIS_5}/CMSIS/Core/Include
${MAX32_CMSIS}/Include
${MAX32_CMSIS}/Device/Maxim/MAX32650/Include
${MAX32_PERIPH}/Include/MAX32650
Expand Down
3 changes: 1 addition & 2 deletions hw/bsp/max32650/family.mk
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@ SRC_C += \
$(PERIPH_SRC)/ICC/icc_reva.c \
$(PERIPH_SRC)/ICC/icc_common.c \
$(PERIPH_SRC)/TPU/tpu_me10.c \
$(PERIPH_SRC)/TPU/tpu_reva.c \
$(PERIPH_SRC)/TPU/tpu_reva.c \
$(PERIPH_SRC)/UART/uart_common.c \
$(PERIPH_SRC)/UART/uart_me10.c \
$(PERIPH_SRC)/UART/uart_reva.c \

INC += \
$(TOP)/$(BOARD_PATH) \
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
$(TOP)/$(MAX32_CMSIS)/Include \
$(TOP)/$(MAX32_CMSIS)/Device/Maxim/MAX32650/Include \
$(TOP)/$(MAX32_PERIPH)/Include/MAX32650 \
Expand Down
15 changes: 13 additions & 2 deletions hw/bsp/max32666/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,24 @@
* This file is part of the TinyUSB stack.
*/

#include "board.h"
#include "bsp/board_api.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-prototypes" // _mxc_crit_get_state()
#endif

#include "gpio.h"
#include "mxc_sys.h"
#include "mcr_regs.h"
#include "mxc_device.h"
#include "uart.h"

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#include "board.h"
#include "bsp/board_api.h"

//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
Expand Down
1 change: 0 additions & 1 deletion hw/bsp/max32666/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ function(add_board_target BOARD_TARGET)
)
target_include_directories(${BOARD_TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
${CMSIS_5}/CMSIS/Core/Include
${MAX32_CMSIS}/Include
${MAX32_CMSIS}/Device/Maxim/MAX32665/Include
${MAX32_PERIPH}/Include/MAX32665
Expand Down
1 change: 0 additions & 1 deletion hw/bsp/max32666/family.mk
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ SRC_C += \

INC += \
$(TOP)/$(BOARD_PATH) \
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
$(TOP)/$(MAX32_CMSIS)/Include \
$(TOP)/$(MAX32_CMSIS)/Device/Maxim/MAX32665/Include \
$(TOP)/$(MAX32_PERIPH)/Include/MAX32665 \
Expand Down
16 changes: 14 additions & 2 deletions hw/bsp/max32690/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,25 @@
* This file is part of the TinyUSB stack.
*/

#include "board.h"
#include "bsp/board_api.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-prototypes" // _mxc_crit_get_state()
#endif

#include "gpio.h"
#include "mxc_sys.h"
#include "mcr_regs.h"
#include "mxc_device.h"
#include "uart.h"

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#include "board.h"
#include "bsp/board_api.h"


//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
Expand Down
1 change: 0 additions & 1 deletion hw/bsp/max32690/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function(add_board_target BOARD_TARGET)
)
target_include_directories(${BOARD_TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
${CMSIS_5}/CMSIS/Core/Include
${MAX32_CMSIS}/Include
${MAX32_CMSIS}/Device/Maxim/MAX32690/Include
${MAX32_PERIPH}/Include/MAX32690
Expand Down
1 change: 0 additions & 1 deletion hw/bsp/max32690/family.mk
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ SRC_C += \

INC += \
$(TOP)/$(BOARD_PATH) \
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
$(TOP)/$(MAX32_CMSIS)/Include \
$(TOP)/$(MAX32_CMSIS)/Device/Maxim/MAX32690/Include \
$(TOP)/$(MAX32_PERIPH)/Include/MAX32690 \
Expand Down
15 changes: 13 additions & 2 deletions hw/bsp/max78002/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,24 @@
* This file is part of the TinyUSB stack.
*/

#include "board.h"
#include "bsp/board_api.h"
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-prototypes" // _mxc_crit_get_state()
#endif

#include "gpio.h"
#include "mxc_sys.h"
#include "mcr_regs.h"
#include "mxc_device.h"
#include "uart.h"

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#include "board.h"
#include "bsp/board_api.h"

//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
Expand Down
1 change: 0 additions & 1 deletion hw/bsp/max78002/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function(add_board_target BOARD_TARGET)
)
target_include_directories(${BOARD_TARGET} PUBLIC
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
${CMSIS_5}/CMSIS/Core/Include
${MAX32_CMSIS}/Include
${MAX32_CMSIS}/Device/Maxim/MAX78002/Include
${MAX32_PERIPH}/Include/MAX78002
Expand Down
1 change: 0 additions & 1 deletion hw/bsp/max78002/family.mk
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ SRC_C += \

INC += \
$(TOP)/$(BOARD_PATH) \
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
$(TOP)/$(MAX32_CMSIS)/Include \
$(TOP)/$(MAX32_CMSIS)/Device/Maxim/MAX78002/Include \
$(TOP)/$(MAX32_PERIPH)/Include/MAX78002 \
Expand Down
33 changes: 14 additions & 19 deletions src/portable/mentor/musb/musb_max32.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@
extern "C" {
#endif

#if TU_CHECK_MCU(OPT_MCU_MAX32690, OPT_MCU_MAX32650, OPT_MCU_MAX32666, OPT_MCU_MAX78002)
#include "mxc_device.h"
#include "usbhs_regs.h"
#else
#error "Unsupported MCUs"
#endif

#include "mxc_device.h"
#include "usbhs_regs.h"

#if CFG_TUD_ENABLED
#define USBHS_M31_CLOCK_RECOVERY
Expand All @@ -48,39 +43,39 @@ static mxc_usbhs_regs_t* const musb_periph_inst[] = {
};

// Mapping of IRQ numbers to port. Currently just 1.
static const IRQn_Type musb_irqs[] = {
static const IRQn_Type musb_irqs[] = {
USB_IRQn
};

TU_ATTR_ALWAYS_INLINE
static inline void musb_dcd_int_enable(uint8_t rhport)
{
static inline void musb_dcd_int_enable(uint8_t rhport) {
NVIC_EnableIRQ(musb_irqs[rhport]);
}

TU_ATTR_ALWAYS_INLINE
static inline void musb_dcd_int_disable(uint8_t rhport)
{
static inline void musb_dcd_int_disable(uint8_t rhport) {
NVIC_DisableIRQ(musb_irqs[rhport]);
}

TU_ATTR_ALWAYS_INLINE
static inline unsigned musb_dcd_get_int_enable(uint8_t rhport)
{
static inline unsigned musb_dcd_get_int_enable(uint8_t rhport) {
#ifdef NVIC_GetEnableIRQ // only defined in CMSIS 5
return NVIC_GetEnableIRQ(musb_irqs[rhport]);
#else
uint32_t IRQn = (uint32_t) musb_irqs[rhport];
return ((NVIC->ISER[IRQn >> 5UL] & (1UL << (IRQn & 0x1FUL))) != 0UL) ? 1UL : 0UL;
#endif
}

TU_ATTR_ALWAYS_INLINE
static inline void musb_dcd_int_clear(uint8_t rhport)
{
NVIC_ClearPendingIRQ(musb_irqs[rhport]);
static inline void musb_dcd_int_clear(uint8_t rhport) {
NVIC_ClearPendingIRQ(musb_irqs[rhport]);
}

//Used to save and restore user's register map when interrupt occurs
static volatile unsigned isr_saved_index = 0;

static inline void musb_dcd_int_handler_enter(uint8_t rhport)
{
static inline void musb_dcd_int_handler_enter(uint8_t rhport) {
uint32_t mxm_int, mxm_int_en, mxm_is;

//save current register index
Expand Down
2 changes: 1 addition & 1 deletion tools/get_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'fc100s'],
'hw/mcu/analog/max32' : ['https://github.com/analogdevicesinc/msdk.git',
'b20b398d3e5e2007594e54a74ba3d2a2e50ddd75',
'max32690 max32650 max32666 max78002'],
'max32650 max32666 max32690 max78002'],
'hw/mcu/bridgetek/ft9xx/ft90x-sdk': ['https://github.com/BRTSG-FOSS/ft90x-sdk.git',
'91060164afe239fcb394122e8bf9eb24d3194eb1',
'brtmm90x'],
Expand Down

0 comments on commit 0be427b

Please sign in to comment.