Modifications

Sauter à la navigation Sauter à la recherche
Ligne 83 : Ligne 83 :     
== L'accès mémoire (Aligned Memory Access) ==
 
== L'accès mémoire (Aligned Memory Access) ==
This is a little less likely to happen to you but it happened to me! If you're used to 8-bit platforms, you can do this nice thing where you can typecast variables around. e.g.
+
Cela ne risque pas forcément de vous arriver mais nous avons rencontré ce problème!  
 +
 
 +
Si vous avez l'habitude des plateformes 8-bits, vous pouvez utiliser des techniques de typecasting de variable comme celle-ci dessous:
    
  <nowiki>uint8_t mybuffer[4];
 
  <nowiki>uint8_t mybuffer[4];
 
float f = (float)mybuffer;</nowiki>
 
float f = (float)mybuffer;</nowiki>
   −
You can't be guaranteed that this will work on a 32-bit platform because '''mybuffer''' might not be aligned to a 2 or 4-byte boundary. The ARM Cortex-M0 can only directly access data on 16-bit boundaries (every 2 or 4 bytes). Trying to access an odd-boundary byte (on a 1 or 3 byte location) will cause a Hard Fault and stop the MCU. Thankfully, there's an easy work around ... just use memcpy!
+
Vous ne pouvez pas avoir la garantie qu'une telle méthode fonctionnera sur une plateforme 32-bits parce que '''mybuffer''' pourrait ne pas être aligné sur 2 ou 4-octets. The ARM Cortex-M0 can only directly access data on 16-bit boundaries (every 2 or 4 bytes). Trying to access an odd-boundary byte (on a 1 or 3 byte location) will cause a Hard Fault and stop the MCU. Thankfully, there's an easy work around ... just use memcpy!
    
  <nowiki>uint8_t mybuffer[4];
 
  <nowiki>uint8_t mybuffer[4];
29 918

modifications

Menu de navigation