1 diff --git a/src/aes/ao_aes.c b/src/aes/ao_aes.c
2 index a04174c6..fd90c5bf 100644
5 @@ -359,10 +359,10 @@ void xrijndaelDecrypt(word32 block[], roundkey *rkk)
9 -static uint8_t key[16];
10 +static word32 key[16/4];
13 -static uint8_t iv[16];
14 +static word32 iv[16/4];
17 ao_aes_set_mode(enum ao_aes_mode mode)
18 @@ -389,10 +389,11 @@ ao_aes_run(__xdata uint8_t *in,
22 + uint8_t *_iv = (uint8_t *) iv;
24 for (i = 0; i < 16; i++)
26 - xrijndaelEncrypt((word32 *) iv, &rkk);
28 + xrijndaelEncrypt(iv, &rkk);
32 diff --git a/src/drivers/ao_gps_ublox.c b/src/drivers/ao_gps_ublox.c
33 index 22af413a..c720f802 100644
34 --- a/src/drivers/ao_gps_ublox.c
35 +++ b/src/drivers/ao_gps_ublox.c
36 @@ -156,7 +156,7 @@ static char __xdata *ublox_target;
38 static void ublox_u16(uint8_t offset)
40 - uint16_t __xdata *ptr = (uint16_t __xdata *) (ublox_target + offset);
41 + uint16_t __xdata *ptr = (uint16_t __xdata *) (void __xdata *) (ublox_target + offset);
45 @@ -175,7 +175,7 @@ static void ublox_u8(uint8_t offset)
47 static void ublox_u32(uint8_t offset) __reentrant
49 - uint32_t __xdata *ptr = (uint32_t __xdata *) (ublox_target + offset);
50 + uint32_t __xdata *ptr = (uint32_t __xdata *) (void __xdata *) (ublox_target + offset);
53 val = ((uint32_t) data_byte ());
54 diff --git a/src/drivers/ao_trng_send.c b/src/drivers/ao_trng_send.c
55 index 85034efd..b1227aaa 100644
56 --- a/src/drivers/ao_trng_send.c
57 +++ b/src/drivers/ao_trng_send.c
58 @@ -104,7 +104,7 @@ ao_trng_get_cooked(uint16_t *buf)
62 - uint32_t *rnd = (uint32_t *) ao_adc_ring;
63 + uint32_t *rnd = (uint32_t *) (void *) ao_adc_ring;
66 t = ao_adc_get(AO_USB_IN_SIZE) >> 1; /* one 16-bit value per output byte */
67 diff --git a/src/kernel/ao_list.h b/src/kernel/ao_list.h
68 index e2df6885..45a3df5b 100644
69 --- a/src/kernel/ao_list.h
70 +++ b/src/kernel/ao_list.h
71 @@ -138,7 +138,7 @@ ao_list_is_empty(struct ao_list *head)
72 * @return A pointer to the data struct containing the list head.
74 #define ao_container_of(ptr, type, member) \
75 - ((type *)((char *)(ptr) - offsetof(type, member)))
76 + ((type *)((void *) ((char *)(ptr) - offsetof(type, member))))
79 * Alias of ao_container_of
80 diff --git a/src/kernel/ao_pyro.c b/src/kernel/ao_pyro.c
81 index c9920ab3..813e866a 100644
82 --- a/src/kernel/ao_pyro.c
83 +++ b/src/kernel/ao_pyro.c
84 @@ -437,7 +437,7 @@ ao_pyro_show(void)
85 if (ao_pyro_values[v].flag & AO_PYRO_8_BIT_VALUE)
86 value = *((uint8_t *) ((char *) pyro + ao_pyro_values[v].offset));
88 - value = *((int16_t *) ((char *) pyro + ao_pyro_values[v].offset));
89 + value = *((int16_t *) (void *) ((char *) pyro + ao_pyro_values[v].offset));
90 printf ("%6d ", value);
93 @@ -516,7 +516,7 @@ ao_pyro_set(void)
96 ao_cmd_lex_i = -ao_cmd_lex_i;
97 - *((int16_t *) ((char *) &pyro_tmp + ao_pyro_values[v].offset)) = ao_cmd_lex_i;
98 + *((int16_t *) (void *) ((char *) &pyro_tmp + ao_pyro_values[v].offset)) = ao_cmd_lex_i;
102 diff --git a/src/kernel/ao_task.h b/src/kernel/ao_task.h
103 index f1dbd654..30b018ff 100644
104 --- a/src/kernel/ao_task.h
105 +++ b/src/kernel/ao_task.h
107 #define HAS_TASK_INFO 1
110 +/* arm stacks must be 32-bit aligned */
112 +#define AO_STACK_ALIGNMENT __attribute__ ((aligned(4)))
115 +#define AO_STACK_ALIGNMENT
118 +#define AO_STACK_ALIGNMENT
123 __xdata void *wchan; /* current wait channel (NULL if running) */
124 @@ -37,7 +48,7 @@ struct ao_task {
125 struct ao_list queue;
126 struct ao_list alarm_queue;
128 - uint8_t stack[AO_STACK_SIZE]; /* saved stack */
129 + uint8_t stack[AO_STACK_SIZE] AO_STACK_ALIGNMENT; /* saved stack */
130 #if HAS_SAMPLE_PROFILE
133 diff --git a/src/stm/Makefile.defs b/src/stm/Makefile.defs
134 index c3d2707f..0ba86f5a 100644
135 --- a/src/stm/Makefile.defs
136 +++ b/src/stm/Makefile.defs
137 @@ -27,7 +27,7 @@ LIBS=$(PDCLIB_LIBS_M3) -lgcc
138 WARN_FLAGS=-Wall -Wextra -Werror
140 AO_CFLAGS=-I. -I../stm -I../kernel -I../drivers -I../math -I.. $(PDCLIB_INCLUDES)
141 -STM_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m3 -mthumb \
142 +STM_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m3 -mthumb -Wcast-align \
143 -ffreestanding -nostdlib $(AO_CFLAGS) $(WARN_FLAGS)
145 LDFLAGS=-L../stm -Wl,-Taltos.ld
146 diff --git a/src/stm/ao_arch_funcs.h b/src/stm/ao_arch_funcs.h
147 index 18ca20da..a9d0fa34 100644
148 --- a/src/stm/ao_arch_funcs.h
149 +++ b/src/stm/ao_arch_funcs.h
150 @@ -375,7 +375,7 @@ ao_arch_irq_check(void) {
152 ao_arch_init_stack(struct ao_task *task, void *start)
154 - uint32_t *sp = (uint32_t *) (task->stack + AO_STACK_SIZE);
155 + uint32_t *sp = (uint32_t *) ((void*) task->stack + AO_STACK_SIZE);
156 uint32_t a = (uint32_t) start;
159 @@ -413,16 +413,11 @@ static inline void ao_arch_save_stack(void) {
161 asm("mov %0,sp" : "=&r" (sp) );
162 ao_cur_task->sp = (sp);
163 - if ((uint8_t *) sp < &ao_cur_task->stack[0])
164 - ao_panic (AO_PANIC_STACK);
167 static inline void ao_arch_restore_stack(void) {
169 - sp = (uint32_t) ao_cur_task->sp;
172 - asm("mov sp, %0" : : "r" (sp) );
173 + asm("mov sp, %0" : : "r" (ao_cur_task->sp) );
175 /* Restore PRIMASK */
177 diff --git a/src/stm/ao_eeprom_stm.c b/src/stm/ao_eeprom_stm.c
178 index 05f880b8..4f477122 100644
179 --- a/src/stm/ao_eeprom_stm.c
180 +++ b/src/stm/ao_eeprom_stm.c
181 @@ -83,7 +83,7 @@ ao_intflash_write32(uint16_t pos, uint32_t w)
183 volatile uint32_t *addr;
185 - addr = (uint32_t *) (stm_eeprom + pos);
186 + addr = (uint32_t *) (void *) (stm_eeprom + pos);
188 /* Write a word to a valid address in the data EEPROM */
190 @@ -96,7 +96,7 @@ ao_intflash_write8(uint16_t pos, uint8_t d)
191 uint32_t w, *addr, mask;
194 - addr = (uint32_t *) (stm_eeprom + (pos & ~3));
195 + addr = (uint32_t *) (void *) (stm_eeprom + (pos & ~3));
197 /* Compute word to be written */
198 shift = (pos & 3) << 3;
199 diff --git a/src/stm/ao_usb_stm.c b/src/stm/ao_usb_stm.c
200 index f2b8ea94..9d72844e 100644
201 --- a/src/stm/ao_usb_stm.c
202 +++ b/src/stm/ao_usb_stm.c
203 @@ -139,7 +139,7 @@ static inline uint32_t set_toggle(uint32_t current_value,
205 static inline uint32_t *ao_usb_packet_buffer_addr(uint16_t sram_addr)
207 - return (uint32_t *) (stm_usb_sram + 2 * sram_addr);
208 + return (uint32_t *) (((void *) ((uint8_t *) stm_usb_sram + 2 * sram_addr)));
211 static inline uint32_t ao_usb_epr_stat_rx(uint32_t epr) {
212 diff --git a/src/stm/stm32l.h b/src/stm/stm32l.h
213 index 463125e2..be1e1d65 100644
214 --- a/src/stm/stm32l.h
215 +++ b/src/stm/stm32l.h
216 @@ -1961,7 +1961,7 @@ union stm_usb_bdt {
218 #define STM_USB_BDT_SIZE 8
220 -extern uint8_t stm_usb_sram[];
221 +extern uint8_t stm_usb_sram[] __attribute__ ((aligned(4)));
225 diff --git a/src/stmf0/Makefile-stmf0.defs b/src/stmf0/Makefile-stmf0.defs
226 index 4862f46e..f3296b69 100644
227 --- a/src/stmf0/Makefile-stmf0.defs
228 +++ b/src/stmf0/Makefile-stmf0.defs
229 @@ -25,7 +25,7 @@ endif
230 ELFTOHEX=$(TOPDIR)/../ao-tools/ao-elftohex/ao-elftohex
233 -WARN_FLAGS=-Wall -Wextra -Werror
234 +WARN_FLAGS=-Wall -Wextra -Werror -Wcast-align
236 AO_CFLAGS=-I. -I$(TOPDIR)/stmf0 -I$(TOPDIR)/kernel -I$(TOPDIR)/drivers -I$(TOPDIR)/product -I$(TOPDIR) -I$(TOPDIR)/math $(PDCLIB_INCLUDES)
237 STMF0_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m0 -mthumb\
238 diff --git a/src/stmf0/ao_adc_fast.h b/src/stmf0/ao_adc_fast.h
239 index b8b5e003..3f0b0547 100644
240 --- a/src/stmf0/ao_adc_fast.h
241 +++ b/src/stmf0/ao_adc_fast.h
242 @@ -28,7 +28,7 @@ ao_adc_init(void);
243 /* Total ring size in samples */
244 #define AO_ADC_RING_SIZE 256
246 -extern uint16_t ao_adc_ring[AO_ADC_RING_SIZE];
247 +extern uint16_t ao_adc_ring[AO_ADC_RING_SIZE] __attribute__((aligned(4)));
249 #define ao_adc_ring_step(pos,inc) (((pos) + (inc)) & (AO_ADC_RING_SIZE - 1))
251 diff --git a/src/stmf0/ao_arch_funcs.h b/src/stmf0/ao_arch_funcs.h
252 index 8b6234c4..0cb0e43d 100644
253 --- a/src/stmf0/ao_arch_funcs.h
254 +++ b/src/stmf0/ao_arch_funcs.h
255 @@ -355,7 +355,7 @@ ao_arch_memory_barrier() {
257 ao_arch_init_stack(struct ao_task *task, void *start)
259 - uint32_t *sp = (uint32_t *) (task->stack + AO_STACK_SIZE);
260 + uint32_t *sp = (uint32_t *) ((void *) task->stack + AO_STACK_SIZE);
261 uint32_t a = (uint32_t) start;
264 diff --git a/src/stmf0/ao_usb_stm.c b/src/stmf0/ao_usb_stm.c
265 index cbedb996..652b3b6c 100644
266 --- a/src/stmf0/ao_usb_stm.c
267 +++ b/src/stmf0/ao_usb_stm.c
268 @@ -185,7 +185,7 @@ static inline uint32_t set_toggle(uint32_t current_value,
270 static inline uint16_t *ao_usb_packet_buffer_addr(uint16_t sram_addr)
272 - return (uint16_t *) (stm_usb_sram + sram_addr);
273 + return (uint16_t *) (void *) (stm_usb_sram + sram_addr);
276 static inline uint16_t ao_usb_packet_buffer_offset(uint16_t *addr)
277 diff --git a/src/stmf0/stm32f0.h b/src/stmf0/stm32f0.h
278 index 054200e0..bafa763a 100644
279 --- a/src/stmf0/stm32f0.h
280 +++ b/src/stmf0/stm32f0.h
281 @@ -1996,7 +1996,7 @@ union stm_usb_bdt {
283 #define STM_USB_BDT_SIZE 8
285 -extern uint8_t stm_usb_sram[];
286 +extern uint8_t stm_usb_sram[] __attribute__((aligned(4)));