Make STM32F303x6/x8 vs xB/xC

This commit is contained in:
CNLohr 2020-08-05 04:41:18 -04:00
parent fdabac3b0d
commit 2146a5c3f5
7 changed files with 179 additions and 24 deletions

View file

@ -14,7 +14,7 @@ OBJCOPYFLAGS = -O binary
BIN=$(CP) -O ihex
DEFS = -DSTM32F30X -DHSE_VALUE=25000000
DEFS = -DSTM32F30X
STARTUP = lib/startup_stm32f30x.s
MCU = cortex-m4
@ -29,8 +29,14 @@ CFLAGS = $(MCFLAGS) $(OPTIMIZE) $(DEFS) \
$(STM32_INCLUDES) \
-I../embeddedcommon \
-Wl,-T,lib/stm32f303.ld
CFLAGS+=-DDEBUG
CFLAGS+=-I.
#If you use a TQFP STM32F303.
CFLAGS+=-I. -DTQFP32 -DHSE_VALUE=8000000
#From the nucleos(sp?)
#CFLAGS+=-I. -DHSE_VALUE=25000000
AFLAGS = $(MCFLAGS)

View file

@ -11,6 +11,24 @@
static int calibration_value;
extern RCC_ClocksTypeDef RCC_Clocks;
#ifdef TQFP32
#define GPIOADCPORT GPIOA
#define GPIOADCNUM GPIO_Pin_0
#define ADCPLLCLK RCC_ADC12PLLCLK_Div2
#define ADCPERIPHEN RCC_AHBPeriph_ADC12
#define ADCPORTAHB RCC_AHBPeriph_GPIOA
#define ADCNUM ADC1
#define ADCCHAN ADC_Channel_1
#else
#define GPIOADCPORT GPIOB
#define GPIOADCNUM GPIO_Pin_12
#define ADCPLLCLK RCC_ADC34PLLCLK_Div2
#define ADCPERIPHEN RCC_AHBPeriph_ADC34
#define ADCPORTAHB RCC_AHBPeriph_GPIOB
#define ADCNUM ADC4
#define ADCCHAN ADC_Channel_3
#endif
void InitADC()
{
ADC_InitTypeDef ADC_InitStructure;
@ -19,25 +37,25 @@ void InitADC()
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* Configure the ADC clock */
RCC_ADCCLKConfig( RCC_ADC34PLLCLK_Div2 );
RCC_ADCCLKConfig( ADCPLLCLK );
/* Enable ADC1 clock */
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_ADC34, ENABLE );
RCC_AHBPeriphClockCmd( ADCPERIPHEN, ENABLE );
/* ADC Channel configuration */
/* GPIOC Periph clock enable */
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB, ENABLE );
RCC_AHBPeriphClockCmd( ADCPORTAHB, ENABLE );
/* Configure ADC Channel7 as analog input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Pin = GPIOADCNUM;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init( GPIOB, &GPIO_InitStructure );
GPIO_Init( GPIOADCPORT, &GPIO_InitStructure );
ADC_StructInit( &ADC_InitStructure );
/* Calibration procedure */
ADC_VoltageRegulatorCmd( ADC4, ENABLE );
ADC_VoltageRegulatorCmd( ADCNUM, ENABLE );
/* Insert delay equal to 10 µs */
_delay_us( 10 );
@ -47,7 +65,7 @@ void InitADC()
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_OneShot;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0;
ADC_CommonInit( ADC4, &ADC_CommonInitStructure );
ADC_CommonInit( ADCNUM, &ADC_CommonInitStructure );
ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
@ -57,16 +75,16 @@ void InitADC()
ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;
ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable;
ADC_InitStructure.ADC_NbrOfRegChannel = 1;
ADC_Init( ADC4, &ADC_InitStructure );
ADC_Init( ADCNUM, &ADC_InitStructure );
/* ADC4 regular channel3 configuration */
ADC_RegularChannelConfig( ADC4, ADC_Channel_3, 1, ADC_SampleTime_181Cycles5 );
ADC_RegularChannelConfig( ADCNUM, ADCCHAN, 1, ADC_SampleTime_181Cycles5 );
/* Enable ADC4 */
ADC_Cmd( ADC4, ENABLE );
ADC_Cmd( ADCNUM, ENABLE );
/* wait for ADRDY */
while( !ADC_GetFlagStatus( ADC4, ADC_FLAG_RDY ) );
while( !ADC_GetFlagStatus( ADCNUM, ADC_FLAG_RDY ) );
NVIC_InitTypeDef NVIC_InitStructure;
@ -92,7 +110,7 @@ void InitADC()
TIM_Cmd (TIM2, ENABLE);
/* Start ADC4 Software Conversion */
ADC_StartConversion( ADC4 );
ADC_StartConversion( ADCNUM );
}
@ -104,8 +122,8 @@ void TIM2_IRQHandler (void)
if (TIM_GetITStatus (TIM2, TIM_IT_Update) != RESET) {
TIM_ClearITPendingBit (TIM2, TIM_IT_Update);
int16_t value = ADC_GetConversionValue(ADC4);
ADC_StartConversion( ADC4 );
int16_t value = ADC_GetConversionValue(ADCNUM);
ADC_StartConversion( ADCNUM );
oversampout += value;
oversamp++;

View file

@ -2,9 +2,16 @@
#define _CCCONFIG_H
#define CCEMBEDDED
#ifdef TQFP32
#define NUM_LIN_LEDS 20
#define USE_NUM_LIN_LEDS 20
#define DFREQ 12500 //XXX Incorrect.
#else
#define NUM_LIN_LEDS 24
#define USE_NUM_LIN_LEDS 24
#define DFREQ 12500
#endif
#endif

View file

@ -3,7 +3,7 @@ ENTRY( Reset_Handler )
/* Highest address of the user mode stack .*/
_estack = 0x2000a000; /* end of 40K RAM */
_estack = 0x20003000; /* end of 40K RAM */
/* Generate a link error if heap and s tack dont fit int o RAM */
@ -12,9 +12,9 @@ _Min_Stack_Size = 0x200; /* required amount of stack .*/
MEMORY
{
FLASH ( rx ) : ORIGIN = 0x08000000 , LENGTH = 256K
RAM ( xrw) : ORIGIN = 0x20000000 , LENGTH = 40K
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 8K
FLASH ( rx ) : ORIGIN = 0x08000000 , LENGTH = 32K
RAM ( xrw) : ORIGIN = 0x20000000 , LENGTH = 12K
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 4K
}
SECTIONS

View file

@ -341,8 +341,15 @@ static void SetSysClock(void)
/* PLL configuration */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
// RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL9);
//If we're using an 8 MHz crystal.
#ifdef TQFP32
// RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL9); // 8 * 9 = 72 MHz
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL8); //8 * 8 = 64 MHz
#else
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL2); //25MHz*2 = 50 MHz
#endif
/* Enable PLL */
RCC->CR |= RCC_CR_PLLON;

