Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
53e24d88b8 | |||
5e93258f5e |
19
README.MD
19
README.MD
@ -1,18 +1 @@
|
||||
# WS2812B light signal - CPU Board
|
||||
|
||||
Board to run [colorchord2](https://github.com/cnlohr/colorchord) on a string of WS2812B LEDs with live line-in audio.
|
||||
|
||||
## Errata (Rev 01)
|
||||
|
||||
* Opamp inverting / non-inverting inputs are swapped
|
||||
* Workaround: Lift pads 2 and 3, and 5 and 6, and connect them crossed using magnet wire.
|
||||
* Opamp is not rail-to-rail and does not allow to use the ADC in full range
|
||||
* Workaround: Only use limited range -640 to 520.
|
||||
* LED footprint is wrong.
|
||||
* Workaround: Flip 180 degrees and solder shifted onto the right pads, then use magnet wire to connect the remaining two pads.
|
||||
* Serial boot loader non-functional (uses incompatible UART I/Os).
|
||||
* Workaround: Program via JTAG / SWD.
|
||||
* Missing level shifters for WS2812B LEDs (RX)
|
||||
* Workaround: Don't use WS2812B RX inputs on the board
|
||||
* Missing level shifters for WS2812B LEDs (TX)
|
||||
* Workaround: The first LED will kinda sorta do the level shifting for you, but sometimes fail to display correctly. Just ignore its erratic blinking.
|
||||
# Sabik WS2812B light signal - CPU Board
|
||||
|
@ -13,8 +13,9 @@ OD=$(PREFIX)-objdump
|
||||
OBJCOPYFLAGS = -O binary
|
||||
|
||||
BIN=$(CP) -O ihex
|
||||
|
||||
CCBASE = colorchord/embeddedstm32f407
|
||||
DEFS = -DSTM32F40_41xxx -DHSE_VALUE=8000000 -DREVISION=\"`git describe --match=NeVeRmAtCh --always --abbrev=40 --dirty`\"
|
||||
DEFS = -DSTM32F40_41xxx -DHSE_VALUE=8000000
|
||||
STARTUP = $(CCBASE)/lib/startup_stm32f40_41xxx.s
|
||||
STLIB = $(CCBASE)/STM32F4xx_StdPeriph_Driver
|
||||
EMCOM = $(CCBASE)/../embeddedcommon
|
||||
|
@ -14,6 +14,8 @@ void adc_init()
|
||||
ADC_InitTypeDef ADC_InitStructure;
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
printf("ADC init\r\n");
|
||||
|
||||
// Enable Clocks
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
|
||||
@ -28,7 +30,7 @@ void adc_init()
|
||||
// Set up timer
|
||||
TIM_TimeBaseInitTypeDef Timer_InitStruct;
|
||||
TIM_TimeBaseStructInit(&Timer_InitStruct);
|
||||
Timer_InitStruct.TIM_Prescaler = 0;
|
||||
Timer_InitStruct.TIM_Prescaler = 0x0;
|
||||
Timer_InitStruct.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
Timer_InitStruct.TIM_Period = (ADC_F_TIM / ADC_SAMPLE_RATE);
|
||||
Timer_InitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
@ -44,7 +46,7 @@ void adc_init()
|
||||
TIM_OC1Init (TIM5, &TIM_OCInitStructure);
|
||||
|
||||
TIM_SetCompare1(TIM5, 0xFFFF);
|
||||
// Let's leave the interrupt disabled until we are done configuring everything
|
||||
TIM_ITConfig(TIM5, TIM_IT_CC1, ENABLE);
|
||||
|
||||
TIM_CCxCmd(TIM5, TIM_Channel_1, TIM_CCx_Enable);
|
||||
TIM_CCxNCmd(TIM5, TIM_Channel_1, TIM_CCx_Enable);
|
||||
@ -125,38 +127,44 @@ void adc_init()
|
||||
// Turn it all on
|
||||
ADC_Cmd(ADC1, ENABLE);
|
||||
ADC_DMACmd(ADC1, ENABLE);
|
||||
}
|
||||
|
||||
void adc_start()
|
||||
{
|
||||
TIM_ITConfig(TIM5, TIM_IT_CC1, ENABLE);
|
||||
printf("adc init done.\r\n");
|
||||
printf("ADC CR1: %08x, CR2: %08x\r\n", ADC1->CR1, ADC1->CR2);
|
||||
printf("ADC SQR1: %08x, SQR3: %08x\r\n", ADC1->SQR1, ADC1->SQR3);
|
||||
printf("DMA2 S0CR: %08x\r\n", ADC_RX_DMA_STREAM->CR);
|
||||
printf("ADC init complete.\r\n");
|
||||
}
|
||||
|
||||
void DMA2_Stream0_IRQHandler()
|
||||
{
|
||||
int sample;
|
||||
int peaking;
|
||||
|
||||
DMA_ClearFlag(ADC_RX_DMA_STREAM, DMA_FLAG_TCIF0);
|
||||
//printf("[DMA-IRQ] %d, %d\r\n", adc_buffer[0], adc_buffer[1]);
|
||||
//sample = 2048 - ((adc_buffer[0] + adc_buffer[1]) / 2);
|
||||
sample = 2048 - adc_buffer[0];
|
||||
//printf("ADC0: %4d, ADC1: %4d, SMP: %4d\r\n",
|
||||
// adc_buffer[0], adc_buffer[1], sample);
|
||||
|
||||
sample = ((adc_buffer[0] + adc_buffer[1]) / 2) - 2048;
|
||||
peaking = (adc_buffer[0] < -640+2048) || (adc_buffer[0] > 520+2048);
|
||||
peaking |= (adc_buffer[1] < -640+2048) || (adc_buffer[1] > 520+2048);
|
||||
|
||||
GotSample(sample, peaking);
|
||||
GotSample(sample);
|
||||
}
|
||||
|
||||
// Only for debugging. Currently disabled.
|
||||
// Not used:
|
||||
void ADC_IRQHandler()
|
||||
{
|
||||
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
|
||||
// printf("[ADC-IRQ] %d, %d\r\n", adc_buffer[0], adc_buffer[1]);
|
||||
//printf("[ADC-IRQ] %d, %d\r\n", adc_buffer[0], adc_buffer[1]);
|
||||
}
|
||||
|
||||
void TIM5_IRQHandler()
|
||||
{
|
||||
TIM_ClearFlag(TIM5, TIM_FLAG_CC1);
|
||||
// I would really like to this in HW via events, but somehow it's broken...
|
||||
|
||||
/*static int s=0;
|
||||
s=!s;
|
||||
if (s) {
|
||||
LED_ON2;
|
||||
} else {
|
||||
LED_OFF2;
|
||||
}*/
|
||||
ADC_SoftwareStartConv(ADC1);
|
||||
}
|
||||
|
@ -11,6 +11,5 @@
|
||||
// TODO: Update the IRQ handler in adc.c when updating the stream / channel.
|
||||
|
||||
void adc_init();
|
||||
void adc_start();
|
||||
|
||||
#endif
|
||||
|
@ -2,8 +2,8 @@
|
||||
#define _CCCONFIG_H
|
||||
|
||||
#define CCEMBEDDED
|
||||
#define NUM_LIN_LEDS 60
|
||||
#define USE_NUM_LIN_LEDS 60
|
||||
#define NUM_LIN_LEDS 48
|
||||
#define USE_NUM_LIN_LEDS 48
|
||||
#define DFREQ (40000)
|
||||
|
||||
#endif
|
||||
|
@ -168,9 +168,8 @@ void ConfigureUART()
|
||||
|
||||
void ConfigureLED()
|
||||
{
|
||||
ConfigureGPIO(LED_RED, INOUT_OUT);
|
||||
ConfigureGPIO(LED_GREEN, INOUT_OUT);
|
||||
ConfigureGPIO(LED_BLUE, INOUT_OUT);
|
||||
ConfigureGPIO(LEDPIN, INOUT_OUT);
|
||||
ConfigureGPIO(LEDPIN2, INOUT_OUT);
|
||||
}
|
||||
|
||||
uint8_t GetGPIOFromString( const char * str )
|
||||
@ -264,29 +263,3 @@ void ConfigureGPIO( uint8_t gpio, int parameters )
|
||||
GPIO_Init(GPIOOf(gpio), &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
void JumpToBootloader(void) {
|
||||
// Many thanks to https://stm32f4-discovery.net/2017/04/tutorial-jump-system-memory-software-stm32/
|
||||
|
||||
void (*SysMemBootJump)(void);
|
||||
volatile uint32_t addr = 0x1FFF0000;
|
||||
|
||||
RCC_DeInit();
|
||||
|
||||
// Disable and reset systick
|
||||
SysTick->CTRL = 0;
|
||||
SysTick->LOAD = 0;
|
||||
SysTick->VAL = 0;
|
||||
|
||||
__disable_irq();
|
||||
|
||||
// Remap system memory
|
||||
SYSCFG->MEMRMP = 0x01;
|
||||
|
||||
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
|
||||
|
||||
// Set main stack pointer
|
||||
__set_MSP(*(uint32_t *)addr);
|
||||
|
||||
// Jump
|
||||
SysMemBootJump();
|
||||
}
|
||||
|
@ -51,19 +51,19 @@ void ConfigureGPIO( gpio gpio, int parameters );
|
||||
#define LEDPIN 0x18
|
||||
#elif defined( STM32F40_41xxx )
|
||||
#define LEDPIN (16+13)
|
||||
#define LEDPIN2 (16+14)
|
||||
#endif
|
||||
|
||||
#define LED_GREEN (LEDPIN+0)
|
||||
#define LED_BLUE (LEDPIN+1)
|
||||
#define LED_RED (LEDPIN+2)
|
||||
|
||||
void ConfigureUART();
|
||||
|
||||
void ConfigureLED();
|
||||
#define LED_TOGGLE {GPIOOf(LEDPIN)->ODR^=(1<<((LEDPIN)&0x0f));}
|
||||
#define LED_ON GPIOOn(LEDPIN)
|
||||
#define LED_OFF GPIOOff(LEDPIN)
|
||||
|
||||
void JumpToBootloader(void);
|
||||
#define LED_ON2 GPIOOn(LEDPIN2)
|
||||
#define LED_OFF2 GPIOOff(LEDPIN2)
|
||||
|
||||
#define LED_ON(p) GPIOOn(p)
|
||||
#define LED_OFF(p) GPIOOff(p)
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -25,20 +25,17 @@ int16_t sampbuff[CIRCBUFSIZE];
|
||||
volatile int samples;
|
||||
|
||||
//This gets called by the ADC/Microphone
|
||||
void GotSample(int samp, int peaking)
|
||||
void GotSample( int samp )
|
||||
{
|
||||
//printf("[GOT-SMP] %d\r\n", samp);
|
||||
sampbuff[last_samp_pos] = samp;
|
||||
last_samp_pos = ((last_samp_pos+1)%CIRCBUFSIZE);
|
||||
samples++;
|
||||
|
||||
if (peaking) {
|
||||
LED_ON(LED_RED);
|
||||
} else if (samp > 128) {
|
||||
LED_ON(LED_BLUE);
|
||||
if (samp > 128) {
|
||||
LED_ON2;
|
||||
} else {
|
||||
LED_OFF(LED_BLUE);
|
||||
// Red LED reset in main loop
|
||||
LED_OFF2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,7 +114,9 @@ int main(void)
|
||||
|
||||
RCC_GetClocksFreq( &RCC_Clocks );
|
||||
|
||||
ConfigureLED();
|
||||
ConfigureLED();
|
||||
|
||||
LED_OFF;
|
||||
|
||||
// SysTick end of count event each 10ms
|
||||
SysTick_Config( RCC_Clocks.HCLK_Frequency / 100);
|
||||
@ -130,14 +129,15 @@ int main(void)
|
||||
InitSPI2812();
|
||||
adc_init();
|
||||
|
||||
printf("\r\nThis is Sabik-CPU, commit %s.\r\n", REVISION);
|
||||
printf("Operating at %.3fMHz.\r\n", fv );
|
||||
printf("Operating at %.3fMHz\r\n", fv );
|
||||
|
||||
int this_samp = 0;
|
||||
int wf = 0;
|
||||
|
||||
LED_ON;
|
||||
LED_ON2;
|
||||
|
||||
int c = 1;
|
||||
LED_ON(LED_RED);
|
||||
while (1) {
|
||||
for (int a=0; a < NUM_LIN_LEDS; a++) {
|
||||
ledOut[a*3 + 0] = c/2;
|
||||
@ -148,31 +148,17 @@ int main(void)
|
||||
SendSPI2812(ledOut, NUM_LIN_LEDS);
|
||||
_delay_us(10*1000);
|
||||
c++;
|
||||
if (c==16) {
|
||||
LED_OFF(LED_RED);
|
||||
LED_ON(LED_BLUE);
|
||||
} else if (c==32) {
|
||||
LED_OFF(LED_BLUE);
|
||||
LED_ON(LED_GREEN);
|
||||
} else if (c==48) {
|
||||
LED_OFF(LED_GREEN);
|
||||
} else if (c==64) {
|
||||
if (c==64)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LED_OFF(LED_RED);
|
||||
LED_OFF(LED_GREEN);
|
||||
LED_OFF(LED_BLUE);
|
||||
|
||||
LED_OFF2;
|
||||
SendSPI2812(ledOut, NUM_LIN_LEDS);
|
||||
adc_start();
|
||||
|
||||
while(1)
|
||||
{
|
||||
if( this_samp != last_samp_pos )
|
||||
{
|
||||
LED_OFF(LED_GREEN); //Use led on the board to show us how much CPU we're using. (You can also probe PB15)
|
||||
LED_OFF; //Use led on the board to show us how much CPU we're using. (You can also probe PB15)
|
||||
|
||||
PushSample32( sampbuff[this_samp] ); //Can't put in full volume. (here was /2)
|
||||
|
||||
@ -183,11 +169,10 @@ int main(void)
|
||||
{
|
||||
NewFrame();
|
||||
wf = 0;
|
||||
LED_OFF(LED_RED);
|
||||
}
|
||||
LED_ON(LED_GREEN);
|
||||
LED_ON;
|
||||
}
|
||||
LED_ON(LED_GREEN); //Take up a little more time to make sure we don't miss this.
|
||||
LED_ON; //Take up a little more time to make sure we don't miss this.
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,6 +133,8 @@ void InitSPI2812()
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
NVIC_InitTypeDef nvic_init_struct;
|
||||
|
||||
printf("Init SPI2812: sizeof(MyBuffer)=%d\r\n", sizeof(MyBuffer));
|
||||
|
||||
#ifdef STM32F30X
|
||||
|
||||
//On SPI2, PORT B.15
|
||||
|
Loading…
Reference in New Issue
Block a user