karlp on master
stm32: rtc-v2: Fix ADD1S bit de… (compare)
buf[len] = 0;
in the cdcacm_data_rx_cb in the usb examples ? I was about to open a PR because that buf is only 64 bytes long and that added zero is causing a hardfault. I don't know if it is better to remove the buf[len] = 0 in the examples or to enlarge the buffer.GPIOB->ODR = (GPIOB->ODR & ~(pin_mask)) | pin_states;
but I was wondering if there is a function for that
/*
uint8_t potis_vals[ARRAY_PLACES];
static void rcc_setup(void){
/* ADC1 */
rcc_periph_clock_enable(RCC_ADC1);
/*ADC1 on APB2*/
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN);
/* Potis*/
rcc_periph_clock_enable(RCC_GPIOA);
/*Clock for DMA2*/
rcc_peripheral_enable_clock(&RCC_AHB1ENR,RCC_AHB1ENR_DMA2EN);
}
void dma_setup(void);
void dma_setup(void){
//dma_stream_reset(DMA2,DMA_STREAM0); /*The specified stream is disabled and configuration registers are cleared.*/
dma_disable_stream(DMA2, DMA_STREAM0);
dma_channel_select(DMA2,DMA_STREAM0,DMA_SxCR_CHSEL_0); /*DMA2, Stream0,Channel0, for ADC1 .*/
dma_set_number_of_data(DMA2,DMA_STREAM0,ARRAY_PLACES);
dma_set_transfer_mode(DMA2,DMA_STREAM0,DMA_SxCR_DIR_PERIPHERAL_TO_MEM);
dma_set_peripheral_address(DMA2,DMA_STREAM0,(uint32_t) &ADC_DR(ADC1));
dma_set_memory_address(DMA2, DMA_STREAM0, (uint32_t) potis_vals);
dma_disable_peripheral_increment_mode(DMA2,DMA_STREAM0);
dma_enable_memory_increment_mode(DMA2,DMA_STREAM0);
dma_set_peripheral_size(DMA2,DMA_STREAM0,DMA_SxCR_PSIZE_16BIT);
dma_set_memory_size(DMA2,DMA_STREAM0,DMA_SxCR_MSIZE_16BIT);
dma_enable_circular_mode(DMA2,DMA_STREAM0);
dma_set_priority(DMA2,DMA_STREAM0,DMA_SxCR_PL_HIGH);
dma_enable_direct_mode(DMA2,DMA_STREAM0); /*No FIFO*/
dma_set_peripheral_flow_control(DMA2,DMA_STREAM0);
dma_enable_stream(DMA2,DMA_STREAM0);
}
static void adc_setup(void)
{
/*Pins for Potis*/
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO6);
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO7);
/*ADC*/
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0);
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1);
adc_power_off(ADC1);
adc_set_clk_prescale(ADC_CCR_ADCPRE_BY4);
adc_set_resolution(ADC1,ADC_CR1_RES_12BIT);
adc_set_right_aligned(ADC1);
adc_set_continuous_conversion_mode(ADC1);
adc_disable_external_trigger_regular(ADC1);
adc_enable_scan_mode(ADC1); /* 2 channels*/
adc_set_sample_time_on_all_channels(ADC1,ADC_SMPR_SMP_84CYC);
/*allow DMA to continue to operate after the last conversion in the DMA sequence.
This allows DMA to be used in continuous circular mode.*/
adc_set_dma_continue(ADC1);
adc_enable_dma(ADC1);
/*ADC1-channels for the 2 potentiometer*/
uint8_t channel_array[2];
channel_array[0]=ADC_CHANNEL6;
channel_array[1]=ADC_CHANNEL7;
adc_set_regular_sequence(ADC1, 2, channel_array);
adc_power_on(ADC1);
/* Wait for ADC starting up. */
int i;
for (i = 0; i < 800000; i++)
__asm__("nop");
adc_start_conversion_regular(ADC1);
}
int main(void)
{
char val1[32],val2[32]; /*put voltage-values of the potis in val1 and val2 */
float poti_proportion1, poti_proportion2;
int i;
rcc_setup();
dma_setup();
adc_setup();
clock_setup();
console_setup(115200);
sdram_init();
lcd_spi_init();
gfx_init(lcd_draw_pixel, 240, 320);
while (1) {
for (i = 0; i < 1000000; i++) { /* Wait a bit. */
__asm__("NOP");
}
poti_proportion1 = potis_vals[0] / POTIS_ADC_MAX_VALUE;
poti_proportion2 = potis_vals[1] / POTIS_ADC_MAX_VALUE;
sprintf(val1, "%.2f V", 3.3 * poti_pro
Hey. Just asked this over on IRC as well, but it seems there's more people here as well, so I hope nobody minds if I repeat myself for a bit.
According to https://github.com/libopencm3/libopencm3/blame/master/include/libopencm3/usb/usbstd.h#L157 we shouldn't instantiate struct usb_interface... but every example I've seen (gadget zero, and a whole bunch in libopencm3-examples) /does/.
What are we actually supposed to do?
hello folks,
it's about the code that I posted. After a few days I have now looked at it again and found out that the "circular mode" is disabled when I let the DMA flow determined by the periphery.
The NDT register of the DMA is set to the maximum value by the hardware (0xFFFF).
But since I want to transfer 2 values (in circular mode) into an array with 2 places in my code, this has triggered a SegFault.
What can I say? I should have just read the Reference Manual more carefully.
(Maybe this is interesting for one or the other here)