View file

@ -25,7 +25,11 @@ volatile int samples;
void ADCCallback( uint16_t adcval )
{
#ifdef TQFP32
sampbuff[last_samp_pos] = adcval*2.0;
#else
sampbuff[last_samp_pos] = adcval;
#endif
last_samp_pos = ((last_samp_pos+1)%CIRCBUFSIZE);
samples++;
}
@ -47,14 +51,18 @@ int main(void)
{
uint32_t i = 0;
send_text( "TEST1\n" );
RCC_GetClocksFreq( &RCC_Clocks );
ConfigureLED(); LED_OFF;
GPIO_InitTypeDef GPIO_InitStructure;
//Turn B10 (TX) on, so we can have something positive to bias the ADC with.
#ifndef TQFP32
ConfigureLED(); LED_OFF;
ConfigureGPIO( GetGPIOFromString( "PB10" ), INOUT_OUT | DEFAULT_ON );
#endif
/* SysTick end of count event each 10ms */
SysTick_Config( RCC_Clocks.HCLK_Frequency/100 ); /// 100);
@ -63,23 +71,30 @@ int main(void)
InitSPI2812();
InitADC();
Init(); //Colorchord
InitColorChord(); //Colorchord
// printf( "Operating at %.3fMHz\n", fv );
#ifndef TQFP32
freepin = GetGPIOFromString( "PB11" );
ConfigureGPIO( freepin, INOUT_OUT | DEFAULT_ON );
#endif
int this_samp = 0;
int wf = 0;
#ifndef TQFP32
LED_ON;
#endif
while(1)
{
if( this_samp != last_samp_pos )
{
#ifndef TQFP32
GPIOOn( freepin );
#endif
PushSample32( sampbuff[this_samp] ); //Can't put in full volume.
this_samp = (this_samp+1)%CIRCBUFSIZE;
@ -87,18 +102,25 @@ int main(void)
wf++;
if( wf == 128 )
{
//uint8_t rdat[20] = { 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff };
//static int countup;
//rdat[5] = sampbuff[last_samp_pos] ;//countup++;
//SendSPI2812( rdat, 4 );
NewFrame();
wf = 0;
}
#ifndef TQFP32
GPIOOff( freepin );
#endif
}
}
}
void TimingDelay_Decrement()
{
#ifndef TQFP32
LED_TOGGLE;
#endif
}

View file

