Получалось ли у кого либо менять значение Capture/compare 1 register в обработчике прерывания? предположим для второго таймера.
Обязательно ли указывать значение в регистр авто перезаписи ? (counter counts from 0 to the auto-reload value (content of the
TIMx_ARR register)
Уже несколько месяцев танцы с бубном не приводят к изменению значения в Capture/compare 1 register в обработчике прерывания.
Имеет ли смысл пробовать писать напрямую по адресам в стиле:
*((uint32_t volatile *)0xE000ED04) = 0x10000000; ?
прикладываю кусок кода если кому не лень подумать.
1 #include <libopencm3/stm32/rcc.h>
2 #include <libopencm3/stm32/gpio.h>
3 #include <libopencm3/stm32/flash.h>
4 #include <libopencm3/stm32/exti.h>
5 #include <libopencm3/stm32/timer.h>
6
7 #include <libopencm3/cm3/scb.h>
8 #include <libopencm3/cm3/nvic.h>
9 //#include <libopencm3/cm3/systick.h>
10 //#include <libopencm3/cm3/cortex.h>
11
23 #define PIN GPIO0
24
25
26 #define PORT GPIOB
27 #define RCC_RORT RCC_APB2ENR_IOPBEN
28
29 // для удобства изменения номера таймера , ключевые слова вытащены наверх.
30 #define TIMER TIM2
31 #define TIM_ISR tim2_isr
32 #define NVIC NVIC_TIM2_IRQ
33 #define RCC_TIMER RCC_APB1ENR_TIM2EN
34 #define NVIC_CLOCK_TIMER NVIC_TIM2_IRQ
35
36
37 #define TIMER_PRSC 7200
38
39
40 #define barrier() do { __asm__ __volatile__ (""); } while (0)
41
42
43 uint16_t G_COMPARE_TIME = 10000;
44
45
46
47
48
49 void TIM_ISR( void )
50 {
51 if ( !( timer_get_flag( TIMER, TIM_SR_CC1IF )))
52 return;
53
54 timer_clear_flag( TIMER, TIM_SR_CC1IF );
55
56
57 G_COMPARE_TIME = timer_get_counter( TIMER );
58 G_COMPARE_TIME += 1000;
59
60 timer_set_oc_value( TIMER, TIM_OC1, G_COMPARE_TIME );
61
62 gpio_toggle( PORT, PIN );
63 }
64
65
66
67
68
69
70
71 int main(void)
72 {
73 extern uint32_t vector_table __asm__( "vector_table" );
74 SCB_VTOR = ( uint32_t ) &vector_table;
75
76 // - - - - - - - - -
77
78 rcc_clock_setup_in_hse_8mhz_out_72mhz();
79
80 rcc_peripheral_enable_clock( &RCC_APB1ENR, RCC_TIMER );
81 rcc_peripheral_enable_clock( &RCC_APB2ENR, RCC_RORT );
82
83
84 // - - - - - - - - -
85
86 gpio_set( PORT, PIN );
87
88 gpio_set_mode( PORT
89 , GPIO_MODE_OUTPUT_2_MHZ
90 , GPIO_CNF_OUTPUT_PUSHPULL
91 , PIN );
92
93 // - - - - - - - - -
94
95
96 timer_reset( TIMER );
97
98 timer_set_prescaler( TIMER, TIMER_PRSC );
99
100
101 timer_set_mode( TIMER
102 , TIM_CR1_CKD_CK_INT
103 , TIM_CR1_CMS_EDGE
104 , TIM_CR1_DIR_UP );
105
106
107 timer_continuous_mode( TIMER );
108
109 timer_enable_update_event( TIMER );
110
111 timer_set_dma_on_compare_event( TIMER ); // check TODO
112 timer_set_dma_on_update_event( TIMER ); // chech TODO
113
114
115 timer_set_oc_slow_mode( TIMER, TIM_OC1 );
116
117
118 timer_set_period( TIMER, 65535 ); // auto-reload register.
119
120
121 timer_disable_oc_clear( TIMER, TIM_OC1 );
122 timer_disable_oc_clear( TIMER, TIM_OC2 );
123 timer_disable_oc_clear( TIMER, TIM_OC3 );
124 timer_disable_oc_clear( TIMER, TIM_OC4 );
125
126 timer_disable_oc_output( TIMER, TIM_OC1 );
127 timer_disable_oc_output( TIMER, TIM_OC2 );
128 timer_disable_oc_output( TIMER, TIM_OC3 );
129 timer_disable_oc_output( TIMER, TIM_OC4 );
130
131 timer_enable_oc_preload( TIMER, TIM_OC1 );
132
133
134 timer_set_oc_value( TIMER, TIM_OC1, G_COMPARE_TIME );
135
136 timer_set_oc_mode( TIMER
137 , TIM_OC1
138 , TIM_OCM_ACTIVE // the output assumes the active state
139 // on the first match.
140 );
141
142
143
144
145
146 timer_enable_irq( TIMER, TIM_DIER_CC1IE );
147 timer_enable_irq( TIMER, TIM_DIER_UIE );
148
149 // - - - - - - - - -
150
151
152 nvic_set_priority( NVIC_CLOCK_TIMER, 2 );
153 nvic_enable_irq( NVIC );
154
155 timer_enable_counter( TIMER );
156
157 // - - - - - - - - -
158 while( 1 )
159 barrier();
160
161 return 0;
162 }