Blog


Testing the SAM R21 Xplained Pro

Posted by on 10:33 pm in SAM4S Xpro | 5 comments

These are a few tests I made with the SAM R21 Xplained Pro and an Xbee. The examples were generated from the Atmel Studio IEEE 802.15.4 MAC Wireless Wizard, with a few extra modifications (since they did not compile). The entire Atmel Studio projects used are available in the download area (tested with ASF v3.22.0). The tests include: sending, sending and receiving, reading LQI, and transmitting values read from the ADC.     Downloads  ...

read more

Buffer Overflow Exploit Demo (SAM4S and Xbee)

Posted by on 8:20 am in MiniOS, SAM4S Xpro, Xbee | 0 comments

I was thinking how to better illustrate (to students) the use of the stack for holding automatic variables at the machine level, and this came out. The class was using the SAM4S Xplained Pro board to learn ARM Thumb assembly, hence its use. The vulnerable application runs MiniOS.  

read more

ASF Working Examples for the Atmel SAM4S Xplained Pro

Posted by on 11:25 pm in Prototyping, SAM4S Xpro | 3 comments

Update: I recently tested some (most) of them with ASFv3.31.0 and they seem to work fine. I’ve also added more examples here.   Original: While working with the SAM4s Xplained Pro I realized the scarcity of documentation available. Atmel examples, when available, would sometimes work, and some others not. Either because  instructions would be missing steps (this happened with the USB CDC), or just because. In any case, this is a set of working examples that might save you from a headache. They were tested with ASF v3.22.. In the downloads you’ll find  a document with the demo’s source code, as well as the steps required to incorporate the functionality into a ASF project (I tested all the demos starting with the Starter Kit Demo – SAM4s Xplained Pro as template). Sample code includes ADC, PWM, GPIO, USART, TWI, SysTick, FatFS, RTC, USB CDC, SSD1306, and Buttons. For more example         Download  ...

read more

An Array Monad in Haskell

Posted by on 10:49 am in Functional Programming | 0 comments

– This is an implementation of an array—using a size-balanced binary search tree under the hood—for a course in programming languages this summer. Some functions may look awkward as they are based on catamorphisms. Global definitions fromList, singleton, toList, set, get, size, contains, inverse, and trim   Test   As a functor   As a monad     Download   Download...

read more

Haskell State Monad Tutorial

Posted by on 9:44 pm in Functional Programming | 0 comments

Background The concept of state refers to a function/computation global or non-local state of memory at any given time. When the output of a function/computation depends solely on its inputs, we say it is stateless — an example of this is combinatory logic. Conversely, when the output depends not only on the received input but also on history of previous executions, we say it is stateful — this is the case in sequential logic. Notice variables local to some scope are not considered state as they die together with their scope and thus cannot keep history of previous executions. So we only consider global and non-local variables to be state. Imperative languages describe computations as series of modifications to state. Pure functional languages like Haskell, on the other hand, describe them as function evaluations and have no concept of state.  While being stateless comes with several advantages (I won’t talk about it), certain programs require to keep track of previous executions. The problem then becomes: how to implement state in a language that cannot, by definition, have state? We simulate it. From the point of view of the function caller — living in an outer scope than the function callee — functions being called can do only two things: take input, and return a value. Thereby the state has to come from input parameters, and can only survive a function return if returned by the callee once it has been altered. Then the caller is responsible for sequentially feeding the state to a function, collecting the new state from the callee upon evaluation, and feeding it to the next function in the execution chain. Let me illustrate it through an example.   Example Consider the following example, where we implement a tiny interpreter for a tiny language that supports only variable lookups and variable updates. To represent memory we use a list of pairs of strings, where the first element in the pair is the variable name, and the second one is the value for that variable name:   type Memory = [(String, String)]   We start by writing a function for looking up elements in memory — Given a variable name, and memory, we get its correspondent value (the second element in the pair whose first element matched the variable name).   varLookUpList :: String -> Memory -> Maybe String varLookUpList name [] = Nothing varLookUpList name ((n,v):xs) = if name == n then Just v else varLookUpList' name xs   Next we need to return the modified data structure to the caller so that the caller can pass it to the new callee, and thus preserve the modifications that have been made during the current call. Perhaps this is not the case when we are just “looking up” values, but in general it is. To do this we need an extra input to receive the state, and an extra output to give back the mutated state together with whatever output the function was returning anyway. In general we want to turn something like this (for functions that lookup values):   function :: a -> state -> b   or like this (for functions that alter a data structure):   function :: a -> state -> state   into something like this:   function :: a -> state ->...

read more