本帖最后由 194490490 于 2023-3-3 08:25 编辑
1,芯片:gd32f303rct62,boot0和boot1都接地。
3,同样的程序stm32f103rct6没有问题。
4,实验内容:通过dma+pwm,控制pb3,输出波形,从而控制rgb灯的点亮,熄灭和颜色。但是程序烧录后,只有在debug模式下程序才能正常运行(点击魔术棒,然后点debug,再点setting不做任何设置,直接退出,程序能自动正确运行)。如果拔除jlink与开发板连线,直接重启电源或按复位都不能正确运行程序。请哪位大佬能不能帮忙看看,我写的配置程序有没有问题,帮忙分析一下原因。
5,void vLED_init(void),为驱动配置程序。
6,void vSetLED(uint8_t (*color)[3],uint16_t len),为通过dma+pwm向rgb灯芯片发送数据
问题已经解决了,配置gpio remap时不仔细一个参数配置错了,正确的是(GPIO_SWJ_SWDPENABLE_REMAP)。
\arg GPIO_SWJ_NONJTRST_REMAP: full SWJ(JTAG-DP + SW-DP),but without NJTRST
\arg GPIO_SWJ_SWDPENABLE_REMAP: JTAG-DP disabled and SW-DP enabled
\arg GPIO_SWJ_DISABLE_REMAP: JTAG-DP disabled and SW-DP disabled<div class="blockcode"><blockquote>/**************************************
/**************************************
功能描述:LED初始化,gpio,pwm,dma
入口参数:无
返回值:无
***************************************/
void vLED_init(void)
{
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
/* PWM_DMA_channel configuration */
dma_parameter_struct dma_data_parameter;
rcu_periph_clock_enable(RCU_TIMER1);//使能定时器1时钟
rcu_periph_clock_enable(RCU_GPIOB);//使能GPIOB时钟
gpio_pin_remap_config(GPIO_TIMER1_FULL_REMAP, ENABLE);//TIMER1 full remapping
gpio_pin_remap_config(GPIO_SWJ_SWDPENABLE_REMAP, ENABLE);//下载口NJTRST引脚当做普通I/O口
/*Configure PB3(TIMER1 CH1) as remap function*/
gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_3);//PB3配置成复用推挽输出
timer_deinit(TIMER1);//复位定时器1
/* TIMER1 configuration */
timer_initpara.prescaler = 0; //0
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 150-1; //800kHz频率 150-1
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER1,&timer_initpara);
/* CH1 configuration in PWM mode0 */
timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
timer_ocintpara.outputnstate= TIMER_CCXN_DISABLE;
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_ocintpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH;
timer_ocintpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW;
timer_ocintpara.ocnidlestate= TIMER_OCN_IDLE_STATE_LOW;
timer_channel_output_config(TIMER1,TIMER_CH_1,&timer_ocintpara); //20230227
/* CH1 configuration in PWM mode1,duty cycle 0% */
timer_channel_output_pulse_value_config(TIMER1,TIMER_CH_1,0);
timer_channel_output_mode_config(TIMER1,TIMER_CH_1,TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER1,TIMER_CH_1,TIMER_OC_SHADOW_ENABLE);
/* enable DMA0 clock */
rcu_periph_clock_enable(RCU_DMA0);
/* ADC DMA_channel configuration */
dma_deinit(DMA0, DMA_CH1);
/* initialize DMA single data mode */
dma_data_parameter.periph_addr = (uint32_t)(&TIMER_CH1CV(TIMER1));
dma_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_data_parameter.memory_addr = (uint32_t)(LED_BYTE_Buffer);
dma_data_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_data_parameter.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
dma_data_parameter.memory_width = DMA_MEMORY_WIDTH_16BIT;
dma_data_parameter.direction = DMA_MEMORY_TO_PERIPHERAL;
dma_data_parameter.number = 4 * 3 * 8; //4个RGB灯珠,3*8个数位
dma_data_parameter.priority = DMA_PRIORITY_ULTRA_HIGH;
dma_init(DMA0, DMA_CH1, &dma_data_parameter);
/* TIMER0 primary output enable */
timer_primary_output_config(TIMER1,ENABLE);
}
<div class="blockcode"><blockquote>/**************************************
功能描述:发送RGB数据
入口参数:(*color)[3]颜色RGB值 len灯珠个数
返回值:无
***************************************/
void vSetLED(uint8_t (*color)[3],uint16_t len)
{
uint8_t i,j;
uint16_t memaddr;
uint16_t buffersize;
buffersize = len*24+225; // number of bytes needed is #LEDs * 24 bytes + 42 trailing bytes
memaddr = 0; // reset buffer memory index
for(j=0;j<len;j++)
{
for(i=0; i<8; i++) // RED data
{
LED_BYTE_Buffer[memaddr] = ((color[j][1]<<i) & 0x0080) ? TIMING_ONE:TIMING_ZERO;
memaddr++;
}
for(i=0; i<8; i++) // GREEN
{
LED_BYTE_Buffer[memaddr] = ((color[j][0]<<i) & 0x0080) ? TIMING_ONE:TIMING_ZERO;
memaddr++;
}
for(i=0; i<8; i++) // BLUE
{
LED_BYTE_Buffer[memaddr] = ((color[j][2]<<i) & 0x0080) ? TIMING_ONE:TIMING_ZERO;
memaddr++;
}
}
while(memaddr < buffersize)
{
LED_BYTE_Buffer[memaddr] = 0;
memaddr++;
}
dma_transfer_number_config(DMA0, DMA_CH1, buffersize);
/* enable the TIMER DMA */
timer_dma_enable(TIMER1, TIMER_DMA_UPD); //更新时请求DMA,注意对应的DMA0通道为CH1 -> TIMER1_UP
timer_counter_value_config(TIMER1, 0x0000);
timer_flag_clear(TIMER1,TIMER_FLAG_UP);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER1);
timer_enable(TIMER1);
/* enable DMA channel */
dma_channel_enable(DMA0, DMA_CH1);
while(!dma_flag_get(DMA0, DMA_CH1, DMA_FLAG_FTF));
dma_channel_disable(DMA0, DMA_CH1);
dma_flag_clear(DMA0, DMA_CH1, DMA_FLAG_FTF);
timer_dma_disable(TIMER1, TIMER_DMA_UPD); //更新时请求DMA,注意对应的DMA0通道为CH1 -> TIMER1_UP
timer_disable(TIMER1);
timer_flag_clear(TIMER1,TIMER_FLAG_UP);
}
|