Hi everyone,
I would like to move to AS7 from Arduino-IDE. For other peripherals bare-metal coding is fine but USB-CDC is something in another dimension for me. I was using SerialUSB.println and SerialUSB.write functions for data transmission or printing purposes.
How can i use SerialUSB in Atmel Studio 7 without creating a Arduino sketch in it. Which files do i need to put in the src directory. Or what would you suggest.
The reason i do not want to create a Arduino sketch is that it has its own hierarchy and it creates problem for example when i want to create my own SysTick functions with SysTick_Handler.
Any help is appreciated.
There is no issue with Arduino IDE if you need to use SysTick_Handler, you simply call sysTickHook().
See this example sketch to blink an led every 1 second thru Systick_Handler()/ SystickHook() and pendSVHook():
/*************************************************************************************
void SysTick Handler (void) {
i f ( sysTickHook ( ) ) return ;
. . .
}
void PendSV Handler ( void) f pendSVHook ( ) ;
int sysTickHook (void) __attribute__( (weak , alias ( " __false " ) ) ) ;
void pendSVHook (void) __attribute__( (weak , alias ( " __halt " ) ) ) ;
*************************************************************************************/
#define SYSTICK_FREQUENCY_HZ (1000)
#define Number_of_Ticks SystemCoreClock / SYSTICK_FREQUENCY_HZ
// sysTickHook will be triggered by sysTick_Handler once per ms
extern "C" {
int sysTickHook() {
SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk ;
return 0;
}
}
// pendSVHook will be triggered by systickHook once per ms
extern "C" {
__attribute__ ( ( naked ) )
void pendSVHook () {
blink();
}
}
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(250000);
/* Set interrupts to be preemptive. Change the grouping to set no
sub-priority.
See SAM3x8E datasheet 12.6.6 and 12.21.6.1 */
NVIC_SetPriorityGrouping (0b011) ;
/* Configure the system tick frequency to adjust the time quantum allocated
to processes. */
SysTick_Config (Number_of_Ticks) ;
/* Set the base priority register to 0 to allow any exception to be
handled.
See SAM3x8E datasheet 12.4.3.14 */
__set_BASEPRI (0) ;
/* Force the PendSV exception to have the lowest priority to avoid killing
other interrupts.
See SAM3x8E datasheet 12.20.10.1 */
NVIC_SetPriority ((IRQn_Type)PendSV_IRQn, 0xFF) ;
NVIC_SetPriority ((IRQn_Type)SysTick_IRQn, 0xFF) ; // Set the lowest priority for SysTick
}
void loop() { }
void blink() {
static uint16_t i = 0;
if (i++ == 1000) {
i = 0;
digitalWrite(LED_BUILTIN, !digitalRead(13));
}
}
Thanks for reply. Systick handler was one problem as an example.
In general for debugging i want to go to AS7 but when i use it, i do not know how to add USB functionality to my any project.
I do not know which libraries do i need and where do i need to add them etc.