Skip to content

Commit

Permalink
Merge branch 'composite_usb_audio'
Browse files Browse the repository at this point in the history
  • Loading branch information
twatorowski committed Feb 16, 2020
2 parents 0d7dbce + 0db2892 commit 234bdbe
Show file tree
Hide file tree
Showing 57 changed files with 4,856 additions and 487 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ SRC += ./base64/src/base64.c
# device drivers
SRC += ./dev/src/usart2.c ./dev/src/watchdog.c
SRC += ./dev/src/cpuclock.c ./dev/src/fpu.c
SRC += ./dev/src/analog.c ./dev/src/i2c1.c
SRC += ./dev/src/i2c1.c
SRC += ./dev/src/cs43l22.c ./dev/src/rfin.c
SRC += ./dev/src/sai1a.c ./dev/src/display.c
SRC += ./dev/src/extimux.c ./dev/src/joystick.c
Expand All @@ -52,6 +52,10 @@ SRC += ./dev/src/timemeas.c ./dev/src/led.c
SRC += ./dev/src/invoke.c ./dev/src/lsi.c
SRC += ./dev/src/dec.c

SRC += ./dev/src/usb.c ./dev/src/usbcore.c
SRC += ./dev/src/usbdesc.c ./dev/src/usb_vcp.c
SRC += ./dev/src/usb_audiosrc.c

# digital signal processing
SRC += ./dsp/src/biquad.c

Expand All @@ -62,12 +66,15 @@ SRC += ./radio/src/radio.c ./radio/src/dec4.c

# system files
SRC += ./sys/src/critical.c ./sys/src/ev.c
SRC += ./sys/src/sem.c
SRC += ./sys/src/sem.c ./sys/src/idle.c

# tests
SRC += ./test/src/usart2.c ./test/src/dac_sine.c
SRC += ./test/src/dec.c ./test/src/radio.c
SRC += ./test/src/am_radio.c ./test/src/float_fixp.c
SRC += ./test/src/vcp.c ./test/src/vcp_rate.c
SRC += ./test/src/rfin.c ./test/src/rf_dec.c
SRC += ./test/src/rf_dec_usb.c

