Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4750

General • DMA on PWM hangs the pico

$
0
0
Trying to send continuous samples to pwm with the interrupt on DMA to reset samples to the beginning on pico 1 on and latest SDK, DMA appears to run once and then the pico hangs completely and I start getting "queue_event 346: ASSERT FAILED" on uart

Code:

struct {    uint32_t left[AUDIO_N_DMA_BUFFERS][AUDIO_MAX_BUFFER_SIZE / 2];    uint32_t right[AUDIO_N_DMA_BUFFERS][AUDIO_MAX_BUFFER_SIZE / 2];} audio_dma_buffers;void dma_left_irq_handler() {    dma_channel_set_read_addr(dma_ch_left_1, &audio_dma_buffers.left[0][0], false);    dma_channel_set_trans_count(dma_ch_left_1, AUDIO_CURRENT_BUFFER_SIZE / 2, true);    dma_irqn_acknowledge_channel(DMA_IRQ_0, dma_ch_left_1);}void dma_set() {    dma_ch_left_1 = dma_claim_unused_channel(true);    int pwm_ch_left = pwm_gpio_to_channel(PIN_LEFT_CH);    int slice_num_left = pwm_gpio_to_slice_num(PIN_LEFT_CH);    dma_channel_config cfg = dma_channel_get_default_config(dma_ch_left_1);    channel_config_set_transfer_data_size(&cfg, DMA_SIZE_32);    channel_config_set_read_increment(&cfg, true);    channel_config_set_write_increment(&cfg, false);    channel_config_set_dreq(&cfg, DREQ_PWM_WRAP0 + slice_num_left);        uint32_t write_addr = (uint32_t) &pwm_hw->slice[slice_num_left].cc;    if(pwm_ch_left) write_addr += 2;    dma_channel_configure(dma_ch_left_1        , &cfg        , (volatile void*) write_addr        , &audio_dma_buffers.left[0][0]        , AUDIO_CURRENT_BUFFER_SIZE / 2        , false);    dma_channel_set_irq0_enabled(dma_ch_left_1, true);    irq_set_exclusive_handler(DMA_IRQ_0, dma_left_irq_handler);    irq_set_enabled(DMA_IRQ_0, true);    dma_channel_start(dma_ch_left_1);}

Code:

void pwm_init_for_44khz(void){    pwm_set_wrap(pwm_gpio_to_slice_num(PIN_LEFT_CH), WRAP_44KHZ);    pwm_set_wrap(pwm_gpio_to_slice_num(PIN_RIGHT_CH), WRAP_44KHZ);    pwm_set_clkdiv(pwm_gpio_to_slice_num(PIN_LEFT_CH), 2.4f);    pwm_set_clkdiv(pwm_gpio_to_slice_num(PIN_RIGHT_CH), 2.4f);    pwm_set_gpio_level(PIN_LEFT_CH, WRAP_44KHZ / 2);    pwm_set_gpio_level(PIN_RIGHT_CH, WRAP_44KHZ / 2);    uint32_t mask_slices = (1 << pwm_gpio_to_slice_num(PIN_LEFT_CH)) | (1 << pwm_gpio_to_slice_num(PIN_RIGHT_CH));    pwm_set_mask_enabled(mask_slices);    s_pwm_max_wrap = WRAP_44KHZ;}void pwm_set(uint32_t freq, irq_handler_t on_pwm_wrap) {    if(freq == 44100) {        pwm_init_for_44khz();    } else    if(freq == 48000) {        pwm_init_for_48khz();    }    pwm_set_irq_enabled(pwm_gpio_to_slice_num(PIN_LEFT_CH), true);    pwm_set_irq_enabled(pwm_gpio_to_slice_num(PIN_RIGHT_CH), true);}

Statistics: Posted by hugoballs — Sun Dec 08, 2024 8:58 am — Replies 2 — Views 37



Viewing all articles
Browse latest Browse all 4750

Trending Articles