@ -30,6 +30,30 @@ uint8_t MyBuffer[SPI2812_BUFFSIZE+ZERO_BUFFER];
//Currently, the 30X version does not have configurable ports.
#ifdef TQFP32
#define SPI_PORT SPI1
#define SPI_PORT_CLOCK RCC_APB2Periph_SPI1
#define SPI_PORT_CLOCK_INIT RCC_APB2PeriphClockCmd
#define SPI_MOSI_PIN GPIO_Pin_7
#define SPI_MOSI_GPIO_PORT GPIOA
#define SPI_MOSI_GPIO_CLK RCC_AHBPeriph_GPIOA
#define SPI_MOSI_SOURCE GPIO_PinSource7
#define SPI_MOSI_AF GPIO_AF_5
#define SPI_PORT_DR_ADDRESS SPI_PORT->DR
#define SPI_PORT_DMA DMA1
#define SPI_PORT_DMAx_CLK RCC_AHBPeriph_DMA1
#define SPI_PORT_TX_DMA_CHANNEL DMA1_Channel3
#define SPI_PORT_DMA_TX_IRQn DMA1_Channel3_IRQn
#define DMA_HANDLER_IRQFN DMA1_Channel3_IRQHandler
#define DMA_FLAG_C DMA1_FLAG_TC3 //XXX May be wrong.
#define DMA_FLAG_E DMA1_FLAG_TE3 //XXX May be wrong
#else
#define SPI_PORT SPI2
#define SPI_PORT_CLOCK RCC_APB1Periph_SPI2
#define SPI_PORT_CLOCK_INIT RCC_APB1PeriphClockCmd
@ -58,6 +82,8 @@ uint8_t MyBuffer[SPI2812_BUFFSIZE+ZERO_BUFFER];
#define SPI_PORT_DMA_TX_IRQHandler DMA1_Stream4_IRQHandler
*/
#endif
#elif defined( STM32F40_41xxx )
#include <stm32f4xx_rcc.h>
@ -135,6 +161,73 @@ void InitSPI2812()
#ifdef STM32F30X
#ifdef TQFP32
//On SPI1, PORT A.7
RCC_AHBPeriphClockCmd(SPI_MOSI_GPIO_CLK, ENABLE);
RCC_AHBPeriphClockCmd(SPI_PORT_DMAx_CLK, ENABLE);
SPI_PORT_CLOCK_INIT(SPI_PORT_CLOCK, ENABLE);
SPI_I2S_DeInit(SPI_PORT);
/* Configure the GPIO_LED pin */
GPIO_InitStructure.GPIO_Pin = SPI_MOSI_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(SPI_MOSI_GPIO_PORT, SPI_MOSI_SOURCE, SPI_MOSI_AF); //MOSI //GPIO_AF_5??? GPIO_AF_6??? TODO
/* SPI Config */
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7; //TODO: Remove this???
SPI_CalculateCRC(SPI_PORT, DISABLE);
SPI_Init(SPI_PORT, &SPI_InitStructure);
RCC_I2SCLKConfig( RCC_I2S2CLKSource_SYSCLK);
SPI_Cmd(SPI_PORT, ENABLE);
//We're on DMA1, channel 5.
memset( MyBuffer, 0xAA, 128 );
DMA_DeInit(SPI_PORT_TX_DMA_CHANNEL);
DMA_StructInit(&dma_init_struct);
dma_init_struct.DMA_PeripheralBaseAddr = (uint32_t) &SPI_PORT->DR;
dma_init_struct.DMA_MemoryBaseAddr = (uint32_t)MyBuffer; //REmove this? somehow?
dma_init_struct.DMA_DIR = DMA_DIR_PeripheralDST;
dma_init_struct.DMA_BufferSize = 128;
dma_init_struct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
dma_init_struct.DMA_MemoryInc = DMA_MemoryInc_Enable;
dma_init_struct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
dma_init_struct.DMA_MemoryDataSize = DMA_PeripheralDataSize_Byte;
dma_init_struct.DMA_Mode = DMA_Mode_Normal;
dma_init_struct.DMA_Priority = DMA_Priority_VeryHigh;
dma_init_struct.DMA_M2M = DMA_M2M_Disable;
DMA_Init(SPI_PORT_TX_DMA_CHANNEL, &dma_init_struct);
/* Configure the Priority Group */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Initialize NVIC Struct for DMA */
nvic_init_struct.NVIC_IRQChannel = SPI_PORT_DMA_TX_IRQn;
nvic_init_struct.NVIC_IRQChannelPreemptionPriority = 1;
nvic_init_struct.NVIC_IRQChannelSubPriority = 0;
nvic_init_struct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic_init_struct);
SPI_I2S_DMACmd(SPI_PORT, SPI_I2S_DMAReq_Tx, ENABLE);
#else
//On SPI2, PORT B.15
RCC_AHBPeriphClockCmd(SPI_MOSI_GPIO_CLK, ENABLE);
@ -198,6 +291,8 @@ void InitSPI2812()
SPI_I2S_DMACmd(SPI_PORT, SPI_I2S_DMAReq_Tx, ENABLE);
#endif
#elif defined( STM32F40_41xxx )
// enable the SPI peripheral clock