# utilities
SRC += ./util/src/string.c ./util/src/stdio.c
Expand Down
6 changes: 3 additions & 3 deletions arch/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static inline ALWAYS_INLINE void Arch_NOP(void)
* @param src source address to load from. must be 32-bit aligned
* @return 32-bit value present at address @p ptr
*/
static inline ALWAYS_INLINE uint32_t Arch_LDREX(void *src)
static inline ALWAYS_INLINE uint32_t Arch_LDREX(volatile void *src)
{
/* result */
uint32_t result;
Expand All @@ -55,7 +55,7 @@ static inline ALWAYS_INLINE uint32_t Arch_LDREX(void *src)
* @param value value to be stored
* @return 0 in case of success, 1 otherwise
*/
static inline ALWAYS_INLINE int Arch_STREX(void *dst, uint32_t value)
static inline ALWAYS_INLINE int Arch_STREX(volatile void *dst, uint32_t value)
{
/* storage result */
int result;
Expand Down Expand Up @@ -98,7 +98,7 @@ static inline ALWAYS_INLINE void Arch_ISB(void)
*
* @param x value to be written
*/
static inline ALWAYS_INLINE void Arch_WriteBasepri(uint32_t x)
static inline ALWAYS_INLINE void Arch_WriteBasepri(int x)
{
/* assembly code */
ASM volatile (
Expand Down
2 changes: 1 addition & 1 deletion assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "reset.h"
#include "util/concatstr.h"

#define DEBUG
// #define DEBUG
#include "debug_dump.h"

/* assert message prefix */
Expand Down
87 changes: 71 additions & 16 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
/** @name System CPU Frequency */
/** @{ */
/** @brief reference oscillator speed (hse or it's prescaled version) */
#define CPUCLOCK_REF_FREQ 8000000
#define CPUCLOCK_REF_FREQ 4000000
/** @brief system frequency in Hz */
#define CPUCLOCK_FREQ 80000000
#define CPUCLOCK_FREQ 72000000
/** @} */

/** @name Debug configuration */
Expand Down Expand Up @@ -71,18 +71,18 @@
/** @{ */
/** @brief disable/enable led globally */
#define LED_ENABLE 1
/** @brief show cpu activity on led */
#define LED_IDLE_SHOW_ACTIVITY 1
/** @} */

/** @name Interrupt Priorities */
/** @{ */
/** @brief data received callback priority (0x00 - highest, 0xf0 lowest) */
#define INT_PRI_USART2_RX 0x20
#define INT_PRI_USART2_RX 0xf0
/** @brief data sent callback priority (0x00 - highest, 0xf0 lowest) */
#define INT_PRI_USART2_TX 0xf0
/** @brief async delay priority */
#define INT_PRI_AWAIT 0xf0
/** @brief external voltage monitor interrupt priority */
#define INT_PRI_VIN 0xf0
/** @brief rf sampling priority */
#define INT_PRI_RFIN 0x30
/** @brief decimator interrupt priority */
#define INT_PRI_DEC 0x20
/** @brief exti multiplexer interrupt priority for exti[5-9] */
Expand All @@ -91,6 +91,12 @@
#define INT_PRI_EXI10_15 0xf0
/** @brief invoke interrupt priority */
#define INT_PRI_INVOKE 0x50
/** @brief async delay priority */
#define INT_PRI_AWAIT 0x10
/** @brief USB priority */
#define INT_PRI_USB 0x20
/** @brief LCD priority */
#define INT_PRI_LCD 0xf0
/** @} */

/** @name USART2 configuration */
Expand All @@ -99,14 +105,6 @@
#define USART2_BAUD_RATE 1500000
/** @} */

/** @name IQ Decimators */
/** @{ */
/** @brief decimation rate, must be a power of 2 */
#define DEC_DECIMATION_RATE 64
/** maximal input word bit width */
#define DEC_MAX_INPUT_BITS 14
/** @} */

/** @name CS43L22 configuration */
/** @{ */
/** @brief DAC's i2c address */
Expand All @@ -116,11 +114,68 @@
/** @name RF paramaters */
/** @{ */
/** @brief Sampling frequency */
#define RF_SAMPLING_FREQ 2500000
#define RF_SAMPLING_FREQ 2400000
/** @define number of bits per rf sample */
#define RF_SAMPLING_BITS 12
/** @} */

/** @name IQ Decimators */
/** @{ */
/** @brief decimation rate */
#define DEC_DECIMATION_RATE 50
/** maximal input word bit width */
#define DEC_MAX_INPUT_BITS 14
/** @} */

/** @name Baseband Sampling rate (after the decimation) */
/** @{ */
/** @brief decimation rate */
#define BB_SAMPLING_RATE \
(RF_SAMPLING_FREQ / DEC_DECIMATION_RATE)

/** @name SAI1 configuration */
/** @{ */
/** @brief serial audio interface sampling rate */
#define SAI1_SAMPLING_RATE BB_SAMPLING_RATE
/** */
/** @} */

/** @name USB module */
/** @{ */
/** @brief use the true serial number */
#define USB_SN_SIZE 58
/** @brief control endpoint max size (bidirectional) */
#define USB_CTRLEP_SIZE 64
/** @brief interrupt endpoint transfer size (must be a power of 2) */
#define USB_VCP_INT_SIZE 8
/** @brief transmission packet size (must be a power of 2) */
#define USB_VCP_TX_SIZE 32
/** @brief reception packet size (must be a power of 2) */
#define USB_VCP_RX_SIZE 32
/** @brief usb audio sampling rate */
#define USB_AUDIO_SRC_SAMPLING_RATE BB_SAMPLING_RATE
/** @brief usb audio frame rate */
#define USB_AUDIO_SRC_FRAME_RATE 1000
/** @brief usb audio sampling rate */
#define USB_AUDIO_SRC_SAMPLES_PER_FRAME \
(USB_AUDIO_SRC_SAMPLING_RATE / USB_AUDIO_SRC_FRAME_RATE)
/** @brief usb audio: bits per sample (8, 16, 24, 32) */
#define USB_AUDIO_SRC_BITS_PER_SAMPLE 32
/** @brief usb audio frame size: mono mode */
#define USB_AUDIO_SRC_MONO_SIZE \
(1 * USB_AUDIO_SRC_SAMPLING_RATE * USB_AUDIO_SRC_BITS_PER_SAMPLE / \
USB_AUDIO_SRC_FRAME_RATE / 8)
/** @brief usb audio frame size: stereo mode */
#define USB_AUDIO_SRC_STEREO_SIZE \
(2 * USB_AUDIO_SRC_SAMPLING_RATE * USB_AUDIO_SRC_BITS_PER_SAMPLE / \
USB_AUDIO_SRC_FRAME_RATE / 8)
/** @brief usb audio max transfer size */
#define USB_AUDIO_SRC_MAX_TFER_SIZE 512
/** @brief usb uses common fifo for reception so we need to set it's size to
* hold the largest packet possible */
#define USB_RX_FIFO_SIZE 512
/** @} */



#endif /* CONFIG_H_ */
4 changes: 4 additions & 0 deletions debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "compiler.h"
#include "err.h"
#include "version.h"
#include "dev/systime.h"
#include "sys/sem.h"

#define DEBUG
Expand Down Expand Up @@ -109,6 +110,9 @@ int Debug_Init(void)
Debug_PrintSCBInfo(&debug_scb_info);
Debug_PrintAssertInfo(&debug_assert_info);

/* give it some time to flow out of the debug interfaces */
SysTime_Delay(100);

/* report status */
return EOK;
}
9 changes: 5 additions & 4 deletions defhndl.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
#include "compiler.h"

#include "err.h"
#include "reset.h"
#include "arch/arch.h"
#include "stm32l476/scb.h"

#define DEBUG
#include "debug_dump.h"

/* dump information to storage */
static void DefHndl_Dump(void *sp, uint32_t ipsr)
static void OPTIMIZE ("O0") DefHndl_Dump(void *sp, uint32_t ipsr)
{
/* placeholders */
volatile debug_exc_info_t *ei = &debug_exc_info;
Expand Down Expand Up @@ -53,7 +54,7 @@ static void DefHndl_Dump(void *sp, uint32_t ipsr)
}

/* default interrupt/exception handler */
void DefHndl_DefaultHandler(void)
void OPTIMIZE ("O0") NAKED DefHndl_DefaultHandler(void)
{
/* read the stack pointer */
void * sp = (void *)Arch_ReadMSP();
Expand All @@ -63,6 +64,6 @@ void DefHndl_DefaultHandler(void)
/* dump all the information */
DefHndl_Dump(sp, ipsr);

/* watchog will have the pleasure of kicking the system */
while (1);
/* reset the system */
Reset_ResetMCU();
}
4 changes: 4 additions & 0 deletions dev/dec.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <stdint.h>

#include "sys/cb.h"
#include "sys/sem.h"

/* decimator semaphore */
extern sem_t dec_sem;

/** @brief decimation callback argument type */
typedef struct dec_cbarg {
Expand Down
17 changes: 15 additions & 2 deletions dev/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
#ifndef DEV_DISPLAY_H_
#define DEV_DISPLAY_H_

#include "sys/cb.h"
#include "sys/sem.h"

/* semaphore */
extern sem_t display_sem;

/** @brief lcd interrupt */
void Display_LCDIsr(void);

/**
* @brief Initialize the display module
*
Expand All @@ -28,8 +37,12 @@ int Display_Init(void);
void Display_SetCharacter(int pos, char c);

/**
* @brief Transfers the LCD RAM contents to the Display itself
* @brief Transfers the LCD RAM contents to the Display itself.
*
* @param cb callback to be called when the transfer is complete
*
* @return void * null
*/
void Display_Update(void);
void * Display_Update(cb_t cb);

#endif /* DEV_DISPLAY_H_ */
39 changes: 38 additions & 1 deletion dev/rfin.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,48 @@
#ifndef DEV_RFIN_H_
#define DEV_RFIN_H_

#include <stdint.h>

#include "sys/ev.h"

/** @name event types */
/** @{ */
/** @brief half transfer */
#define RFIN_TYPE_HT 0x01
/** @brief full transfer */
#define RFIN_TYPE_FT 0x02
/**@} */

/** @brief rf samples ready event */
extern ev_t rfin_ev;

/** @brief samples ready event argument */
typedef struct rfin_evarg {
/**< number of samples */
int type, num;
/**< samples pointer */
int16_t *samples;
} rfin_evarg_t;

/** @brief adc dma1 interrupt */
void RFIn_DMA1C1Isr(void);

/**
* @brief Initialize and prepare the main RF input
* @brief Initialize and prepare the main RF input. Initialize the ADC. For
* sampling rate configuration please see the config.h
*
* @return int status (@ref ERR_ERROR_CODES)
*/
int RFIn_Init(void);

/**
* @brief Starts sampling with the period given by the prescaled HCLK clock.
* After the sampling is started then the data containing events will be
* produced.
*
* @param ptr pointer to the circular data buffer
* @param num size of buffer expressed in number of elements.
*/
void RFIn_StartSampling(int16_t *ptr, int num);

#endif /* DEV_RFIN_H_ */
3 changes: 1 addition & 2 deletions dev/sai1a.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ int SAI1A_Init(void);
* @brief Start Streaming audio samples stored in the cricular buffer pointed
* by ptr that is `num` samples in size
*
* @param sampling_rate desired sampling rate
* @param ptr buffer pointer
* @param num size of buffer expressed in number of samples
*/
void SAI1A_StartStreaming(float sampling_rate, const int32_t *ptr, int num);
void SAI1A_StartStreaming(const int32_t *ptr, int num);


#endif /* DEV_SAI1A_H_ */
13 changes: 1 addition & 12 deletions dev/src/analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void Analog_DMA1C1Isr(void)
/* notify others */
Ev_Notify(&analog_ev, &ea);
}

/* initialize adc */
int Analog_Init(void)
{
Expand Down Expand Up @@ -86,15 +87,6 @@ int Analog_Init(void)
/* apply prescaler setting */
TIM2->EGR = TIM_EGR_UG;

// TIM2->ARR = 79;
// TIM2->CCR1 = 70;
// TIM2->CCMR1 = TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1;
// TIM2->CCER = TIM_CCER_CC1E;
// GPIOA->MODER &= ~GPIO_MODER_MODER0;
// GPIOA->AFRL |= 1 << 0;
// GPIOA->MODER |= GPIO_MODER_MODER0_1;
// GPIOA->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR0;

/* select dma channel */
DMA1->CSELR = (DMA1->CSELR & ~DMA_CSELR_C1S) | DMA1_CSELR_C1S_ADC1;
/* select mode: 16b transfers, circular buffer, generate interrupts */
Expand Down Expand Up @@ -131,9 +123,6 @@ int Analog_Init(void)
* mode */
ADC1->CFGR = ADC_CFGR_OVRMOD | ADC_CFGR_EXTSEL_TIM2_TRGO | ADC_CFGR_DMAEN |
ADC_CFGR_EXTEN_RE | ADC_CFGR_DMACFG;
// /* enable oversampling: 2x, shift by 1 bit */
// ADC1->CFGR2 = ADC_CFGR2_TROVS | 1 << LSB(ADC_CFGR2_OVSS) |
// 0 << LSB(ADC_CFGR2_OVSR) | ADC_CFGR2_ROVSE;

/* clear ready flag */
ADC1->ISR = ADC_ISR_ADRDY;
Expand Down
Loading

0 comments on commit 234bdbe

Please sign in to comment.