1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-19 09:42:11 +03:00

[sam] adding USB updates

This commit is contained in:
Thibaut VIARD
2012-04-28 11:49:28 +02:00
parent ed0be7c1b8
commit c0a5eb38e2
23 changed files with 1623 additions and 345 deletions

View File

@ -37,7 +37,7 @@ UARTClass::UARTClass( Uart* pUart, IRQn_Type dwIrq, uint32_t dwId, RingBuffer* p
void UARTClass::begin( const uint32_t dwBaudRate ) void UARTClass::begin( const uint32_t dwBaudRate )
{ {
// Configure PMC // Configure PMC
PMC_EnablePeripheral( _dwId ) ; pmc_enable_periph_clk( _dwId ) ;
// Disable PDC channel // Disable PDC channel
_pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS ; _pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS ;
@ -73,7 +73,7 @@ void UARTClass::end( void )
// Wait for any outstanding data to be sent // Wait for any outstanding data to be sent
flush(); flush();
PMC_DisablePeripheral( _dwId ) ; pmc_disable_periph_clk( _dwId ) ;
} }
int UARTClass::available( void ) int UARTClass::available( void )

View File

@ -37,7 +37,7 @@ USARTClass::USARTClass( Usart* pUsart, IRQn_Type dwIrq, uint32_t dwId, RingBuffe
void USARTClass::begin( const uint32_t dwBaudRate ) void USARTClass::begin( const uint32_t dwBaudRate )
{ {
// Configure PMC // Configure PMC
PMC_EnablePeripheral( _dwId ) ; pmc_enable_periph_clk( _dwId ) ;
// Disable PDC channel // Disable PDC channel
_pUsart->US_PTCR = US_PTCR_RXTDIS | US_PTCR_TXTDIS ; _pUsart->US_PTCR = US_PTCR_RXTDIS | US_PTCR_TXTDIS ;
@ -74,7 +74,7 @@ void USARTClass::end( void )
// Wait for any outstanding data to be sent // Wait for any outstanding data to be sent
flush(); flush();
PMC_DisablePeripheral( _dwId ) ; pmc_disable_periph_clk( _dwId ) ;
} }
int USARTClass::available( void ) int USARTClass::available( void )

View File

@ -16,11 +16,13 @@
** SOFTWARE. ** SOFTWARE.
*/ */
#if defined(USBCON) #define USBCON
#include "Platform.h" #include "Platform.h"
#include "USBAPI.h" #include "USBAPI.h"
#include "USBDesc.h" #include "USBDesc.h"
#if defined(USBCON)
#ifdef HID_ENABLED #ifdef HID_ENABLED
//#define RAWHID_ENABLED //#define RAWHID_ENABLED
@ -43,9 +45,7 @@ Keyboard_ Keyboard;
#define RAWHID_TX_SIZE 64 #define RAWHID_TX_SIZE 64
#define RAWHID_RX_SIZE 64 #define RAWHID_RX_SIZE 64
extern const u8 _hidReportDescriptor[] PROGMEM; extern const u8 _hidReportDescriptor[] = {
const u8 _hidReportDescriptor[] = {
// Mouse // Mouse
0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54
0x09, 0x02, // USAGE (Mouse) 0x09, 0x02, // USAGE (Mouse)
@ -106,7 +106,7 @@ const u8 _hidReportDescriptor[] = {
0x81, 0x00, // INPUT (Data,Ary,Abs) 0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0, // END_COLLECTION 0xc0, // END_COLLECTION
#if RAWHID_ENABLED #ifdef RAWHID_ENABLED
// RAW HID // RAW HID
0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30 0x06, LSB(RAWHID_USAGE_PAGE), MSB(RAWHID_USAGE_PAGE), // 30
0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE), 0x0A, LSB(RAWHID_USAGE), MSB(RAWHID_USAGE),
@ -128,8 +128,7 @@ const u8 _hidReportDescriptor[] = {
#endif #endif
}; };
extern const HIDDescriptor _hidInterface PROGMEM; extern const HIDDescriptor _hidInterface =
const HIDDescriptor _hidInterface =
{ {
D_INTERFACE(HID_INTERFACE,1,3,0,0), D_INTERFACE(HID_INTERFACE,1,3,0,0),
D_HIDREPORT(sizeof(_hidReportDescriptor)), D_HIDREPORT(sizeof(_hidReportDescriptor)),
@ -278,11 +277,8 @@ void Keyboard_::sendReport(KeyReport* keys)
HID_SendReport(2,keys,sizeof(KeyReport)); HID_SendReport(2,keys,sizeof(KeyReport));
} }
extern
const uint8_t _asciimap[128] PROGMEM;
#define SHIFT 0x80 #define SHIFT 0x80
const uint8_t _asciimap[128] = extern const uint8_t _asciimap[128] =
{ {
0x00, // NUL 0x00, // NUL
0x00, // SOH 0x00, // SOH
@ -430,7 +426,7 @@ size_t Keyboard_::press(uint8_t k)
_keyReport.modifiers |= (1<<(k-128)); _keyReport.modifiers |= (1<<(k-128));
k = 0; k = 0;
} else { // it's a printing key } else { // it's a printing key
k = pgm_read_byte(_asciimap + k); k = _asciimap[k];
if (!k) { if (!k) {
setWriteError(); setWriteError();
return 0; return 0;
@ -474,7 +470,7 @@ size_t Keyboard_::release(uint8_t k)
_keyReport.modifiers &= ~(1<<(k-128)); _keyReport.modifiers &= ~(1<<(k-128));
k = 0; k = 0;
} else { // it's a printing key } else { // it's a printing key
k = pgm_read_byte(_asciimap + k); k = _asciimap[k];
if (!k) { if (!k) {
return 0; return 0;
} }
@ -510,9 +506,12 @@ void Keyboard_::releaseAll(void)
size_t Keyboard_::write(uint8_t c) size_t Keyboard_::write(uint8_t c)
{ {
/* TODO
uint8_t p = press(c); // Keydown uint8_t p = press(c); // Keydown
uint8_t r = release(c); // Keyup uint8_t r = release(c); // Keyup
return (p); // just return the result of press() since release() almost always returns 1 return (p); // just return the result of press() since release() almost always returns 1
*/
return 1 ;
} }
#endif #endif

View File

@ -28,7 +28,7 @@ extern USB_ USB;
class Serial_ : public Stream class Serial_ : public Stream
{ {
private: private:
ring_buffer *_cdc_rx_buffer; RingBuffer *_cdc_rx_buffer;
public: public:
void begin(uint16_t baud_count); void begin(uint16_t baud_count);
void end(void); void end(void);
@ -39,6 +39,7 @@ public:
virtual int read(void); virtual int read(void);
virtual void flush(void); virtual void flush(void);
virtual size_t write(uint8_t); virtual size_t write(uint8_t);
virtual void write(uint8_t);
operator bool(); operator bool();
}; };
extern Serial_ Serial; extern Serial_ Serial;

View File

@ -34,6 +34,7 @@ OUTPUT_BIN = ..
# Libraries # Libraries
PROJECT_BASE_PATH = .. PROJECT_BASE_PATH = ..
PROJECT_BASE_PATH_USB = ../USB
SYSTEM_PATH = ../../../system SYSTEM_PATH = ../../../system
CMSIS_ROOT_PATH = $(SYSTEM_PATH)/CMSIS CMSIS_ROOT_PATH = $(SYSTEM_PATH)/CMSIS
CMSIS_ARM_PATH=$(CMSIS_ROOT_PATH)/CMSIS/Include CMSIS_ARM_PATH=$(CMSIS_ROOT_PATH)/CMSIS/Include
@ -45,14 +46,15 @@ VARIANT_PATH = ../../../variants/$(VARIANT)
# Files # Files
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
vpath %.h $(PROJECT_BASE_PATH) $(SYSTEM_PATH) $(VARIANT_PATH) vpath %.h $(PROJECT_BASE_PATH) $(PROJECT_BASE_PATH_USB) $(SYSTEM_PATH) $(VARIANT_PATH)
vpath %.c $(PROJECT_BASE_PATH) $(VARIANT_PATH) vpath %.c $(PROJECT_BASE_PATH) $(PROJECT_BASE_PATH_USB) $(VARIANT_PATH)
vpath %.cpp $(PROJECT_BASE_PATH) $(PROJECT_BASE_PATH) vpath %.cpp $(PROJECT_BASE_PATH) $(PROJECT_BASE_PATH_USB) $(PROJECT_BASE_PATH)
VPATH+=$(PROJECT_BASE_PATH) VPATH+=$(PROJECT_BASE_PATH)
INCLUDES = INCLUDES =
INCLUDES += -I$(PROJECT_BASE_PATH) INCLUDES += -I$(PROJECT_BASE_PATH)
INCLUDES += -I$(PROJECT_BASE_PATH_USB)
INCLUDES += -I$(VARIANT_PATH) INCLUDES += -I$(VARIANT_PATH)
INCLUDES += -I$(CMSIS_ARM_PATH) INCLUDES += -I$(CMSIS_ARM_PATH)
INCLUDES += -I$(CMSIS_ATMEL_PATH) INCLUDES += -I$(CMSIS_ATMEL_PATH)
@ -86,7 +88,7 @@ OUTPUT_PATH=$(OUTPUT_OBJ)_$(VARIANT)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# C source files and objects # C source files and objects
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
C_SRC=$(wildcard $(PROJECT_BASE_PATH)/*.c) C_SRC=$(wildcard $(PROJECT_BASE_PATH)/*.c $(PROJECT_BASE_PATH_USB)/*.c)
C_OBJ_TEMP = $(patsubst %.c, %.o, $(notdir $(C_SRC))) C_OBJ_TEMP = $(patsubst %.c, %.o, $(notdir $(C_SRC)))
@ -98,7 +100,7 @@ C_OBJ=$(filter-out $(C_OBJ_FILTER), $(C_OBJ_TEMP))
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# CPP source files and objects # CPP source files and objects
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
CPP_SRC=$(wildcard $(PROJECT_BASE_PATH)/*.cpp) CPP_SRC=$(wildcard $(PROJECT_BASE_PATH)/*.cpp $(PROJECT_BASE_PATH_USB)/*.cpp)
CPP_OBJ_TEMP = $(patsubst %.cpp, %.o, $(notdir $(CPP_SRC))) CPP_OBJ_TEMP = $(patsubst %.cpp, %.o, $(notdir $(CPP_SRC)))

View File

@ -24,14 +24,14 @@
*/ */
int main( void ) int main( void )
{ {
init() ; init();
setup() ; setup();
for ( ; ; ) for (;;)
{ {
loop() ; loop();
} }
// return 0 ; // return 0 ;
} }

View File

@ -32,6 +32,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "sam.h"
#if defined ( __GNUC__ ) /* GCC CS3 */ #if defined ( __GNUC__ ) /* GCC CS3 */
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -109,6 +110,13 @@ extern int _write( int file, char *ptr, int len )
for ( iIndex=0 ; iIndex < len ; iIndex++, ptr++ ) for ( iIndex=0 ; iIndex < len ; iIndex++, ptr++ )
{ {
// UART_PutChar( *ptr ) ; // UART_PutChar( *ptr ) ;
// Check if the transmitter is ready
while ((UART->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY)
;
// Send character
UART->UART_THR = *ptr;
} }
return iIndex ; return iIndex ;

View File

@ -99,6 +99,7 @@ INCLUDES += -I$(SYSTEM_PATH)/libsam
INCLUDES += -I$(CMSIS_ARM_PATH) INCLUDES += -I$(CMSIS_ARM_PATH)
INCLUDES += -I$(CMSIS_ATMEL_PATH) INCLUDES += -I$(CMSIS_ATMEL_PATH)
INCLUDES += -I$(CMSIS_CHIP_PATH) INCLUDES += -I$(CMSIS_CHIP_PATH)
INCLUDES += -I$(PROJECT_BASE_PATH)/../USB
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
ifdef DEBUG ifdef DEBUG

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2011 Arduino. All right reserved. Copyright (c) 2012 Arduino. All right reserved.
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
@ -17,74 +17,86 @@
*/ */
#include "variant.h" #include "variant.h"
#include <stdio.h>
void setup( void ) // set pin numbers for the five buttons:
{ const int upButton = 2;
// Initialize the digital pin as an output. const int downButton = 3;
// Pin PIN_LED has a LED connected on most Arduino boards: const int leftButton = 4;
pinMode( PIN_LED, OUTPUT ) ; const int rightButton = 5;
digitalWrite( PIN_LED, LOW ) ; const int mouseButton = 6;
// Initialize the PIN_LED2 digital pin as an output. int range = 5; // output range of X or Y movement; affects movement speed
pinMode( PIN_LED2, OUTPUT ) ; int responseDelay = 10; // response delay of the mouse, in ms
digitalWrite( PIN_LED2, HIGH ) ;
Serial1.begin( 115200 ) ; /*
void setup() {
// initialize the buttons' inputs:
pinMode(upButton, INPUT);
pinMode(downButton, INPUT);
pinMode(leftButton, INPUT);
pinMode(rightButton, INPUT);
pinMode(mouseButton, INPUT);
// initialize mouse control:
Mouse.begin();
} }
static void led_step1( void ) void loop() {
{ // read the buttons:
#if defined sam3s_ek int upState = digitalRead(upButton);
digitalWrite( PIN_LED, HIGH ) ; // set the LED on int downState = digitalRead(downButton);
digitalWrite( PIN_LED2, LOW ) ; // set the red LED off int rightState = digitalRead(rightButton);
#endif /* sam3s_ek */ int leftState = digitalRead(leftButton);
int clickState = digitalRead(mouseButton);
#if defined sam3u_ek // calculate the movement distance based on the button states:
digitalWrite( PIN_LED, HIGH ) ; // set the LED on int xDistance = (leftState - rightState)*range;
digitalWrite( PIN_LED2, LOW ) ; // set the red LED off int yDistance = (upState - downState)*range;
#endif /* sam3u_ek */
#if defined arduino_due_x // if X or Y is non-zero, move:
digitalWrite( PIN_LED, LOW ) ; // set the LED on if ((xDistance != 0) || (yDistance != 0)) {
digitalWrite( PIN_LED2, LOW ) ; // set the red LED off Mouse.move(xDistance, yDistance, 0);
#endif /* arduino_due_x */
}
static void led_step2( void )
{
#if defined sam3s_ek
digitalWrite( PIN_LED, LOW ) ; // set the LED off
digitalWrite( PIN_LED2, HIGH ) ; // set the red LED on
#endif /* sam3s_ek */
#if defined sam3u_ek
digitalWrite( PIN_LED, LOW ) ; // set the LED off
digitalWrite( PIN_LED2, HIGH ) ; // set the red LED on
#endif /* sam3u_ek */
#if defined arduino_due_x
digitalWrite( PIN_LED, HIGH ) ; // set the LED off
digitalWrite( PIN_LED2, HIGH ) ; // set the red LED on
#endif /* arduino_due_x */
}
void loop( void )
{
led_step1() ;
delay( 1000 ) ; // wait for a second
led_step2() ;
delay( 1000 ) ; // wait for a second
Serial1.write( '-' ) ; // send a char
// Serial1.write( "test1\n" ) ; // send a string
// Serial1.write( "test2" ) ; // send another string
Serial1.print("Analog ins: ");
for (int i=A0; i<A11; i++) {
int a = analogRead(i);
Serial1.print(a, DEC);
Serial1.print(" ");
} }
Serial1.println();
delay(100); // if the mouse button is pressed:
if (clickState == HIGH) {
// if the mouse is not pressed, press it:
if (!Mouse.isPressed(MOUSE_LEFT)) {
Mouse.press(MOUSE_LEFT);
}
}
// else the mouse button is not pressed:
else {
// if the mouse is pressed, release it:
if (Mouse.isPressed(MOUSE_LEFT)) {
Mouse.release(MOUSE_LEFT);
}
}
// a delay so the mouse doesn't move too fast:
delay(responseDelay);
} }
*/
#include "USBAPI.h"
// Cet exemple fonctionne !!! ;-)
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
//pinMode(13, OUTPUT);
Serial1.begin(115200) ;
printf("USB test starting...\r\n");
}
void loop() {
//digitalWrite(13, HIGH); // set the LED on
//delay(1000); // wait for a second
//digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
printf("loop...\r\n");
}

View File

@ -33,7 +33,7 @@ extern void pinMode( uint32_t ulPin, uint32_t ulMode )
{ {
case INPUT: case INPUT:
/* Enable peripheral for clocking input */ /* Enable peripheral for clocking input */
PMC_EnablePeripheral( g_APinDescription[ulPin].ulPeripheralId ) ; pmc_enable_periph_clk( g_APinDescription[ulPin].ulPeripheralId ) ;
PIO_Configure( g_APinDescription[ulPin].pPort, PIO_INPUT, g_APinDescription[ulPin].ulPin, 0 ) ; PIO_Configure( g_APinDescription[ulPin].pPort, PIO_INPUT, g_APinDescription[ulPin].ulPin, 0 ) ;
break ; break ;
@ -41,7 +41,7 @@ extern void pinMode( uint32_t ulPin, uint32_t ulMode )
/* if all pins are output, disable PIO Controller clocking, reduce power consomption */ /* if all pins are output, disable PIO Controller clocking, reduce power consomption */
if ( g_APinDescription[ulPin].pPort->PIO_OSR == 0xffffffff ) if ( g_APinDescription[ulPin].pPort->PIO_OSR == 0xffffffff )
{ {
PMC_DisablePeripheral( g_APinDescription[ulPin].ulPeripheralId ) ; pmc_disable_periph_clk( g_APinDescription[ulPin].ulPeripheralId ) ;
} }
PIO_Configure( g_APinDescription[ulPin].pPort, PIO_OUTPUT_1, g_APinDescription[ulPin].ulPin, g_APinDescription[ulPin].ulPinConfiguration ) ; PIO_Configure( g_APinDescription[ulPin].pPort, PIO_OUTPUT_1, g_APinDescription[ulPin].ulPin, g_APinDescription[ulPin].ulPinConfiguration ) ;
break ; break ;

View File

@ -3,7 +3,8 @@
# --------------------- # ---------------------
name=Atmel SAM3 name=Atmel SAM3
compiler.path={runtime.ide.path}/hardware/tools/g++_arm_none_eabi/bin/ #compiler.path={runtime.ide.path}/hardware/tools/g++_arm_none_eabi/bin/
compiler.path=C:/arm-none-eabi-gcc-4_6/bin/
compiler.c.cmd=arm-none-eabi-gcc compiler.c.cmd=arm-none-eabi-gcc
compiler.c.flags=-c -g -Os -w -mlong-calls -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf compiler.c.flags=-c -g -Os -w -mlong-calls -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf
compiler.c.elf.cmd=arm-none-eabi-gcc compiler.c.elf.cmd=arm-none-eabi-gcc

View File

@ -176,7 +176,7 @@ $(OUTPUT_LIB): $(addprefix $(OUTPUT_PATH)/, $(C_OBJ)) $(addprefix $(OUTPUT_PATH)
.PHONY: clean .PHONY: clean
clean: clean:
@echo --- Cleaning $(CHIP) files $(OUTPUT_PATH) $(subst /,$(SEP),$(OUTPUT_BIN)/$(OUTPUT_LIB)) @echo --- Cleaning $(CHIP) files $(OUTPUT_PATH) $(subst /,$(SEP),$(OUTPUT_BIN)/$(OUTPUT_LIB))
-@$(RM) $(OUTPUT_PATH) -@$(RM) $(OUTPUT_PATH) 1>$(DEV_NUL) 2>&1
-@$(RM) $(subst /,$(SEP),$(OUTPUT_BIN)/$(OUTPUT_LIB)) 1>$(DEV_NUL) 2>&1 -@$(RM) $(subst /,$(SEP),$(OUTPUT_BIN)/$(OUTPUT_LIB)) 1>$(DEV_NUL) 2>&1
-@$(RM) $(subst /,$(SEP),$(OUTPUT_BIN)/$(OUTPUT_LIB)).txt 1>$(DEV_NUL) 2>&1 -@$(RM) $(subst /,$(SEP),$(OUTPUT_BIN)/$(OUTPUT_LIB)).txt 1>$(DEV_NUL) 2>&1

View File

@ -54,7 +54,7 @@
#include "include/wdt.h" #include "include/wdt.h"
#include "include/timetick.h" #include "include/timetick.h"
#include "include/USB_driver.h" #include "include/USB_device.h"
#if SAM3XA_SERIES #if SAM3XA_SERIES
#include "include/uotghs.h" #include "include/uotghs.h"

View File

@ -27,30 +27,399 @@
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
*/ */
#ifndef _PMC_ #ifndef PMC_H_INCLUDED
#define _PMC_ #define PMC_H_INCLUDED
/*---------------------------------------------------------------------------- #include "../chip.h"
* Headers
*----------------------------------------------------------------------------*/
#include <stdint.h>
/*----------------------------------------------------------------------------
* Exported functions
*----------------------------------------------------------------------------*/
/// @cond 0
/**INDENT-OFF**/
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif
/**INDENT-ON**/
/// @endcond
/** Bit mask for peripheral clocks (PCER0) */
#define PMC_MASK_STATUS0 (0xFFFFFFFC)
/** Bit mask for peripheral clocks (PCER1) */
#define PMC_MASK_STATUS1 (0xFFFFFFFF)
/** Loop counter timeout value */
#define PMC_TIMEOUT (2048)
/** Key to unlock CKGR_MOR register */
#define PMC_CKGR_MOR_KEY_VALUE CKGR_MOR_KEY(0x37)
/** Key used to write SUPC registers */
#define SUPC_KEY_VALUE ((uint32_t) 0xA5)
/** PMC xtal statup time */
#define PMC_XTAL_STARTUP_TIME (0x3F)
/** Mask to access fast startup input */
#define PMC_FAST_STARTUP_Msk (0xFFFFu)
/** PMC_WPMR Write Protect KEY, unlock it */
#define PMC_WPMR_WPKEY_VALUE PMC_WPMR_WPKEY((uint32_t) 0x504D43)
/** Using external oscillator */
#define PMC_OSC_XTAL 0
/** Oscillator in bypass mode */
#define PMC_OSC_BYPASS 1
#define PMC_PCK_0 0 /* PCK0 ID */
#define PMC_PCK_1 1 /* PCK1 ID */
#define PMC_PCK_2 2 /* PCK2 ID */
/**
* \name Master clock (MCK) Source and Prescaler configuration
*
* The following functions may be used to select the clock source and
* prescaler for the master clock.
*/
//@{
void pmc_mck_set_prescaler(uint32_t ul_pres);
void pmc_mck_set_source(uint32_t ul_source);
uint32_t pmc_switch_mck_to_sclk(uint32_t ul_pres);
uint32_t pmc_switch_mck_to_mainck(uint32_t ul_pres);
uint32_t pmc_switch_mck_to_pllack(uint32_t ul_pres);
#if (SAM3S_SERIES || SAM4S_SERIES)
uint32_t pmc_switch_mck_to_pllbck(uint32_t ul_pres);
#endif
#if (SAM3XA_SERIES || SAM3U_SERIES)
uint32_t pmc_switch_mck_to_upllck(uint32_t ul_pres);
#endif #endif
extern void PMC_EnablePeripheral( uint32_t dwId ) ; //@}
extern void PMC_DisablePeripheral( uint32_t dwId ) ;
extern uint32_t PMC_IsPeripheralEnabled( uint32_t dwId ) ; /**
* \name Slow clock (SLCK) oscillator and configuration
*
*/
//@{
void pmc_switch_sclk_to_32kxtal(uint32_t ul_bypass);
uint32_t pmc_osc_is_ready_32kxtal(void);
//@}
/**
* \name Main Clock (MAINCK) oscillator and configuration
*
*/
//@{
void pmc_switch_mainck_to_fastrc(uint32_t ul_moscrcf);
void pmc_osc_enable_fastrc(uint32_t ul_rc);
void pmc_osc_disable_fastrc(void);
void pmc_switch_mainck_to_xtal(uint32_t ul_bypass);
void pmc_osc_disable_xtal(uint32_t ul_bypass);
uint32_t pmc_osc_is_ready_mainck(void);
//@}
/**
* \name PLL oscillator and configuration
*
*/
//@{
void pmc_enable_pllack(uint32_t mula, uint32_t pllacount, uint32_t diva);
void pmc_disable_pllack(void);
uint32_t pmc_is_locked_pllack(void);
#if (SAM3S_SERIES || SAM4S_SERIES)
void pmc_enable_pllbck(uint32_t mulb, uint32_t pllbcount, uint32_t divb);
void pmc_disable_pllbck(void);
uint32_t pmc_is_locked_pllbck(void);
#endif
#if (SAM3XA_SERIES || SAM3U_SERIES)
void pmc_enable_upll_clock(void);
void pmc_disable_upll_clock(void);
uint32_t pmc_is_locked_upll(void);
#endif
//@}
/**
* \name Peripherals clock configuration
*
*/
//@{
uint32_t pmc_enable_periph_clk(uint32_t ul_id);
uint32_t pmc_disable_periph_clk(uint32_t ul_id);
void pmc_enable_all_periph_clk(void);
void pmc_disable_all_periph_clk(void);
uint32_t pmc_is_periph_clk_enabled(uint32_t ul_id);
//@}
/**
* \name Programmable clock Source and Prescaler configuration
*
* The following functions may be used to select the clock source and
* prescaler for the specified programmable clock.
*/
//@{
void pmc_pck_set_prescaler(uint32_t ul_id, uint32_t ul_pres);
void pmc_pck_set_source(uint32_t ul_id, uint32_t ul_source);
uint32_t pmc_switch_pck_to_sclk(uint32_t ul_id, uint32_t ul_pres);
uint32_t pmc_switch_pck_to_mainck(uint32_t ul_id, uint32_t ul_pres);
uint32_t pmc_switch_pck_to_pllack(uint32_t ul_id, uint32_t ul_pres);
#if (SAM3S_SERIES || SAM4S_SERIES)
uint32_t pmc_switch_pck_to_pllbck(uint32_t ul_id, uint32_t ul_pres);
#endif
#if (SAM3XA_SERIES || SAM3U_SERIES)
uint32_t pmc_switch_pck_to_upllck(uint32_t ul_id, uint32_t ul_pres);
#endif
void pmc_enable_pck(uint32_t ul_id);
void pmc_disable_pck(uint32_t ul_id);
void pmc_enable_all_pck(void);
void pmc_disable_all_pck(void);
uint32_t pmc_is_pck_enabled(uint32_t ul_id);
//@}
/**
* \name USB clock configuration
*
*/
//@{
#if (SAM3S_SERIES || SAM3XA_SERIES || SAM4S_SERIES)
void pmc_switch_udpck_to_pllack(uint32_t ul_usbdiv);
#endif
#if (SAM3S_SERIES || SAM4S_SERIES)
void pmc_switch_udpck_to_pllbck(uint32_t ul_usbdiv);
#endif
#if (SAM3XA_SERIES)
void pmc_switch_udpck_to_upllck(uint32_t ul_usbdiv);
#endif
#if (SAM3S_SERIES || SAM3XA_SERIES || SAM4S_SERIES)
void pmc_enable_udpck(void);
void pmc_disable_udpck(void);
#endif
//@}
/**
* \name Interrupt and status management
*
*/
//@{
void pmc_enable_interrupt(uint32_t ul_sources);
void pmc_disable_interrupt(uint32_t ul_sources);
uint32_t pmc_get_interrupt_mask(void);
uint32_t pmc_get_status(void);
//@}
/**
* \name Power management
*
* The following functions are used to configure sleep mode and additionnal
* wake up inputs.
*/
//@{
void pmc_set_fast_startup_input(uint32_t ul_inputs);
void pmc_clr_fast_startup_input(uint32_t ul_inputs);
void pmc_enable_sleepmode(uint8_t uc_type);
void pmc_enable_waitmode(void);
void pmc_enable_backupmode(void);
//@}
/**
* \name Write protection
*
*/
//@{
void pmc_set_writeprotect(uint32_t ul_enable);
uint32_t pmc_get_writeprotect_status(void);
//@}
/// @cond 0
/**INDENT-OFF**/
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
/**INDENT-ON**/
/// @endcond
#endif /* #ifndef _PMC_ */ //! @}
/**
* \page sam_pmc_quickstart Quick start guide for the SAM PMC module
*
* This is the quick start guide for the \ref pmc_group "PMC module", with
* step-by-step instructions on how to configure and use the driver in a
* selection of use cases.
*
* The use cases contain several code fragments. The code fragments in the
* steps for setup can be copied into a custom initialization function, while
* the steps for usage can be copied into, e.g., the main application function.
*
* \section pmc_use_cases PMC use cases
* - \ref pmc_basic_use_case Basic use case - Switch Main Clock sources
* - \ref pmc_use_case_2 Advanced use case - Configure Programmable Clocks
*
* \section pmc_basic_use_case Basic use case - Switch Main Clock sources
* In this use case, the PMC module is configured for a variety of system clock
* sources and speeds. A LED is used to visually indicate the current clock
* speed as the source is switched.
*
* \section pmc_basic_use_case_setup Setup
*
* \subsection pmc_basic_use_case_setup_prereq Prerequisites
* -# \ref gpio_group "General Purpose I/O Management (gpio)"
*
* \subsection pmc_basic_use_case_setup_code Code
* The following function needs to be added to the user application, to flash a
* board LED a variable number of times at a rate given in CPU ticks.
*
* \code
* #define FLASH_TICK_COUNT 0x00012345
*
* void flash_led(uint32_t tick_count, uint8_t flash_count)
* {
* SysTick->CTRL = SysTick_CTRL_ENABLE_Msk;
* SysTick->LOAD = tick_count;
*
* while (flash_count--)
* {
* gpio_toggle_pin(LED0_GPIO);
* while (!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk));
* gpio_toggle_pin(LED0_GPIO);
* while (!(SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk));
* }
* }
* \endcode
*
* \section pmc_basic_use_case_usage Use case
*
* \subsection pmc_basic_use_case_usage_code Example code
* Add to application C-file:
* \code
* for (;;)
* {
* pmc_switch_mainck_to_fastrc(CKGR_MOR_MOSCRCF_12_MHz);
* flash_led(FLASH_TICK_COUNT, 5);
* pmc_switch_mainck_to_fastrc(CKGR_MOR_MOSCRCF_8_MHz);
* flash_led(FLASH_TICK_COUNT, 5);
* pmc_switch_mainck_to_fastrc(CKGR_MOR_MOSCRCF_4_MHz);
* flash_led(FLASH_TICK_COUNT, 5);
* pmc_switch_mainck_to_xtal(0);
* flash_led(FLASH_TICK_COUNT, 5);
* }
* \endcode
*
* \subsection pmc_basic_use_case_usage_flow Workflow
* -# Wrap the code in an infinite loop:
* \code
* for (;;)
* \endcode
* -# Switch the Master CPU frequency to the internal 12MHz RC oscillator, flash
* a LED on the board several times:
* \code
* pmc_switch_mainck_to_fastrc(CKGR_MOR_MOSCRCF_12_MHz);
* flash_led(FLASH_TICK_COUNT, 5);
* \endcode
* -# Switch the Master CPU frequency to the internal 8MHz RC oscillator, flash
* a LED on the board several times:
* \code
* pmc_switch_mainck_to_fastrc(CKGR_MOR_MOSCRCF_8_MHz);
* flash_led(FLASH_TICK_COUNT, 5);
* \endcode
* -# Switch the Master CPU frequency to the internal 4MHz RC oscillator, flash
* a LED on the board several times:
* \code
* pmc_switch_mainck_to_fastrc(CKGR_MOR_MOSCRCF_4_MHz);
* flash_led(FLASH_TICK_COUNT, 5);
* \endcode
* -# Switch the Master CPU frequency to the external crystal oscillator, flash
* a LED on the board several times:
* \code
* pmc_switch_mainck_to_xtal(0);
* flash_led(FLASH_TICK_COUNT, 5);
* \endcode
*/
/**
* \page pmc_use_case_2 Use case #2 - Configure Programmable Clocks
* In this use case, the PMC module is configured to start the Slow Clock from
* an attached 32KHz crystal, and start one of the Programmable Clock modules
* sourced from the Slow Clock divided down with a prescale factor of 64.
*
* \section pmc_use_case_2_setup Setup
*
* \subsection pmc_use_case_2_setup_prereq Prerequisites
* -# \ref pio_group "Parallel Input/Output Controller (pio)"
*
* \subsection pmc_use_case_2_setup_code Code
* The following code must be added to the user application:
* \code
* pio_set_peripheral(PIOA, PIO_PERIPH_B, PIO_PA17);
* \endcode
*
* \subsection pmc_use_case_2_setup_code_workflow Workflow
* -# Configure the PCK1 pin to output on a specific port pin (in this case,
* PIOA pin 17) of the microcontroller.
* \code
* pio_set_peripheral(PIOA, PIO_PERIPH_B, PIO_PA17);
* \endcode
* \note The peripheral selection and pin will vary according to your selected
* SAM device model. Refer to the "Peripheral Signal Multiplexing on I/O
* Lines" of your device's datasheet.
*
* \section pmc_use_case_2_usage Use case
* The generated PCK1 clock output can be viewed on an oscilloscope attached to
* the correct pin of the microcontroller.
*
* \subsection pmc_use_case_2_usage_code Example code
* Add to application C-file:
* \code
* pmc_switch_sclk_to_32kxtal(PMC_OSC_XTAL);
* pmc_switch_pck_to_sclk(PMC_PCK_1, PMC_PCK_PRES_CLK_64);
* pmc_enable_pck(PMC_PCK_1);
*
* for (;;)
* {
* // Do Nothing
* }
* \endcode
*
* \subsection pmc_use_case_2_usage_flow Workflow
* -# Switch the Slow Clock source input to an external 32KHz crystal:
* \code
* pmc_switch_sclk_to_32kxtal(PMC_OSC_XTAL);
* \endcode
* -# Switch the Programmable Clock module PCK1 source clock to the Slow Clock,
* with a prescaler of 64:
* \code
* pmc_switch_pck_to_sclk(PMC_PCK_1, PMC_PCK_PRES_CLK_64);
* \endcode
* -# Enable Programmable Clock module PCK1:
* \code
* pmc_enable_pck(PMC_PCK_1);
* \endcode
* -# Enter an infinite loop:
* \code
* for (;;)
* {
* // Do Nothing
* }
* \endcode
*/
#endif /* PMC_H_INCLUDED */

File diff suppressed because it is too large Load Diff

View File

@ -128,7 +128,7 @@ extern void SPI_DisableIt( Spi* spi, uint32_t dwSources )
*/ */
extern void SPI_Configure( Spi* spi, uint32_t dwId, uint32_t dwConfiguration ) extern void SPI_Configure( Spi* spi, uint32_t dwId, uint32_t dwConfiguration )
{ {
PMC_EnablePeripheral( dwId ) ; pmc_enable_periph_clk( dwId ) ;
spi->SPI_CR = SPI_CR_SPIDIS ; spi->SPI_CR = SPI_CR_SPIDIS ;
/* Execute a software reset of the SPI twice */ /* Execute a software reset of the SPI twice */

View File

@ -20,7 +20,7 @@
#if SAM3S_SERIES || SAM4S_SERIES #if SAM3S_SERIES || SAM4S_SERIES
#include "USB_driver.h" #include "USB_device.h"
#include "udp.h" #include "udp.h"

View File

@ -20,7 +20,7 @@
#if 0 //SAM3U_SERIES #if 0 //SAM3U_SERIES
#include "USB_driver.h" #include "USB_device.h"
#include "udphs.h" #include "udphs.h"
/// Max size of the FMA FIFO /// Max size of the FMA FIFO

View File

@ -103,6 +103,12 @@
* #CS SS3 | PB23 * #CS SS3 | PB23
* *
* *
* USB pin | PORT
* ----------------+--------
* ID | PB11
* VBOF | PB10
*
*
* LEDs | PORT * LEDs | PORT
* ----------------+-------- * ----------------+--------
* "TX" | PA21 * "TX" | PA21
@ -263,6 +269,9 @@ extern const PinDescription g_APinDescription[]=
// 84 - USART3 (Serial4) all pins // 84 - USART3 (Serial4) all pins
{ PIOD, PIO_PD4B_TXD3|PIO_PD5B_RXD3, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NO_PWM, NO_TC }, { PIOD, PIO_PD4B_TXD3|PIO_PD5B_RXD3, ID_PIOD, PIO_PERIPH_B, PIO_DEFAULT, (PIN_ATTR_DIGITAL|PIN_ATTR_COMBO), NO_ADC, NO_ADC, NO_PWM, NO_TC },
// 85 - USB
{ PIOB, PIO_PB11A_UOTGID|PIO_PB10A_UOTGVBOF, ID_PIOB, PIO_PERIPH_A, PIO_DEFAULT, PIN_ATTR_DIGITAL,NO_ADC, NO_ADC, NO_PWM, NO_TC }, // ID - VBOF
// END // END
{ NULL, 0, 0, PIO_NOT_A_PIN, PIO_DEFAULT, 0, NO_ADC, NO_ADC, NO_PWM, NO_TC } { NULL, 0, 0, PIO_NOT_A_PIN, PIO_DEFAULT, 0, NO_ADC, NO_ADC, NO_PWM, NO_TC }
} ; } ;
@ -355,8 +364,15 @@ extern void init( void )
g_APinDescription[PINS_USART2].ulPin, g_APinDescription[PINS_USART2].ulPin,
g_APinDescription[PINS_USART2].ulPinConfiguration); g_APinDescription[PINS_USART2].ulPinConfiguration);
// Initialize USB
PIO_Configure(
g_APinDescription[PINS_USB].pPort,
g_APinDescription[PINS_USB].ulPinType,
g_APinDescription[PINS_USB].ulPin,
g_APinDescription[PINS_USB].ulPinConfiguration);
// Initialize 10bit Analog Controller // Initialize 10bit Analog Controller
PMC_EnablePeripheral( ID_ADC ) ; pmc_enable_periph_clk( ID_ADC ) ;
adc_init( ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST ) ; adc_init( ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST ) ;
adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1); adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1);
adc_configure_trigger(ADC, ADC_TRIG_SW, 0); // Disable hardware trigger. adc_configure_trigger(ADC, ADC_TRIG_SW, 0); // Disable hardware trigger.

View File

@ -125,6 +125,11 @@ static const uint8_t SCK = PIN_SPI_SCK ;
#define PINS_USART1 (83u) #define PINS_USART1 (83u)
#define PINS_USART2 (84u) #define PINS_USART2 (84u)
/*
* USB Interfaces
*/
#define PINS_USB (85u)
/* /*
* Analog pins * Analog pins
*/ */